mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
Add support for block statements
This commit is contained in:
parent
9298288aee
commit
681c201c3c
@ -271,6 +271,9 @@ pub enum Statement {
|
||||
name: Identifier,
|
||||
value: Option<Expression>,
|
||||
},
|
||||
Block {
|
||||
body: Block,
|
||||
},
|
||||
Noop,
|
||||
}
|
||||
|
||||
|
@ -893,6 +893,12 @@ impl Parser {
|
||||
finally,
|
||||
}
|
||||
}
|
||||
TokenKind::LeftBrace => {
|
||||
self.next();
|
||||
let body = self.block(&TokenKind::RightBrace)?;
|
||||
self.rbrace()?;
|
||||
Statement::Block { body }
|
||||
}
|
||||
_ => {
|
||||
let expr = self.expression(0)?;
|
||||
|
||||
@ -2957,6 +2963,19 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block() {
|
||||
assert_ast("<?php {}", &[Statement::Block { body: vec![] }]);
|
||||
assert_ast(
|
||||
"<?php { $a; }",
|
||||
&[Statement::Block {
|
||||
body: vec![Statement::Expression {
|
||||
expr: Expression::Variable { name: "a".into() },
|
||||
}],
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noop() {
|
||||
assert_ast("<?php ;", &[Statement::Noop]);
|
||||
|
Loading…
Reference in New Issue
Block a user