mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +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,
|
name: Identifier,
|
||||||
value: Option<Expression>,
|
value: Option<Expression>,
|
||||||
},
|
},
|
||||||
|
Block {
|
||||||
|
body: Block,
|
||||||
|
},
|
||||||
Noop,
|
Noop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,6 +893,12 @@ impl Parser {
|
|||||||
finally,
|
finally,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TokenKind::LeftBrace => {
|
||||||
|
self.next();
|
||||||
|
let body = self.block(&TokenKind::RightBrace)?;
|
||||||
|
self.rbrace()?;
|
||||||
|
Statement::Block { body }
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let expr = self.expression(0)?;
|
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]
|
#[test]
|
||||||
fn noop() {
|
fn noop() {
|
||||||
assert_ast("<?php ;", &[Statement::Noop]);
|
assert_ast("<?php ;", &[Statement::Noop]);
|
||||||
|
Loading…
Reference in New Issue
Block a user