From c2db212c78af9b1df8b549a893b458c40280eb24 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 13 Jul 2018 22:12:30 -0700 Subject: [PATCH] Some more guard arm stuff + dealing with split binexp ... in if-blocks. Need to do some re-architecture I think --- schala-lang/src/parsing.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index 2dde59d..60cc53a 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -120,13 +120,13 @@ tuple_struct_pattern := IDENTIFIER '(' (pattern, ',')* ')' /* Expression - If */ if_expr := 'if' discriminator ('then' condititional | 'is' simple_pattern_match | guard_block) discriminator := modified_precedence_expression -modified_precedence_expression := ??? +modified_precedence_expression := precedence_expr (operator)+ //TODO this is currently hard, rearchitect things conditional := block else_clause simple_pattern_match := pattern 'then' conditional else_clause := ε | 'else' block guard_block := '{' (guard_arm, ',')* '}' guard_arm := guard '->' block -guard := ?? +guard := 'is' pattern | (operator)+ precedence_expr /* Expression - While */ while_expr := 'while' while_cond '{' (statement delimiter)* '}' @@ -714,7 +714,14 @@ impl Parser { }); parse_method!(guard(&mut self) -> ParseResult { - unimplemented!() + Ok(match self.peek() { + Keyword(Kw::Is) => { + self.next(); + let pat = self.pattern()?; + Guard::Pat(pat) + }, + _ => unimplemented!() //TODO fix + }) }); parse_method!(pattern(&mut self) -> ParseResult {