AST - Variable assignment

This commit is contained in:
Emmanuel BENOîT 2022-12-31 16:16:12 +01:00
parent c486b81cba
commit b5ff24ffad

View file

@ -22,6 +22,9 @@ pub enum StmtNode {
/// An AST node that represents an expression.
#[derive(Debug, Clone)]
pub enum ExprNode {
/// Assignment to a variable.
Assignment { name: Token, value: Box<ExprNode> },
/// Binary expression.
Binary {
left: Box<ExprNode>,
@ -79,6 +82,7 @@ impl AstDumper for StmtNode {
impl AstDumper for ExprNode {
fn dump(&self) -> String {
match self {
Self::Assignment { name, value } => format!("( = {} {} )", name.lexeme, value.dump()),
Self::Binary {
left,
operator,