Skip to content

Commit 9211348

Browse files
Austin Seippbrson
authored andcommitted
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
1 parent fbad020 commit 9211348

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/comp/syntax/parse/parser.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,11 @@ fn parse_alt_expr(p: parser) -> @ast::expr {
13891389
while p.peek() != token::RBRACE {
13901390
let pats = parse_pats(p);
13911391
let guard = none;
1392-
if eat_word(p, "when") { guard = some(parse_expr(p)); }
1392+
if eat_word(p, "when") {
1393+
guard = some(parse_expr(p));
1394+
} else if eat_word(p, "if") {
1395+
guard = some(parse_expr(p));
1396+
}
13931397
let blk = parse_block(p);
13941398
arms += [{pats: pats, guard: guard, body: blk}];
13951399
}

src/comp/syntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
843843
}
844844
space(s.s);
845845
alt arm.guard {
846-
some(e) { word_space(s, "when"); print_expr(s, e); space(s.s); }
846+
some(e) { word_space(s, "if"); print_expr(s, e); space(s.s); }
847847
none. { }
848848
}
849849
print_possibly_embedded_block(s, arm.body, block_normal,

0 commit comments

Comments
 (0)