diff --git a/src/ast.rs b/src/ast.rs index 0d63d8e..ff07c11 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -25,11 +25,12 @@ pub enum StmtNode { then_branch: Box, else_branch: Option>, }, - /// While loop statement. - WhileStmt { + /// Loop statement. + LoopStmt { label: Option, condition: ExprNode, body: Box, + after_body: Option>, }, /// Break or continue statement. LoopControlStmt { @@ -125,17 +126,29 @@ impl AstDumper for StmtNode { ), }, - Self::WhileStmt { + Self::LoopStmt { label, condition, body, + after_body, } => { let ltxt = if let Some(label) = label { format!("@{} ", label.lexeme) } else { "".to_string() }; - format!("( {}while {} {} )", ltxt, condition.dump(), body.dump()) + let abtxt = if let Some(after_body) = after_body { + format!("{} ", after_body.dump()) + } else { + "".to_string() + }; + format!( + "( {}loop {} {} {})", + ltxt, + condition.dump(), + body.dump(), + abtxt + ) } Self::LoopControlStmt {