AST - Blocks

This commit is contained in:
Emmanuel BENOîT 2022-12-31 16:58:48 +01:00
parent c71bdd8c87
commit 3fe2b4256a

View file

@ -17,6 +17,8 @@ pub enum StmtNode {
Expression(ExprNode), Expression(ExprNode),
/// The print statement /// The print statement
Print(ExprNode), Print(ExprNode),
/// A block containing multiple statements.
Block(Vec<Box<StmtNode>>),
} }
/// An AST node that represents an expression. /// An AST node that represents an expression.
@ -75,6 +77,11 @@ impl AstDumper for StmtNode {
Self::VarDecl(name, None) => format!("( var {} nil )", name.lexeme), Self::VarDecl(name, None) => format!("( var {} nil )", name.lexeme),
Self::Expression(expr) => format!("( {} )", expr.dump()), Self::Expression(expr) => format!("( {} )", expr.dump()),
Self::Print(expr) => format!("(print {})", expr.dump()), Self::Print(expr) => format!("(print {})", expr.dump()),
Self::Block(stmts) => stmts
.iter()
.map(|s| s.dump())
.collect::<Vec<String>>()
.join(" "),
} }
} }
} }