Conditionals - handle delimiters correctly

This commit is contained in:
greg 2017-01-03 01:21:20 -08:00
parent 872e9ce7ee
commit ba8f67441f
2 changed files with 20 additions and 1 deletions

View File

@ -1,4 +1,5 @@
if 20 then
if 20
then
a = 20
b = 30
c = 40

View File

@ -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!(),
}
}
}