mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
parser: support empty yield expressions
This commit is contained in:
parent
fc9aa62cff
commit
6820d09938
@ -557,7 +557,7 @@ pub enum Expression {
|
||||
value: Box<Expression>,
|
||||
},
|
||||
Yield {
|
||||
value: Box<Expression>,
|
||||
value: Option<Box<Expression>>,
|
||||
},
|
||||
Negate {
|
||||
value: Box<Self>,
|
||||
|
@ -1473,12 +1473,16 @@ impl Parser {
|
||||
TokenKind::Yield => {
|
||||
self.next();
|
||||
|
||||
let value = self.expression(Precedence::Lowest)?;
|
||||
if self.current.kind == TokenKind::SemiColon {
|
||||
Expression::Yield { value: None }
|
||||
} else {
|
||||
let value = self.expression(Precedence::Lowest)?;
|
||||
|
||||
// FIXME: Check for presence of => here to allow yielding key and value.
|
||||
// FIXME: Check for presence of => here to allow yielding key and value.
|
||||
|
||||
Expression::Yield {
|
||||
value: Box::new(value),
|
||||
Expression::Yield {
|
||||
value: Some(Box::new(value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenKind::Clone => {
|
||||
@ -4674,6 +4678,13 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_yield() {
|
||||
assert_ast("<?php yield;", &[
|
||||
expr!(Expression::Yield { value: None })
|
||||
]);
|
||||
}
|
||||
|
||||
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||
let mut lexer = Lexer::new(None);
|
||||
let tokens = lexer.tokenize(source).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user