AST - Refactored variable reference expressions

This commit is contained in:
Emmanuel BENOîT 2023-01-09 07:43:45 +01:00
parent 75387c5ac4
commit bb2765d057
2 changed files with 12 additions and 7 deletions

View file

@ -105,6 +105,15 @@ pub struct BinaryExpr {
pub right: Box<ExprNode>, pub right: Box<ExprNode>,
} }
/// A variable reference expression.
#[derive(Debug, Clone)]
pub struct VariableExpr {
/// The name of the variable, or the "this" keyword.
pub token: Token,
/// Identifier used for variable resolution.
pub id: usize,
}
/// An AST node that represents an expression. /// An AST node that represents an expression.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ExprNode { pub enum ExprNode {
@ -135,11 +144,7 @@ pub enum ExprNode {
Litteral { value: Token }, Litteral { value: Token },
/// A reference to a variable. /// A reference to a variable.
Variable { Variable(VariableExpr),
name: Token,
/// Identifier used for variable resolution.
id: usize,
},
/// A lambda function. /// A lambda function.
Lambda { Lambda {

View file

@ -217,8 +217,8 @@ fn dump_expr_node(dumper: &mut Dumper, expr: &ExprNode) {
dumper.current_line().push_str(&value.lexeme); dumper.current_line().push_str(&value.lexeme);
} }
ExprNode::Variable { name, id: _ } => { ExprNode::Variable(var) => {
dumper.current_line().push_str(&name.lexeme); dumper.current_line().push_str(&var.token.lexeme);
} }
ExprNode::Lambda { params, body } => { ExprNode::Lambda { params, body } => {