AST - Added labels to while statements

This commit is contained in:
Emmanuel BENOîT 2023-01-02 10:37:47 +01:00
parent bf8eee7ecb
commit 2f44a81b6d

View file

@ -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 {