diff --git a/trunk_parser/src/ast.rs b/trunk_parser/src/ast.rs index ab3506a..3e18ca5 100644 --- a/trunk_parser/src/ast.rs +++ b/trunk_parser/src/ast.rs @@ -442,6 +442,9 @@ pub enum Expression { Variable { name: ByteString, }, + DynamicVariable { + name: Box, + }, Infix { lhs: Box, op: InfixOp, diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index 016a086..14c1bf2 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -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("