From 2f44a81b6d0ddbca016e3b258c669c647c24e1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 2 Jan 2023 10:37:47 +0100 Subject: [PATCH] AST - Added labels to while statements --- src/ast.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 3d73d33..50707e0 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -27,6 +27,7 @@ pub enum StmtNode { }, /// While loop statement. WhileStmt { + label: Option, condition: ExprNode, body: Box, }, @@ -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 {