From a90b1529ad24b05d44c9ac5bdcba9f48d4a6b5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 15:42:10 +0100 Subject: [PATCH] AST - Added variable reference nodes --- src/ast.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index a4e99ce..0cf5576 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -40,6 +40,9 @@ pub enum ExprNode { /// A litteral value, represented by the corresponding token. Litteral { value: Token }, + + /// A reference to a variable. + Variable { name: Token }, } /* -------------------------------- * @@ -80,15 +83,10 @@ impl AstDumper for ExprNode { left, operator, right, - } => { - format!("( {} {} {} )", operator.lexeme, left.dump(), right.dump()) - } - Self::Unary { operator, right } => { - format!("( {} {} )", operator.lexeme, right.dump()) - } - Self::Grouping { expression } => { - format!("( {} )", expression.dump()) - } + } => format!("( {} {} {} )", operator.lexeme, left.dump(), right.dump()), + Self::Unary { operator, right } => format!("( {} {} )", operator.lexeme, right.dump()), + Self::Grouping { expression } => format!("( {} )", expression.dump()), + Self::Variable { name } => name.lexeme.clone(), Self::Litteral { value } => { if value.is_litteral() { value.lexeme.clone()