From 1bd48ed5dbc3ce301f4b6eb2870df19dd73d7012 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 5 Nov 2018 13:07:08 -0800 Subject: [PATCH] Fix problem with parsing commas I should probably rethink how delimited block expressions like if-blocks (and eventually for-blocks) work --- schala-lang/language/src/eval.rs | 2 +- schala-lang/language/src/parsing.rs | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/schala-lang/language/src/eval.rs b/schala-lang/language/src/eval.rs index 63dbdff..ec820f6 100644 --- a/schala-lang/language/src/eval.rs +++ b/schala-lang/language/src/eval.rs @@ -677,7 +677,7 @@ if (1, 5) { } #[test] - fn need_to_fix_parser_to_make_work() { + fn tuple_pattern_4() { let source = r#" if (1, 5) { is (10, x) -> x, diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index b0c75f5..17145b8 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -749,19 +749,26 @@ impl Parser { //TODO - delimited! isn't sophisticated enough to do thisa //let guards = delimited!(self, LCurlyBrace, guard_arm, Comma, RCurlyBrace); expect!(self, LCurlyBrace); + let mut guards = vec![]; loop { - while let Newline = self.peek() { - self.next(); - } - let guard_arm = self.guard_arm()?; - guards.push(guard_arm); - while let Newline = self.peek() { - self.next(); - } match self.peek() { - Comma => {self.next(); continue }, - _ => break + RCurlyBrace | EOF => break, + Semicolon | Newline => { self.next(); continue}, + _ => { + let guard_arm = self.guard_arm()?; + guards.push(guard_arm); + loop { + match self.peek() { + Semicolon | Newline => { self.next(); continue; }, + _ => break, + } + } + if let RCurlyBrace = self.peek() { + break; + } + expect!(self, Comma); + } } } expect!(self, RCurlyBrace);