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
This commit is contained in:
Austin Seipp 2012-01-09 09:42:07 -06:00 committed by Brian Anderson
parent fbad0204e4
commit 9211348989
2 changed files with 6 additions and 2 deletions

View File

@ -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}];
}

View File

@ -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,