Code builds, tests don't

This commit is contained in:
greg 2019-09-06 02:23:04 -07:00
parent c04e4356a1
commit 44c073320b
3 changed files with 39 additions and 22 deletions

View File

@ -931,9 +931,9 @@ impl Parser {
#[recursive_descent_method]
fn simple_pattern(&mut self) -> ParseResult<Pattern> {
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<Pattern> {
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)
}
})
}
/*

View File

@ -295,13 +295,16 @@ fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &Vec<Pattern>, 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())],
}
}
}
}
}

View File

@ -1,5 +1,3 @@
use std::rc::Rc;
use crate::symbol_table::{ScopeSegment, ScopeSegmentKind, FullyQualifiedSymbolName};
use crate::ast::*;