summaryrefslogtreecommitdiff
path: root/src/pretty.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-24 21:29:32 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-24 21:29:32 +0100
commitf084165eabbb8ad1b8e8969078fce89070ab4d96 (patch)
tree6003822cc646ecf0ba6a3070c87ab283503a4c3b /src/pretty.rs
parentdae3dad5407e49715736a2a3d8735e65027e6c11 (diff)
While loops 🔁
Diffstat (limited to 'src/pretty.rs')
-rw-r--r--src/pretty.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/pretty.rs b/src/pretty.rs
index de910b99..0899824a 100644
--- a/src/pretty.rs
+++ b/src/pretty.rs
@@ -221,6 +221,7 @@ impl Pretty for Expr {
Self::Call(v) => v.pretty(p),
Self::Let(v) => v.pretty(p),
Self::If(v) => v.pretty(p),
+ Self::While(v) => v.pretty(p),
Self::For(v) => v.pretty(p),
}
}
@@ -413,6 +414,15 @@ impl Pretty for ExprIf {
}
}
+impl Pretty for ExprWhile {
+ fn pretty(&self, p: &mut Printer) {
+ p.push_str("while ");
+ self.condition.pretty(p);
+ p.push(' ');
+ self.body.pretty(p);
+ }
+}
+
impl Pretty for ExprFor {
fn pretty(&self, p: &mut Printer) {
p.push_str("for ");
@@ -718,9 +728,10 @@ mod tests {
// Keywords.
roundtrip("#let x = 1 + 2");
+ test_parse("#if x [y] #else [z]", "#if x [y] else [z]");
+ roundtrip("#while x {y}");
roundtrip("#for x in y {z}");
roundtrip("#for k, x in y {z}");
- test_parse("#if x [y] #else [z]", "#if x [y] else [z]");
}
#[test]