From 8aa33d0872156c34f3076d0bde88627df9823797 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 13 Jul 2018 20:18:57 -0700 Subject: [PATCH] Starting on guards --- schala-lang/src/parsing.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index 7b6c336..f68fe4e 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -120,9 +120,12 @@ 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 := ??? conditional := block else_clause simple_pattern_match := pattern 'then' conditional else_clause := ε | 'else' block +guard_block := '{' (guard, ',')* '}' +guard := ?? /* Expression - While */ while_expr := 'while' while_cond '{' (statement delimiter)* '}' @@ -688,10 +691,6 @@ impl Parser { Ok(IfExpressionBody::SimplePatternMatch(pat, then_clause, else_clause)) }); - parse_method!(guard_block(&mut self) -> ParseResult { - ParseError::new("Rest of if not done") - }); - parse_method!(else_clause(&mut self) -> ParseResult> { Ok(if let Keyword(Kw::Else) = self.peek() { self.next(); @@ -701,6 +700,15 @@ impl Parser { }) }); + parse_method!(guard_block(&mut self) -> ParseResult { + let guards = delimited!(self, LCurlyBrace, guard, Comma, RCurlyBrace); + Ok(IfExpressionBody::GuardList(guards)) + }); + + parse_method!(guard(&mut self) -> ParseResult { + unimplemented!() + }); + parse_method!(pattern(&mut self) -> ParseResult { if let LParen = self.peek() { let tuple_pattern_variants = delimited!(self, LParen, pattern, Comma, RParen);