Pattern matching experimental code
WIP
This commit is contained in:
parent
1abbe2e448
commit
926631ba8f
@ -58,8 +58,8 @@ 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 guards: Vec<Expr>,
|
||||||
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
|
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>,
|
pub item: Vec<Stmt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
|||||||
pat.to_alternative(then_clause, symbol_table),
|
pat.to_alternative(then_clause, symbol_table),
|
||||||
Alternative {
|
Alternative {
|
||||||
tag: None,
|
tag: None,
|
||||||
guard: None,
|
guards: vec![],
|
||||||
bound_vars: vec![],
|
bound_vars: vec![],
|
||||||
item: else_clause,
|
item: else_clause,
|
||||||
},
|
},
|
||||||
@ -196,6 +196,12 @@ impl Pattern {
|
|||||||
SymbolSpec::DataConstructor { index, .. } => index.clone(),
|
SymbolSpec::DataConstructor { index, .. } => index.clone(),
|
||||||
_ => panic!("Bad symbol"),
|
_ => panic!("Bad symbol"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let guards = patterns.iter().map(|p| match p {
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
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,
|
Ignored => None,
|
||||||
@ -203,7 +209,7 @@ impl Pattern {
|
|||||||
}).collect();
|
}).collect();
|
||||||
Alternative {
|
Alternative {
|
||||||
tag: Some(tag),
|
tag: Some(tag),
|
||||||
guard: None,
|
guards,
|
||||||
bound_vars,
|
bound_vars,
|
||||||
item,
|
item,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user