From 44c073320b0ea0ad5d9e25fd6a871f0ef1548ed0 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 6 Sep 2019 02:23:04 -0700 Subject: [PATCH] Code builds, tests don't --- schala-lang/language/src/parsing.rs | 16 ++++---- schala-lang/language/src/reduced_ast.rs | 43 ++++++++++++++------ schala-lang/language/src/scope_resolution.rs | 2 - 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index c56f736..12a94da 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -931,9 +931,9 @@ impl Parser { #[recursive_descent_method] fn simple_pattern(&mut self) -> ParseResult { - match self.token_handler.peek_kind() { + Ok(match self.token_handler.peek_kind() { Identifier(_) => { - let qualified_name = self.qualified_name()?; + let qualified_name = self.qualified_identifier()?; match self.token_handler.peek_kind() { LCurlyBrace => { let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace); @@ -944,17 +944,19 @@ impl Parser { Pattern::TupleStruct(qualified_name, members) }, _ => { - Pattern::VarPattern(qualified_name) + Pattern::VarOrName(qualified_name) }, } }, - _ => self.pattern_literal() - } + _ => self.pattern_literal()? + }) } #[recursive_descent_method] fn pattern_literal(&mut self) -> ParseResult { - match self.token_handler.peek_kind() { + let tok = self.token_handler.peek(); + let kind = tok.kind.clone(); + Ok(match kind { Keyword(Kw::True) => { self.token_handler.next(); Pattern::Literal(PatternLiteral::BoolPattern(true)) @@ -974,7 +976,7 @@ impl Parser { Pattern::Ignored }, other => return ParseError::new_with_token(format!("{:?} is not a valid Pattern", other), tok) - } + }) } /* diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 0d3685b..27f2f82 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -295,13 +295,16 @@ 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 { - Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()), + VarOrName(name) => { + //if this is a variable, return Some(var.clone()), else None + unimplemented!() + }, _ => None, }).collect(); let subpatterns = inner_patterns.iter().map(|p| match p { Ignored => None, - Literal(PatternLiteral::VarPattern(_)) => None, + VarOrName(_) => None, Literal(other) => Some(other.to_subpattern(symbol_table)), tp @ TuplePattern(_) => Some(tp.to_subpattern(symbol_table)), ts @ TupleStruct(_, _) => Some(ts.to_subpattern(symbol_table)), @@ -343,8 +346,13 @@ impl Pattern { fn to_subpattern(&self, symbol_table: &SymbolTable) -> Subpattern { use self::Pattern::*; match self { - TupleStruct(name, inner_patterns) => { - let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name)); + TupleStruct(QualifiedName(vec), inner_patterns) => { + let name = if vec.len() == 1 { + vec[0].clone() + } else { + panic!("check this line of code 2 yo"); + }; + let symbol = symbol_table.lookup_by_name(&name).expect(&format!("Symbol {} not found", name)); handle_symbol(Some(symbol), inner_patterns, symbol_table) }, TuplePattern(inner_patterns) => handle_symbol(None, inner_patterns, symbol_table), @@ -353,6 +361,24 @@ impl Pattern { }, Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] }, Literal(lit) => lit.to_subpattern(symbol_table), + VarOrName(QualifiedName(vec)) => { + //TODO this name needs to be resolved from metadata with context + let name = if vec.len() == 1 { + vec[0].clone() + } else { + panic!("check this line of code yo"); + }; + + match symbol_table.lookup_by_name(&name) { + Some(symbol) => handle_symbol(Some(symbol), &vec![], symbol_table), + None => Subpattern { + tag: None, + subpatterns: vec![], + guard: None, + bound_vars: vec![Some(name.clone())], + } + } + }, } } } @@ -409,15 +435,6 @@ impl PatternLiteral { bound_vars: vec![], } }, - VarPattern(var) => match symbol_table.lookup_by_name(var) { - Some(symbol) => handle_symbol(Some(symbol), &vec![], symbol_table), - None => Subpattern { - tag: None, - subpatterns: vec![], - guard: None, - bound_vars: vec![Some(var.clone())], - } - } } } } diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index 995a699..f963601 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; - use crate::symbol_table::{ScopeSegment, ScopeSegmentKind, FullyQualifiedSymbolName}; use crate::ast::*;