mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
Merge pull request #61 from ryangjchandler/fix/empty-array-items
This commit is contained in:
commit
d70b2685ff
@ -388,6 +388,7 @@ pub struct Use {
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum Expression {
|
||||
Static,
|
||||
Empty,
|
||||
ErrorSuppress {
|
||||
expr: Box<Self>,
|
||||
},
|
||||
|
@ -1505,6 +1505,15 @@ impl Parser {
|
||||
self.skip_comments();
|
||||
|
||||
while self.current.kind != TokenKind::RightBracket {
|
||||
if self.current.kind == TokenKind::Comma {
|
||||
items.push(ArrayItem {
|
||||
key: None,
|
||||
value: Expression::Empty,
|
||||
});
|
||||
self.next();
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut key = None;
|
||||
let mut value = self.expression(0)?;
|
||||
|
||||
@ -3421,6 +3430,33 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_empty_items() {
|
||||
assert_ast(
|
||||
"<?php [1, 2, , 4];",
|
||||
&[expr!(Expression::Array {
|
||||
items: vec![
|
||||
ArrayItem {
|
||||
key: None,
|
||||
value: Expression::Int { i: 1 },
|
||||
},
|
||||
ArrayItem {
|
||||
key: None,
|
||||
value: Expression::Int { i: 2 },
|
||||
},
|
||||
ArrayItem {
|
||||
key: None,
|
||||
value: Expression::Empty,
|
||||
},
|
||||
ArrayItem {
|
||||
key: None,
|
||||
value: Expression::Int { i: 4 },
|
||||
},
|
||||
]
|
||||
})],
|
||||
)
|
||||
}
|
||||
|
||||
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