AST - Blocks
This commit is contained in:
parent
c71bdd8c87
commit
3fe2b4256a
1 changed files with 7 additions and 0 deletions
|
@ -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(" "),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue