Code builds, tests don't
This commit is contained in:
parent
c04e4356a1
commit
44c073320b
@ -931,9 +931,9 @@ impl Parser {
|
|||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn simple_pattern(&mut self) -> ParseResult<Pattern> {
|
fn simple_pattern(&mut self) -> ParseResult<Pattern> {
|
||||||
match self.token_handler.peek_kind() {
|
Ok(match self.token_handler.peek_kind() {
|
||||||
Identifier(_) => {
|
Identifier(_) => {
|
||||||
let qualified_name = self.qualified_name()?;
|
let qualified_name = self.qualified_identifier()?;
|
||||||
match self.token_handler.peek_kind() {
|
match self.token_handler.peek_kind() {
|
||||||
LCurlyBrace => {
|
LCurlyBrace => {
|
||||||
let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace);
|
let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace);
|
||||||
@ -944,17 +944,19 @@ impl Parser {
|
|||||||
Pattern::TupleStruct(qualified_name, members)
|
Pattern::TupleStruct(qualified_name, members)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
Pattern::VarPattern(qualified_name)
|
Pattern::VarOrName(qualified_name)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => self.pattern_literal()
|
_ => self.pattern_literal()?
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn pattern_literal(&mut self) -> ParseResult<Pattern> {
|
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) => {
|
Keyword(Kw::True) => {
|
||||||
self.token_handler.next();
|
self.token_handler.next();
|
||||||
Pattern::Literal(PatternLiteral::BoolPattern(true))
|
Pattern::Literal(PatternLiteral::BoolPattern(true))
|
||||||
@ -974,7 +976,7 @@ impl Parser {
|
|||||||
Pattern::Ignored
|
Pattern::Ignored
|
||||||
},
|
},
|
||||||
other => return ParseError::new_with_token(format!("{:?} is not a valid Pattern", other), tok)
|
other => return ParseError::new_with_token(format!("{:?} is not a valid Pattern", other), tok)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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"),
|
_ => 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 {
|
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,
|
_ => None,
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
let subpatterns = inner_patterns.iter().map(|p| match p {
|
let subpatterns = inner_patterns.iter().map(|p| match p {
|
||||||
Ignored => None,
|
Ignored => None,
|
||||||
Literal(PatternLiteral::VarPattern(_)) => None,
|
VarOrName(_) => None,
|
||||||
Literal(other) => Some(other.to_subpattern(symbol_table)),
|
Literal(other) => Some(other.to_subpattern(symbol_table)),
|
||||||
tp @ TuplePattern(_) => Some(tp.to_subpattern(symbol_table)),
|
tp @ TuplePattern(_) => Some(tp.to_subpattern(symbol_table)),
|
||||||
ts @ TupleStruct(_, _) => Some(ts.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 {
|
fn to_subpattern(&self, symbol_table: &SymbolTable) -> Subpattern {
|
||||||
use self::Pattern::*;
|
use self::Pattern::*;
|
||||||
match self {
|
match self {
|
||||||
TupleStruct(name, inner_patterns) => {
|
TupleStruct(QualifiedName(vec), inner_patterns) => {
|
||||||
let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name));
|
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)
|
handle_symbol(Some(symbol), inner_patterns, symbol_table)
|
||||||
},
|
},
|
||||||
TuplePattern(inner_patterns) => handle_symbol(None, 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![] },
|
Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] },
|
||||||
Literal(lit) => lit.to_subpattern(symbol_table),
|
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![],
|
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())],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use crate::symbol_table::{ScopeSegment, ScopeSegmentKind, FullyQualifiedSymbolName};
|
use crate::symbol_table::{ScopeSegment, ScopeSegmentKind, FullyQualifiedSymbolName};
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user