AST - Fixed statement nodes with *Stmt names
This commit is contained in:
parent
6acf492aa2
commit
e4a86eb1de
3 changed files with 13 additions and 13 deletions
12
src/ast.rs
12
src/ast.rs
|
@ -26,20 +26,20 @@ pub enum StmtNode {
|
||||||
/// A block containing multiple statements.
|
/// A block containing multiple statements.
|
||||||
Block(Vec<StmtNode>),
|
Block(Vec<StmtNode>),
|
||||||
/// A conditional statement.
|
/// A conditional statement.
|
||||||
IfStmt {
|
If {
|
||||||
condition: ExprNode,
|
condition: ExprNode,
|
||||||
then_branch: Box<StmtNode>,
|
then_branch: Box<StmtNode>,
|
||||||
else_branch: Option<Box<StmtNode>>,
|
else_branch: Option<Box<StmtNode>>,
|
||||||
},
|
},
|
||||||
/// Loop statement.
|
/// Loop statement.
|
||||||
LoopStmt {
|
Loop {
|
||||||
label: Option<Token>,
|
label: Option<Token>,
|
||||||
condition: ExprNode,
|
condition: ExprNode,
|
||||||
body: Box<StmtNode>,
|
body: Box<StmtNode>,
|
||||||
after_body: Option<Box<StmtNode>>,
|
after_body: Option<Box<StmtNode>>,
|
||||||
},
|
},
|
||||||
/// Break or continue statement.
|
/// Break or continue statement.
|
||||||
LoopControlStmt {
|
LoopControl {
|
||||||
is_break: bool,
|
is_break: bool,
|
||||||
loop_name: Option<Token>,
|
loop_name: Option<Token>,
|
||||||
},
|
},
|
||||||
|
@ -155,7 +155,7 @@ impl AstDumper for StmtNode {
|
||||||
.join(" ")
|
.join(" ")
|
||||||
),
|
),
|
||||||
|
|
||||||
Self::IfStmt {
|
Self::If {
|
||||||
condition,
|
condition,
|
||||||
then_branch,
|
then_branch,
|
||||||
else_branch,
|
else_branch,
|
||||||
|
@ -169,7 +169,7 @@ impl AstDumper for StmtNode {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
Self::LoopStmt {
|
Self::Loop {
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body,
|
body,
|
||||||
|
@ -194,7 +194,7 @@ impl AstDumper for StmtNode {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::LoopControlStmt {
|
Self::LoopControl {
|
||||||
is_break,
|
is_break,
|
||||||
loop_name,
|
loop_name,
|
||||||
} => {
|
} => {
|
||||||
|
|
|
@ -98,18 +98,18 @@ impl Interpretable for ast::StmtNode {
|
||||||
ast::StmtNode::Expression(expr) => expr.interpret(environment),
|
ast::StmtNode::Expression(expr) => expr.interpret(environment),
|
||||||
ast::StmtNode::Print(expr) => self.on_print(environment, expr),
|
ast::StmtNode::Print(expr) => self.on_print(environment, expr),
|
||||||
ast::StmtNode::Block(statements) => self.on_block(environment, statements),
|
ast::StmtNode::Block(statements) => self.on_block(environment, statements),
|
||||||
ast::StmtNode::IfStmt {
|
ast::StmtNode::If {
|
||||||
condition,
|
condition,
|
||||||
then_branch,
|
then_branch,
|
||||||
else_branch,
|
else_branch,
|
||||||
} => self.on_if_statement(environment, condition, then_branch, else_branch),
|
} => self.on_if_statement(environment, condition, then_branch, else_branch),
|
||||||
ast::StmtNode::LoopStmt {
|
ast::StmtNode::Loop {
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body,
|
body,
|
||||||
after_body,
|
after_body,
|
||||||
} => self.on_loop_statement(environment, label, condition, body, after_body),
|
} => self.on_loop_statement(environment, label, condition, body, after_body),
|
||||||
ast::StmtNode::LoopControlStmt {
|
ast::StmtNode::LoopControl {
|
||||||
is_break,
|
is_break,
|
||||||
loop_name,
|
loop_name,
|
||||||
} => self.on_loop_control_statemement(*is_break, loop_name),
|
} => self.on_loop_control_statemement(*is_break, loop_name),
|
||||||
|
|
|
@ -261,7 +261,7 @@ impl Parser {
|
||||||
Some(_) => Some(Box::new(self.parse_statement()?)),
|
Some(_) => Some(Box::new(self.parse_statement()?)),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
Ok(ast::StmtNode::IfStmt {
|
Ok(ast::StmtNode::If {
|
||||||
condition: expression,
|
condition: expression,
|
||||||
then_branch,
|
then_branch,
|
||||||
else_branch,
|
else_branch,
|
||||||
|
@ -313,7 +313,7 @@ impl Parser {
|
||||||
self.loop_state.pop();
|
self.loop_state.pop();
|
||||||
result?
|
result?
|
||||||
});
|
});
|
||||||
Ok(ast::StmtNode::LoopStmt {
|
Ok(ast::StmtNode::Loop {
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body,
|
body,
|
||||||
|
@ -373,7 +373,7 @@ impl Parser {
|
||||||
self.loop_state.pop();
|
self.loop_state.pop();
|
||||||
result?
|
result?
|
||||||
};
|
};
|
||||||
let while_stmt = ast::StmtNode::LoopStmt {
|
let while_stmt = ast::StmtNode::Loop {
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body: Box::new(body_stmt),
|
body: Box::new(body_stmt),
|
||||||
|
@ -420,7 +420,7 @@ impl Parser {
|
||||||
&TokenType::Semicolon,
|
&TokenType::Semicolon,
|
||||||
"';' expected after loop control statement",
|
"';' expected after loop control statement",
|
||||||
)?;
|
)?;
|
||||||
Ok(ast::StmtNode::LoopControlStmt {
|
Ok(ast::StmtNode::LoopControl {
|
||||||
is_break: stmt_token.token_type == TokenType::Break,
|
is_break: stmt_token.token_type == TokenType::Break,
|
||||||
loop_name,
|
loop_name,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue