Add guard to Alternative
The semantics are:
-if tag is Some(_), assume the condition is a constructor,
and compare tags
- if guard is Some(_), evaluate true/false *after* having
applied any bound variables
With this, I can technically get rid of bare conditionals now, since
they are the same as an Alternative with a None tag
This commit is contained in:
@@ -58,6 +58,7 @@ 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 item: Vec<Stmt>,
|
||||
}
|
||||
@@ -159,6 +160,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
||||
pat.to_alternative(then_clause, symbol_table),
|
||||
Alternative {
|
||||
tag: None,
|
||||
guard: None,
|
||||
bound_vars: vec![],
|
||||
item: else_clause,
|
||||
},
|
||||
@@ -201,6 +203,7 @@ impl Pattern {
|
||||
}).collect();
|
||||
Alternative {
|
||||
tag: Some(tag),
|
||||
guard: None,
|
||||
bound_vars,
|
||||
item,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user