diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index b3d5d1b..76d458a 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -282,9 +282,9 @@ pub enum Pattern { Ignored, TuplePattern(Vec), Literal(PatternLiteral), - TupleStruct(Meta, Vec), - Record(Meta, Vec<(Rc, Pattern)>), - VarOrName(Meta), + TupleStruct(QualifiedName, Vec), + Record(QualifiedName, Vec<(Rc, Pattern)>), + VarOrName(QualifiedName), } #[derive(Debug, PartialEq, Clone)] diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index f6945ac..09c0d5e 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -941,14 +941,14 @@ impl Parser { match self.token_handler.peek_kind() { LCurlyBrace => { let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace); - Pattern::Record(Meta::new(qualified_name), members) + Pattern::Record(qualified_name, members) }, LParen => { let members = delimited!(self, LParen, pattern, Comma, RParen); - Pattern::TupleStruct(Meta::new(qualified_name), members) + Pattern::TupleStruct(qualified_name, members) }, _ => { - Pattern::VarOrName(Meta::new(qualified_name)) + Pattern::VarOrName(qualified_name) }, } }, diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 1e3ee72..29b3e6f 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -620,8 +620,8 @@ fn patterns() { "if x is Some(a) then { 4 } else { 9 }", exst!( IfExpression { discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), - body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(Meta::new(qname!(Some)), - vec![Pattern::VarOrName(Meta::new(qname!(a)))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } + body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some), + vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } ) } @@ -629,8 +629,8 @@ fn patterns() { "if x is Some(a) then 4 else 9", exst!( IfExpression { discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), - body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(Meta::new(qname!(Some)), - vec![Pattern::VarOrName(Meta::new(qname!(a)))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } + body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some), + vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } ) } @@ -639,9 +639,9 @@ fn patterns() { IfExpression { discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), body: bx!(IfExpressionBody::SimplePatternMatch( - Pattern::Record(Meta::new(qname!(Something)), vec![ + Pattern::Record(qname!(Something), vec![ (rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))), - (rc!(b),Pattern::VarOrName(Meta::new(qname!(x)))) + (rc!(b),Pattern::VarOrName(qname!(x))) ]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index ae065eb..1a8b42c 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -357,8 +357,7 @@ fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &Vec, symbol_ _ => panic!("Symbol is not a data constructor - this should've been caught in type-checking"), }); let bound_vars = inner_patterns.iter().map(|p| match p { - VarOrName(meta_name) => { - let qualified_name = meta_name.node(); + VarOrName(qualified_name) => { let fqsn = symbol_table.get_fqsn_from_id(&qualified_name.id); let symbol_exists = fqsn.and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)).is_some(); if symbol_exists { @@ -419,7 +418,7 @@ impl Pattern { fn to_subpattern(&self, symbol_table: &SymbolTable) -> Subpattern { use self::Pattern::*; match self { - TupleStruct( Meta { n: QualifiedName{ components, id }, .. }, inner_patterns) => { + TupleStruct(QualifiedName{ components, id }, inner_patterns) => { let fqsn = symbol_table.get_fqsn_from_id(&id); match fqsn.and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)) { Some(symbol) => handle_symbol(Some(symbol), inner_patterns, symbol_table), @@ -434,7 +433,7 @@ impl Pattern { }, Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] }, Literal(lit) => lit.to_subpattern(symbol_table), - VarOrName(Meta { n: QualifiedName { components, id }, .. }) => { + VarOrName(QualifiedName { components, id }) => { // if fqsn is Some, treat this as a symbol pattern. If it's None, treat it // as a variable. println!("Calling VarOrName reduction with : {:?}", components); diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index bf1ae9b..2cc5a47 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -145,10 +145,9 @@ impl<'a> ScopeResolver<'a> { } /// this might be a variable or a pattern. if a variable, set to none - fn qualified_name_in_pattern(&mut self, meta_qualified_name: &mut Meta, ) { - let inner_name = meta_qualified_name.node(); - let ref id = inner_name.id; - let fqsn = lookup_name_in_scope(inner_name); + fn qualified_name_in_pattern(&mut self, qualified_name: &mut QualifiedName) { + let ref id = qualified_name.id; + let fqsn = lookup_name_in_scope(qualified_name); if self.symbol_table.lookup_by_fqsn(&fqsn).is_some() { self.symbol_table.map_id_to_fqsn(&id, fqsn); }