AST - Changed loop representation
This commit is contained in:
parent
06ae3dd973
commit
ca76b3ab3f
1 changed files with 17 additions and 4 deletions
21
src/ast.rs
21
src/ast.rs
|
@ -25,11 +25,12 @@ pub enum StmtNode {
|
|||
then_branch: Box<StmtNode>,
|
||||
else_branch: Option<Box<StmtNode>>,
|
||||
},
|
||||
/// While loop statement.
|
||||
WhileStmt {
|
||||
/// Loop statement.
|
||||
LoopStmt {
|
||||
label: Option<Token>,
|
||||
condition: ExprNode,
|
||||
body: Box<StmtNode>,
|
||||
after_body: Option<Box<StmtNode>>,
|
||||
},
|
||||
/// 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 {
|
||||
|
|
Loading…
Reference in a new issue