From ba8f67441fb0cef2cdfb2ab812da35bcc6d549c3 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 3 Jan 2017 01:21:20 -0800 Subject: [PATCH] Conditionals - handle delimiters correctly --- conditional.schala | 3 ++- src/parser.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/conditional.schala b/conditional.schala index 7aa4477..9499e5b 100644 --- a/conditional.schala +++ b/conditional.schala @@ -1,4 +1,5 @@ -if 20 then +if 20 +then a = 20 b = 30 c = 40 diff --git a/src/parser.rs b/src/parser.rs index 3debcb8..693faaa 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -341,7 +341,18 @@ impl Parser { use tokenizer::Token::*; use self::Expression::*; expect!(self, Keyword(Kw::If)); + let test = try!(self.expression()); + loop { + match self.peek() { + Some(ref t) if is_delimiter(t) => { + self.next(); + continue; + } + _ => break, + } + } + expect!(self, Keyword(Kw::Then)); let mut then_block = VecDeque::new(); loop { @@ -492,5 +503,12 @@ mod tests { [ExprNode(Conditional(box Null, box Block(_), Some(box Block(_))))] => (), _ => panic!(), } + + let t2 = "if null\nthen\n20\nelse\n40\nend"; + let tokens2 = tokenizer::tokenize(t2).unwrap(); + match parse(&tokens2, &[]).unwrap()[..] { + [ExprNode(Conditional(box Null, box Block(_), Some(box Block(_))))] => (), + _ => panic!(), + } } }