parser: support variable variables

This commit is contained in:
Ryan Chandler 2022-09-16 10:26:11 +01:00
parent d28b93a4e8
commit 63aa82a1cd
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -1933,7 +1933,7 @@ impl Parser {
TokenKind::Dollar => {
self.next();
match self.current.kind {
match &self.current.kind {
TokenKind::LeftBrace => {
self.next();
@ -1945,6 +1945,15 @@ impl Parser {
name: Box::new(name),
}
}
TokenKind::Variable(variable) => {
let variable = variable.clone();
self.next();
Expression::DynamicVariable {
name: Box::new(Expression::Variable { name: variable }),
}
}
_ => 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]) {
let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(source).unwrap();