mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
parser: support braced variables
This commit is contained in:
parent
9353c8fab1
commit
5cc76b4f3d
@ -442,6 +442,9 @@ pub enum Expression {
|
||||
Variable {
|
||||
name: ByteString,
|
||||
},
|
||||
DynamicVariable {
|
||||
name: Box<Self>,
|
||||
},
|
||||
Infix {
|
||||
lhs: Box<Self>,
|
||||
op: InfixOp,
|
||||
|
@ -1929,7 +1929,23 @@ impl Parser {
|
||||
let rhs = self.expression(rpred)?;
|
||||
|
||||
prefix(&op, rhs)
|
||||
},
|
||||
TokenKind::Dollar => {
|
||||
self.next();
|
||||
|
||||
match self.current.kind {
|
||||
TokenKind::LeftBrace => {
|
||||
self.next();
|
||||
|
||||
let name = self.expression(Precedence::Lowest)?;
|
||||
|
||||
self.rbrace()?;
|
||||
|
||||
Expression::DynamicVariable { name: Box::new(name) }
|
||||
},
|
||||
_ => todo!(),
|
||||
}
|
||||
},
|
||||
_ => todo!(
|
||||
"expr lhs: {:?}, line {} col {}",
|
||||
self.current.kind,
|
||||
@ -4200,6 +4216,15 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn braced_variables() {
|
||||
assert_ast("<?php ${'foo'};", &[
|
||||
expr!(Expression::DynamicVariable {
|
||||
name: Box::new(Expression::ConstantString { value: "foo".into() })
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
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