Conditionals - handle delimiters correctly
This commit is contained in:
parent
872e9ce7ee
commit
ba8f67441f
@ -1,4 +1,5 @@
|
|||||||
if 20 then
|
if 20
|
||||||
|
then
|
||||||
a = 20
|
a = 20
|
||||||
b = 30
|
b = 30
|
||||||
c = 40
|
c = 40
|
||||||
|
@ -341,7 +341,18 @@ impl Parser {
|
|||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
use self::Expression::*;
|
use self::Expression::*;
|
||||||
expect!(self, Keyword(Kw::If));
|
expect!(self, Keyword(Kw::If));
|
||||||
|
|
||||||
let test = try!(self.expression());
|
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));
|
expect!(self, Keyword(Kw::Then));
|
||||||
let mut then_block = VecDeque::new();
|
let mut then_block = VecDeque::new();
|
||||||
loop {
|
loop {
|
||||||
@ -492,5 +503,12 @@ mod tests {
|
|||||||
[ExprNode(Conditional(box Null, box Block(_), Some(box Block(_))))] => (),
|
[ExprNode(Conditional(box Null, box Block(_), Some(box Block(_))))] => (),
|
||||||
_ => panic!(),
|
_ => 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!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user