AST - Fixed statement nodes with *Stmt names

This commit is contained in:
Emmanuel BENOîT 2023-01-02 20:13:51 +01:00
parent 6acf492aa2
commit e4a86eb1de
3 changed files with 13 additions and 13 deletions

View file

@ -26,20 +26,20 @@ pub enum StmtNode {
/// A block containing multiple statements.
Block(Vec<StmtNode>),
/// A conditional statement.
IfStmt {
If {
condition: ExprNode,
then_branch: Box<StmtNode>,
else_branch: Option<Box<StmtNode>>,
},
/// Loop statement.
LoopStmt {
Loop {
label: Option<Token>,
condition: ExprNode,
body: Box<StmtNode>,
after_body: Option<Box<StmtNode>>,
},
/// Break or continue statement.
LoopControlStmt {
LoopControl {
is_break: bool,
loop_name: Option<Token>,
},
@ -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,
} => {

View file

@ -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),

View file

@ -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,
})