From ea542192be5a15c12a7a53c1dd408491cd26bdcc Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 6 Sep 2019 17:19:41 -0700 Subject: [PATCH] Temp qualified names work --- schala-lang/language/src/ast.rs | 8 ++++---- schala-lang/language/src/parsing.rs | 2 +- schala-lang/language/src/parsing/test.rs | 4 ++-- schala-lang/language/src/reduced_ast.rs | 6 +++--- schala-lang/language/src/scope_resolution.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index 7b06876..b591568 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -153,7 +153,7 @@ pub enum ExpressionKind { TupleLiteral(Vec>), Value(Meta), NamedStruct { - name: QualifiedName, + name: Meta, fields: Vec<(Rc, Meta)>, }, Call { @@ -230,9 +230,9 @@ pub enum Pattern { Ignored, TuplePattern(Vec), Literal(PatternLiteral), - TupleStruct(QualifiedName, Vec), - Record(QualifiedName, Vec<(Rc, Pattern)>), - VarOrName(QualifiedName), + TupleStruct(Meta, Vec), + Record(Meta, Vec<(Rc, Pattern)>), + VarOrName(Meta), } #[derive(Debug, PartialEq, Clone)] diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 245a898..2a30e18 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -763,7 +763,7 @@ impl Parser { Ok(match self.token_handler.peek_kind() { LCurlyBrace if !self.restrictions.no_struct_literal => { let fields = self.record_block()?; - Expression::new(NamedStruct { name: qualified_identifier, fields }) + Expression::new(NamedStruct { name: Meta::new(qualified_identifier), fields }) }, _ => Expression::new(Value(Meta::new(qualified_identifier))) }) diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 60304c4..12203fe 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -153,11 +153,11 @@ fn parsing_identifiers() { parse_test!("None", AST(vec![exst!(val!("None"))])); parse_test!("Pandas { a: x + y }", AST(vec![ - exst!(NamedStruct { name: QualifiedName(vec![rc!(Pandas)]), fields: vec![(rc!(a), ex!(m binexp!("+", val!("x"), val!("y"))))]}) + exst!(NamedStruct { name: Meta::new(QualifiedName(vec![rc!(Pandas)])), fields: vec![(rc!(a), ex!(m binexp!("+", val!("x"), val!("y"))))]}) ])); parse_test! { "Pandas { a: n, b: q, }", AST(vec![ - exst!(NamedStruct { name: QualifiedName(vec![rc!(Pandas)]), fields: + exst!(NamedStruct { name: Meta::new(QualifiedName(vec![rc!(Pandas)])), fields: vec![(rc!(a), ex!(m val!("n"))), (rc!(b), ex!(m val!("q")))] } ) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 27f2f82..39658e6 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -176,7 +176,7 @@ impl Meta { TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.reduce(symbol_table)).collect()), IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table), Lambda { params, body, .. } => reduce_lambda(params, body, symbol_table), - NamedStruct { name, fields } => reduce_named_struct(self.fqsn.as_ref(), name, fields, symbol_table), + NamedStruct { name, fields } => reduce_named_struct(self.fqsn.as_ref(), name.node(), fields, symbol_table), Index { .. } => Expr::UnimplementedSigilValue, WhileExpression { .. } => Expr::UnimplementedSigilValue, ForExpression { .. } => Expr::UnimplementedSigilValue, @@ -249,7 +249,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, }; let alternatives = vec![ - pat.to_alternative(then_clause, symbol_table), + pat.node().to_alternative(then_clause, symbol_table), Alternative { matchable: Subpattern { tag: None, @@ -272,7 +272,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, match arm.guard { Guard::Pat(ref p) => { let item = reduce_block(&arm.body, symbol_table); - let alt = p.to_alternative(item, symbol_table); + let alt = p.node().to_alternative(item, symbol_table); alternatives.push(alt); }, Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => { diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index 5098475..c9abeaf 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -35,7 +35,7 @@ impl ScopeResolver { expr.fqsn = Some(fqsn); }, NamedStruct { name, .. } => { - let fqsn = lookup_name_in_scope(&name); + let fqsn = lookup_name_in_scope(&name.node()); expr.fqsn = Some(fqsn); }, BinExp(_, ref mut lhs, ref mut rhs) => {