From de0e150536384c32887f2417609e704894cef5d0 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 17 Oct 2018 13:44:29 -0700 Subject: [PATCH] Fix if-block parsing to handle newlines --- schala-lang/src/eval.rs | 5 ++++- schala-lang/src/parsing.rs | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index de5b58f..fb9deab 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -535,7 +535,10 @@ if a { is 15 -> "x", is 10 -> "y" } fn boolean_pattern() { let source = r#" let a = true -if a { is true -> "x", is false -> "y" } +if a { + is true -> "x", + is false -> "y" +} "#; test_in_fresh_env!(source, "\"x\""); } diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index 46b5958..fea8b8b 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -694,7 +694,25 @@ impl Parser { }); parse_method!(guard_block(&mut self) -> ParseResult { - let guards = delimited!(self, LCurlyBrace, guard_arm, Comma, RCurlyBrace); + //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 + } + } + expect!(self, RCurlyBrace); Ok(IfExpressionBody::GuardList(guards)) });