diff --git a/schala-lang/language/src/eval.rs b/schala-lang/language/src/eval.rs index 9f6b7d8..a27d693 100644 --- a/schala-lang/language/src/eval.rs +++ b/schala-lang/language/src/eval.rs @@ -425,15 +425,15 @@ impl<'a> State<'a> { let cond = self.expression(Node::Expr(cond))?; for alt in alternatives { // no matter what type of condition we have, ignore alternative if the guard evaluates false - if !self.guard_passes(&alt.guard, &cond)? { + if !self.guard_passes(&alt.matchable.guard, &cond)? { continue; } match cond { Node::PrimObject { ref tag, ref items, .. } => { - if alt.tag.map(|t| t == *tag).unwrap_or(true) { - let mut inner_state = self.new_frame(items, &alt.bound_vars); - if all_subpatterns_pass(&mut inner_state, &alt.subpatterns, items)? { + if alt.matchable.tag.map(|t| t == *tag).unwrap_or(true) { + let mut inner_state = self.new_frame(items, &alt.matchable.bound_vars); + if all_subpatterns_pass(&mut inner_state, &alt.matchable.subpatterns, items)? { return inner_state.block(alt.item); } else { continue; @@ -441,15 +441,15 @@ impl<'a> State<'a> { } }, Node::PrimTuple { ref items } => { - let mut inner_state = self.new_frame(items, &alt.bound_vars); - if all_subpatterns_pass(&mut inner_state, &alt.subpatterns, items)? { + let mut inner_state = self.new_frame(items, &alt.matchable.bound_vars); + if all_subpatterns_pass(&mut inner_state, &alt.matchable.subpatterns, items)? { return inner_state.block(alt.item); } else { continue; } }, Node::Expr(ref _e) => { - if let None = alt.tag { + if let None = alt.matchable.tag { return self.block(alt.item) } } diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 695d771..de228b5 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -60,10 +60,7 @@ pub type BoundVars = Vec>>; //remember that order matters here #[derive(Debug, Clone)] pub struct Alternative { - pub tag: Option, - pub subpatterns: Vec>, - pub guard: Option, - pub bound_vars: BoundVars, + pub matchable: Subpattern, pub item: Vec, } @@ -201,10 +198,12 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, let alternatives = vec![ pat.to_alternative(then_clause, symbol_table), Alternative { - tag: None, - subpatterns: vec![], - bound_vars: vec![], - guard: None, + matchable: Subpattern { + tag: None, + subpatterns: vec![], + bound_vars: vec![], + guard: None, + }, item: else_clause }, ]; @@ -278,10 +277,12 @@ impl Pattern { fn to_alternative(&self, item: Vec, symbol_table: &SymbolTable) -> Alternative { let s = self.to_subpattern(symbol_table); Alternative { - tag: s.tag, - subpatterns: s.subpatterns, - bound_vars: s.bound_vars, - guard: s.guard, + matchable: Subpattern { + tag: s.tag, + subpatterns: s.subpatterns, + bound_vars: s.bound_vars, + guard: s.guard, + }, item } }