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.
|
/// While loop statement.
|
||||||
WhileStmt {
|
WhileStmt {
|
||||||
|
label: Option<Token>,
|
||||||
condition: ExprNode,
|
condition: ExprNode,
|
||||||
body: Box<StmtNode>,
|
body: Box<StmtNode>,
|
||||||
},
|
},
|
||||||
|
@ -124,8 +125,21 @@ impl AstDumper for StmtNode {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
Self::WhileStmt { condition, body } => {
|
Self::WhileStmt {
|
||||||
format!("( while {} {} )", condition.dump(), body.dump())
|
label,
|
||||||
|
condition,
|
||||||
|
body,
|
||||||
|
} => {
|
||||||
|
format!(
|
||||||
|
"( {}while {} {} )",
|
||||||
|
if let Some(label) = label {
|
||||||
|
&format!("@{} ", label.lexeme)
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
condition.dump(),
|
||||||
|
body.dump()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::LoopControlStmt {
|
Self::LoopControlStmt {
|
||||||
|
|
Loading…
Reference in a new issue