AST - Added variable reference nodes
This commit is contained in:
parent
447e0fe623
commit
a90b1529ad
1 changed files with 7 additions and 9 deletions
16
src/ast.rs
16
src/ast.rs
|
@ -40,6 +40,9 @@ pub enum ExprNode {
|
||||||
|
|
||||||
/// A litteral value, represented by the corresponding token.
|
/// A litteral value, represented by the corresponding token.
|
||||||
Litteral { value: Token },
|
Litteral { value: Token },
|
||||||
|
|
||||||
|
/// A reference to a variable.
|
||||||
|
Variable { name: Token },
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------- *
|
/* -------------------------------- *
|
||||||
|
@ -80,15 +83,10 @@ impl AstDumper for ExprNode {
|
||||||
left,
|
left,
|
||||||
operator,
|
operator,
|
||||||
right,
|
right,
|
||||||
} => {
|
} => format!("( {} {} {} )", operator.lexeme, left.dump(), right.dump()),
|
||||||
format!("( {} {} {} )", operator.lexeme, left.dump(), right.dump())
|
Self::Unary { operator, right } => format!("( {} {} )", operator.lexeme, right.dump()),
|
||||||
}
|
Self::Grouping { expression } => format!("( {} )", expression.dump()),
|
||||||
Self::Unary { operator, right } => {
|
Self::Variable { name } => name.lexeme.clone(),
|
||||||
format!("( {} {} )", operator.lexeme, right.dump())
|
|
||||||
}
|
|
||||||
Self::Grouping { expression } => {
|
|
||||||
format!("( {} )", expression.dump())
|
|
||||||
}
|
|
||||||
Self::Litteral { value } => {
|
Self::Litteral { value } => {
|
||||||
if value.is_litteral() {
|
if value.is_litteral() {
|
||||||
value.lexeme.clone()
|
value.lexeme.clone()
|
||||||
|
|
Loading…
Reference in a new issue