From 501eaeee8720f786ce1de5753caac84b5fe55953 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 16 Oct 2018 03:54:08 -0700 Subject: [PATCH] Implement numeric pattern matching --- schala-lang/src/eval.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 8a2af41..0d1164f 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -226,13 +226,30 @@ impl<'a> State<'a> { inner_state.values.insert(bv.clone(), ValueEntry::Binding { constant: true, val: val.clone() }); } } + + if let Some(guard_expr) = alt.guard { + let evaled_guard = inner_state.expression(guard_expr.to_node()); + println!("EVALED GUARD: {:?}", evaled_guard); + //continue + } + return inner_state.block(alt.item) } } - return Err(format!("No matches found")); + return Err(format!("Failed pattern match")); }, - Node::PrimTuple { .. } => Err(format!("Tuples don't work")), - Node::Expr(e) => Err(format!("Exprs don't work {:?}", e)) + Node::PrimTuple { .. } => Err(format!("Tuples not implemented")), //TODO make a distinction between not yet implemented and an actual runtime error + Node::Expr(e) => { + for alt in alternatives { + match alt.guard { + Some(ref guard_expr) if alt.tag.is_none() => { + return self.block(alt.item) + }, + _ => () + } + } + return Err(format!("Failed pattern match")); + } }, UnimplementedSigilValue => Err(format!("Sigil value eval not implemented")) }