Kill more Meta's

This commit is contained in:
greg 2019-09-20 02:03:10 -07:00
parent 8d1e0ebdea
commit f5d1c89574
5 changed files with 18 additions and 20 deletions

View File

@ -282,9 +282,9 @@ pub enum Pattern {
Ignored, Ignored,
TuplePattern(Vec<Pattern>), TuplePattern(Vec<Pattern>),
Literal(PatternLiteral), Literal(PatternLiteral),
TupleStruct(Meta<QualifiedName>, Vec<Pattern>), TupleStruct(QualifiedName, Vec<Pattern>),
Record(Meta<QualifiedName>, Vec<(Rc<String>, Pattern)>), Record(QualifiedName, Vec<(Rc<String>, Pattern)>),
VarOrName(Meta<QualifiedName>), VarOrName(QualifiedName),
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]

View File

@ -941,14 +941,14 @@ impl Parser {
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);
Pattern::Record(Meta::new(qualified_name), members) Pattern::Record(qualified_name, members)
}, },
LParen => { LParen => {
let members = delimited!(self, LParen, pattern, Comma, RParen); 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)
}, },
} }
}, },

View File

@ -620,8 +620,8 @@ fn patterns() {
"if x is Some(a) then { 4 } else { 9 }", exst!( "if x is Some(a) then { 4 } else { 9 }", exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))),
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(Meta::new(qname!(Some)), body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some),
vec![Pattern::VarOrName(Meta::new(qname!(a)))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } 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!( "if x is Some(a) then 4 else 9", exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))),
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(Meta::new(qname!(Some)), body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some),
vec![Pattern::VarOrName(Meta::new(qname!(a)))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) }
) )
} }
@ -639,9 +639,9 @@ fn patterns() {
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))),
body: bx!(IfExpressionBody::SimplePatternMatch( 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!(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")]))) vec![exst!(s "4")], Some(vec![exst!(s "9")])))
} }

View File

@ -357,8 +357,7 @@ 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 {
VarOrName(meta_name) => { VarOrName(qualified_name) => {
let qualified_name = meta_name.node();
let fqsn = symbol_table.get_fqsn_from_id(&qualified_name.id); 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(); let symbol_exists = fqsn.and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)).is_some();
if symbol_exists { if symbol_exists {
@ -419,7 +418,7 @@ 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( Meta { n: QualifiedName{ components, id }, .. }, inner_patterns) => { TupleStruct(QualifiedName{ components, id }, inner_patterns) => {
let fqsn = symbol_table.get_fqsn_from_id(&id); let fqsn = symbol_table.get_fqsn_from_id(&id);
match fqsn.and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)) { match fqsn.and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)) {
Some(symbol) => handle_symbol(Some(symbol), inner_patterns, symbol_table), 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![] }, 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(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 // if fqsn is Some, treat this as a symbol pattern. If it's None, treat it
// as a variable. // as a variable.
println!("Calling VarOrName reduction with : {:?}", components); println!("Calling VarOrName reduction with : {:?}", components);

View File

@ -145,10 +145,9 @@ impl<'a> ScopeResolver<'a> {
} }
/// this might be a variable or a pattern. if a variable, set to none /// 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<QualifiedName>, ) { fn qualified_name_in_pattern(&mut self, qualified_name: &mut QualifiedName) {
let inner_name = meta_qualified_name.node(); let ref id = qualified_name.id;
let ref id = inner_name.id; let fqsn = lookup_name_in_scope(qualified_name);
let fqsn = lookup_name_in_scope(inner_name);
if self.symbol_table.lookup_by_fqsn(&fqsn).is_some() { if self.symbol_table.lookup_by_fqsn(&fqsn).is_some() {
self.symbol_table.map_id_to_fqsn(&id, fqsn); self.symbol_table.map_id_to_fqsn(&id, fqsn);
} }