From 1abbe2e448137eee81b00060bc607815da2af5f1 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 27 Aug 2018 12:45:08 -0700 Subject: [PATCH] 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 --- schala-lang/src/reduced_ast.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/schala-lang/src/reduced_ast.rs b/schala-lang/src/reduced_ast.rs index 5cf92e3..3eb7bf2 100644 --- a/schala-lang/src/reduced_ast.rs +++ b/schala-lang/src/reduced_ast.rs @@ -58,6 +58,7 @@ pub enum Expr { #[derive(Debug, Clone)] pub struct Alternative { pub tag: Option, + pub guard: Option, pub bound_vars: Vec>>, //remember that order matters here pub item: Vec, } @@ -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, }