diff --git a/src/ast.rs b/src/ast.rs index 39b0cd9..808737d 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -26,20 +26,20 @@ pub enum StmtNode { /// A block containing multiple statements. Block(Vec), /// A conditional statement. - IfStmt { + If { condition: ExprNode, then_branch: Box, else_branch: Option>, }, /// Loop statement. - LoopStmt { + Loop { label: Option, condition: ExprNode, body: Box, after_body: Option>, }, /// Break or continue statement. - LoopControlStmt { + LoopControl { is_break: bool, loop_name: Option, }, @@ -155,7 +155,7 @@ impl AstDumper for StmtNode { .join(" ") ), - Self::IfStmt { + Self::If { condition, then_branch, else_branch, @@ -169,7 +169,7 @@ impl AstDumper for StmtNode { ), }, - Self::LoopStmt { + Self::Loop { label, condition, body, @@ -194,7 +194,7 @@ impl AstDumper for StmtNode { ) } - Self::LoopControlStmt { + Self::LoopControl { is_break, loop_name, } => { diff --git a/src/interpreter/interpretable.rs b/src/interpreter/interpretable.rs index 1edb826..39030e0 100644 --- a/src/interpreter/interpretable.rs +++ b/src/interpreter/interpretable.rs @@ -98,18 +98,18 @@ impl Interpretable for ast::StmtNode { ast::StmtNode::Expression(expr) => expr.interpret(environment), ast::StmtNode::Print(expr) => self.on_print(environment, expr), ast::StmtNode::Block(statements) => self.on_block(environment, statements), - ast::StmtNode::IfStmt { + ast::StmtNode::If { condition, then_branch, else_branch, } => self.on_if_statement(environment, condition, then_branch, else_branch), - ast::StmtNode::LoopStmt { + ast::StmtNode::Loop { label, condition, body, after_body, } => self.on_loop_statement(environment, label, condition, body, after_body), - ast::StmtNode::LoopControlStmt { + ast::StmtNode::LoopControl { is_break, loop_name, } => self.on_loop_control_statemement(*is_break, loop_name), diff --git a/src/parser.rs b/src/parser.rs index 0aff5f1..e00a740 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -261,7 +261,7 @@ impl Parser { Some(_) => Some(Box::new(self.parse_statement()?)), None => None, }; - Ok(ast::StmtNode::IfStmt { + Ok(ast::StmtNode::If { condition: expression, then_branch, else_branch, @@ -313,7 +313,7 @@ impl Parser { self.loop_state.pop(); result? }); - Ok(ast::StmtNode::LoopStmt { + Ok(ast::StmtNode::Loop { label, condition, body, @@ -373,7 +373,7 @@ impl Parser { self.loop_state.pop(); result? }; - let while_stmt = ast::StmtNode::LoopStmt { + let while_stmt = ast::StmtNode::Loop { label, condition, body: Box::new(body_stmt), @@ -420,7 +420,7 @@ impl Parser { &TokenType::Semicolon, "';' expected after loop control statement", )?; - Ok(ast::StmtNode::LoopControlStmt { + Ok(ast::StmtNode::LoopControl { is_break: stmt_token.token_type == TokenType::Break, loop_name, })