From 3fe2b4256a08ed25af8239208725f4f519cc63ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 16:58:48 +0100 Subject: [PATCH] AST - Blocks --- src/ast.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index 51a5b05..fbf7561 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -17,6 +17,8 @@ pub enum StmtNode { Expression(ExprNode), /// The print statement Print(ExprNode), + /// A block containing multiple statements. + Block(Vec>), } /// 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::Expression(expr) => format!("( {} )", expr.dump()), Self::Print(expr) => format!("(print {})", expr.dump()), + Self::Block(stmts) => stmts + .iter() + .map(|s| s.dump()) + .collect::>() + .join(" "), } } }