More work on more patterns
-need to convert guard into a possibly-empty vec
This commit is contained in:
parent
dca9ad06c3
commit
e57d33eae7
@ -58,7 +58,7 @@ pub enum Expr {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Alternative {
|
pub struct Alternative {
|
||||||
pub tag: Option<usize>,
|
pub tag: Option<usize>,
|
||||||
pub guard: Option<Expr>,
|
pub guard: Option<Expr>, //TODO should be a vec
|
||||||
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
|
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
|
||||||
pub item: Vec<Stmt>,
|
pub item: Vec<Stmt>,
|
||||||
}
|
}
|
||||||
@ -188,6 +188,10 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* ig var pat
|
||||||
|
* x is SomeBigOldEnum(_, x, Some(t))
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
impl Pattern {
|
impl Pattern {
|
||||||
fn to_alternative(&self, cond: &Box<Expr>, item: Vec<Stmt>, symbol_table: &SymbolTable) -> Alternative {
|
fn to_alternative(&self, cond: &Box<Expr>, item: Vec<Stmt>, symbol_table: &SymbolTable) -> Alternative {
|
||||||
@ -200,9 +204,18 @@ impl Pattern {
|
|||||||
};
|
};
|
||||||
let bound_vars = subpatterns.iter().map(|p| match p {
|
let bound_vars = subpatterns.iter().map(|p| match p {
|
||||||
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
|
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
|
||||||
Ignored => None,
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
|
/*
|
||||||
|
let guard_equality_exprs: Vec<Expr> = subpatterns.iter().map(|p| match p {
|
||||||
|
Literal(lit) => match lit {
|
||||||
|
_ => unimplemented!()
|
||||||
|
},
|
||||||
|
_ => unimplemented!()
|
||||||
|
}).collect();
|
||||||
|
*/
|
||||||
|
|
||||||
Alternative {
|
Alternative {
|
||||||
tag: Some(tag),
|
tag: Some(tag),
|
||||||
guard: None,
|
guard: None,
|
||||||
@ -216,7 +229,7 @@ impl Pattern {
|
|||||||
let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name));
|
let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name));
|
||||||
handle_symbol(symbol, subpatterns, item)
|
handle_symbol(symbol, subpatterns, item)
|
||||||
},
|
},
|
||||||
TuplePattern(_items) => {
|
TuplePattern(items) => {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
},
|
},
|
||||||
Record(_name, _pairs) => {
|
Record(_name, _pairs) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user