AST - Added labels to while statements
This commit is contained in:
parent
bf8eee7ecb
commit
2f44a81b6d
1 changed files with 16 additions and 2 deletions
18
src/ast.rs
18
src/ast.rs
|
@ -27,6 +27,7 @@ pub enum StmtNode {
|
|||
},
|
||||
/// While loop statement.
|
||||
WhileStmt {
|
||||
label: Option<Token>,
|
||||
condition: ExprNode,
|
||||
body: Box<StmtNode>,
|
||||
},
|
||||
|
@ -124,8 +125,21 @@ impl AstDumper for StmtNode {
|
|||
),
|
||||
},
|
||||
|
||||
Self::WhileStmt { condition, body } => {
|
||||
format!("( while {} {} )", condition.dump(), body.dump())
|
||||
Self::WhileStmt {
|
||||
label,
|
||||
condition,
|
||||
body,
|
||||
} => {
|
||||
format!(
|
||||
"( {}while {} {} )",
|
||||
if let Some(label) = label {
|
||||
&format!("@{} ", label.lexeme)
|
||||
} else {
|
||||
""
|
||||
},
|
||||
condition.dump(),
|
||||
body.dump()
|
||||
)
|
||||
}
|
||||
|
||||
Self::LoopControlStmt {
|
||||
|
|
Loading…
Reference in a new issue