AST - Refactored variable reference expressions
This commit is contained in:
parent
75387c5ac4
commit
bb2765d057
2 changed files with 12 additions and 7 deletions
15
src/ast.rs
15
src/ast.rs
|
@ -105,6 +105,15 @@ pub struct BinaryExpr {
|
|||
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.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ExprNode {
|
||||
|
@ -135,11 +144,7 @@ pub enum ExprNode {
|
|||
Litteral { value: Token },
|
||||
|
||||
/// A reference to a variable.
|
||||
Variable {
|
||||
name: Token,
|
||||
/// Identifier used for variable resolution.
|
||||
id: usize,
|
||||
},
|
||||
Variable(VariableExpr),
|
||||
|
||||
/// A lambda function.
|
||||
Lambda {
|
||||
|
|
|
@ -217,8 +217,8 @@ fn dump_expr_node(dumper: &mut Dumper, expr: &ExprNode) {
|
|||
dumper.current_line().push_str(&value.lexeme);
|
||||
}
|
||||
|
||||
ExprNode::Variable { name, id: _ } => {
|
||||
dumper.current_line().push_str(&name.lexeme);
|
||||
ExprNode::Variable(var) => {
|
||||
dumper.current_line().push_str(&var.token.lexeme);
|
||||
}
|
||||
|
||||
ExprNode::Lambda { params, body } => {
|
||||
|
|
Loading…
Reference in a new issue