VarOrName fix in reduced ast

This commit is contained in:
greg 2019-09-08 17:01:07 -07:00
parent 09dbe5b736
commit 29f4060a71

View File

@ -158,7 +158,7 @@ impl Meta<Expression> {
Value(qualified_name) => {
let ref sym_name = match self.fqsn {
Some(ref fqsn) => fqsn,
None => return Expr::ReductionError(format!("FQSN lookup for value failed")),
None => return Expr::ReductionError(format!("FQSN lookup for value A failed")),
};
let FullyQualifiedSymbolName(ref v) = sym_name;
let name = v.last().unwrap().name.clone();
@ -196,7 +196,7 @@ fn reduce_lambda(params: &Vec<FormalParam>, body: &Block, symbol_table: &SymbolT
fn reduce_named_struct(fqsn: Option<&FullyQualifiedSymbolName>, name: &QualifiedName, fields: &Vec<(Rc<String>, Meta<Expression>)>, symbol_table: &SymbolTable) -> Expr {
let sym_name = match fqsn {
Some(fqsn) => fqsn,
None => return Expr::ReductionError(format!("FQSN lookup for value failed")),
None => return Expr::ReductionError(format!("FQSN lookup for value B failed")),
};
let FullyQualifiedSymbolName(ref v) = sym_name;
let ref name = v.last().unwrap().name;
@ -295,9 +295,18 @@ 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 {
VarOrName(name) => {
//if this is a variable, return Some(var.clone()), else None
unimplemented!()
VarOrName(meta_name) => {
let symbol_exists = meta_name.fqsn.as_ref().and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)).is_some();
if symbol_exists {
None
} else {
let QualifiedName(name_elems) = meta_name.node();
if name_elems.len() == 1 {
Some(name_elems[0].clone())
} else {
panic!("Bad variable name in pattern");
}
}
},
_ => None,
}).collect();