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>,
|
then_branch: Box<StmtNode>,
|
||||||
else_branch: Option<Box<StmtNode>>,
|
else_branch: Option<Box<StmtNode>>,
|
||||||
},
|
},
|
||||||
/// While loop statement.
|
/// Loop statement.
|
||||||
WhileStmt {
|
LoopStmt {
|
||||||
label: Option<Token>,
|
label: Option<Token>,
|
||||||
condition: ExprNode,
|
condition: ExprNode,
|
||||||
body: Box<StmtNode>,
|
body: Box<StmtNode>,
|
||||||
|
after_body: Option<Box<StmtNode>>,
|
||||||
},
|
},
|
||||||
/// Break or continue statement.
|
/// Break or continue statement.
|
||||||
LoopControlStmt {
|
LoopControlStmt {
|
||||||
|
@ -125,17 +126,29 @@ impl AstDumper for StmtNode {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
Self::WhileStmt {
|
Self::LoopStmt {
|
||||||
label,
|
label,
|
||||||
condition,
|
condition,
|
||||||
body,
|
body,
|
||||||
|
after_body,
|
||||||
} => {
|
} => {
|
||||||
let ltxt = if let Some(label) = label {
|
let ltxt = if let Some(label) = label {
|
||||||
format!("@{} ", label.lexeme)
|
format!("@{} ", label.lexeme)
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".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 {
|
Self::LoopControlStmt {
|
||||||
|
|
Loading…
Reference in a new issue