Parser - Use new loop AST node
This commit is contained in:
parent
c407fcd546
commit
4c54643a8d
1 changed files with 8 additions and 15 deletions
|
@ -250,10 +250,11 @@ impl Parser {
|
||||||
self.loop_state.pop();
|
self.loop_state.pop();
|
||||||
result?
|
result?
|
||||||
});
|
});
|
||||||
Ok(ast::StmtNode::WhileStmt {
|
Ok(ast::StmtNode::LoopStmt {
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body,
|
body,
|
||||||
|
after_body: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,22 +310,14 @@ impl Parser {
|
||||||
self.loop_state.pop();
|
self.loop_state.pop();
|
||||||
result?
|
result?
|
||||||
};
|
};
|
||||||
let body_with_incr = if let Some(incr) = increment {
|
let while_stmt = ast::StmtNode::LoopStmt {
|
||||||
let incr_stmt = Box::new(ast::StmtNode::Expression(incr));
|
|
||||||
let body_block = if let ast::StmtNode::Block(mut body_block) = body_stmt {
|
|
||||||
body_block.push(incr_stmt);
|
|
||||||
body_block
|
|
||||||
} else {
|
|
||||||
vec![Box::new(body_stmt), incr_stmt]
|
|
||||||
};
|
|
||||||
ast::StmtNode::Block(body_block)
|
|
||||||
} else {
|
|
||||||
body_stmt
|
|
||||||
};
|
|
||||||
let while_stmt = ast::StmtNode::WhileStmt {
|
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body: Box::new(body_with_incr),
|
body: Box::new(body_stmt),
|
||||||
|
after_body: match increment {
|
||||||
|
Some(incr) => Some(Box::new(ast::StmtNode::Expression(incr))),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
if let Some(init_stmt) = initializer {
|
if let Some(init_stmt) = initializer {
|
||||||
Ok(ast::StmtNode::Block(vec![
|
Ok(ast::StmtNode::Block(vec![
|
||||||
|
|
Loading…
Reference in a new issue