Pattern matching experimental code

WIP
This commit is contained in:
greg 2018-08-29 03:00:54 -07:00
parent 1abbe2e448
commit 926631ba8f
1 changed files with 10 additions and 4 deletions

View File

@ -58,8 +58,8 @@ pub enum Expr {
#[derive(Debug, Clone)]
pub struct Alternative {
pub tag: Option<usize>,
pub guard: Option<Expr>,
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
pub guards: Vec<Expr>,
pub bound_vars: Vec<Option<Rc<String>>>, //order here is iconic to order in a tuple-like type, None is equivalent to ignored
pub item: Vec<Stmt>,
}
@ -160,7 +160,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
pat.to_alternative(then_clause, symbol_table),
Alternative {
tag: None,
guard: None,
guards: vec![],
bound_vars: vec![],
item: else_clause,
},
@ -196,6 +196,12 @@ impl Pattern {
SymbolSpec::DataConstructor { index, .. } => index.clone(),
_ => panic!("Bad symbol"),
};
let guards = patterns.iter().map(|p| match p {
});
let bound_vars = subpatterns.iter().map(|p| match p {
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
Ignored => None,
@ -203,7 +209,7 @@ impl Pattern {
}).collect();
Alternative {
tag: Some(tag),
guard: None,
guards,
bound_vars,
item,
}