From d821331fa26c9d6c6f1988871b699c3f5cc88a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 15:44:26 +0100 Subject: [PATCH] Parser - Variable references in expressions --- src/parser.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 76e5cca..5c71870 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -214,6 +214,7 @@ impl Parser { /// ``` /// primary := "(" expression ")" /// primary := FALSE | TRUE | NIL | STRING | NUMBER + /// primary := IDENTIFIER /// ``` fn parse_primary(&mut self) -> Result { if self.expect(&[TokenType::LeftParen]).is_some() { @@ -231,6 +232,9 @@ impl Parser { TokenType::Number(_) | &TokenType::String(_) => Ok(ast::ExprNode::Litteral { value: self.advance().clone(), }), + TokenType::Identifier(_) => Ok(ast::ExprNode::Variable { + name: self.advance().clone(), + }), _ => Err(ParserError::new(self.peek(), "expected expression")), } }