about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAustin Seipp <as@hacks.yi.org>2012-01-09 09:42:07 -0600
committerBrian Anderson <banderson@mozilla.com>2012-01-09 10:50:33 -0800
commit92113489893105d5432df2fd8f727fa2ca8cec51 (patch)
treec83e2dc2a69fe23b2b62a2d5bbcbdecc699d9884 /src
parentfbad0204e477537e350963014af936b1646d6d7a (diff)
downloadrust-92113489893105d5432df2fd8f727fa2ca8cec51.tar.gz
rust-92113489893105d5432df2fd8f727fa2ca8cec51.zip
Make the parser accept 'if' as an alternative to 'when' in alt patterns.
Also fix the pretty printer, making it output 'if' instead of 'when'.

Issue #1396
Diffstat (limited to 'src')
-rw-r--r--src/comp/syntax/parse/parser.rs6
-rw-r--r--src/comp/syntax/print/pprust.rs2
2 files changed, 6 insertions, 2 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 6a59b395ab4..2b45115f5b9 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1389,7 +1389,11 @@ fn parse_alt_expr(p: parser) -> @ast::expr {
     while p.peek() != token::RBRACE {
         let pats = parse_pats(p);
         let guard = none;
-        if eat_word(p, "when") { guard = some(parse_expr(p)); }
+        if eat_word(p, "when") {
+            guard = some(parse_expr(p));
+        } else if eat_word(p, "if") {
+            guard = some(parse_expr(p));
+        }
         let blk = parse_block(p);
         arms += [{pats: pats, guard: guard, body: blk}];
     }
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 3e9eab79281..b4a47a8db38 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -843,7 +843,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
             }
             space(s.s);
             alt arm.guard {
-              some(e) { word_space(s, "when"); print_expr(s, e); space(s.s); }
+              some(e) { word_space(s, "if"); print_expr(s, e); space(s.s); }
               none. { }
             }
             print_possibly_embedded_block(s, arm.body, block_normal,