mirror of
https://github.com/danog/parser.git
synced 2025-01-23 05:21:22 +01:00
parser: support continue statements
This commit is contained in:
parent
3ad45e6d1e
commit
e1eff91ee7
@ -623,6 +623,7 @@ fn identifier_to_keyword(ident: &str) -> Option<TokenKind> {
|
||||
"as" => TokenKind::As,
|
||||
"break" => TokenKind::Break,
|
||||
"class" => TokenKind::Class,
|
||||
"continue" => TokenKind::Continue,
|
||||
"const" => TokenKind::Const,
|
||||
"declare" => TokenKind::Declare,
|
||||
"echo" => TokenKind::Echo,
|
||||
|
@ -187,6 +187,9 @@ pub enum Statement {
|
||||
Break {
|
||||
num: Option<Expression>,
|
||||
},
|
||||
Continue {
|
||||
num: Option<Expression>,
|
||||
},
|
||||
Echo {
|
||||
values: Vec<Expression>,
|
||||
},
|
||||
|
@ -361,6 +361,20 @@ impl Parser {
|
||||
expect!(self, TokenKind::SemiColon, "expected semi-colon at the end of an echo statement");
|
||||
Statement::Echo { values }
|
||||
},
|
||||
TokenKind::Continue => {
|
||||
self.next();
|
||||
|
||||
let mut num = None;
|
||||
if self.current.kind != TokenKind::SemiColon {
|
||||
num = Some(self.expression(0)?);
|
||||
}
|
||||
|
||||
dbg!(&self.current.kind);
|
||||
|
||||
expect!(self, TokenKind::SemiColon, "expected semi-colon");
|
||||
|
||||
Statement::Continue { num }
|
||||
},
|
||||
TokenKind::Break => {
|
||||
self.next();
|
||||
|
||||
@ -1007,6 +1021,17 @@ mod tests {
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn continues() {
|
||||
assert_ast("<?php continue;", &[
|
||||
Statement::Continue { num: None }
|
||||
]);
|
||||
|
||||
assert_ast("<?php continue 2;", &[
|
||||
Statement::Continue { num: Some(Expression::Int(2)) }
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_precedence() {
|
||||
assert_ast("<?php 1 + 2 * 3 / 4 - 5;", &[
|
||||
|
Loading…
x
Reference in New Issue
Block a user