mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
parser: support variable variables
This commit is contained in:
parent
d28b93a4e8
commit
63aa82a1cd
@ -1933,7 +1933,7 @@ impl Parser {
|
|||||||
TokenKind::Dollar => {
|
TokenKind::Dollar => {
|
||||||
self.next();
|
self.next();
|
||||||
|
|
||||||
match self.current.kind {
|
match &self.current.kind {
|
||||||
TokenKind::LeftBrace => {
|
TokenKind::LeftBrace => {
|
||||||
self.next();
|
self.next();
|
||||||
|
|
||||||
@ -1945,6 +1945,15 @@ impl Parser {
|
|||||||
name: Box::new(name),
|
name: Box::new(name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TokenKind::Variable(variable) => {
|
||||||
|
let variable = variable.clone();
|
||||||
|
|
||||||
|
self.next();
|
||||||
|
|
||||||
|
Expression::DynamicVariable {
|
||||||
|
name: Box::new(Expression::Variable { name: variable }),
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4240,6 +4249,16 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn variable_variables() {
|
||||||
|
assert_ast(
|
||||||
|
"<?php $$a;",
|
||||||
|
&[expr!(Expression::DynamicVariable {
|
||||||
|
name: Box::new(Expression::Variable { name: "a".into() })
|
||||||
|
})],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn assert_ast(source: &str, expected: &[Statement]) {
|
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||||
let mut lexer = Lexer::new(None);
|
let mut lexer = Lexer::new(None);
|
||||||
let tokens = lexer.tokenize(source).unwrap();
|
let tokens = lexer.tokenize(source).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user