Skip to content

Commit fab57f1

Browse files
committed
---
yaml --- r: 3604 b: refs/heads/master c: 8e585e7 h: refs/heads/master v: v3
1 parent e9997e5 commit fab57f1

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 7661c08496b0dc9ce55657246f8e5e42051c812e
2+
refs/heads/master: 8e585e7008ac5b01c76b6f5830aa9e3104d83bbd

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,7 @@ fn parse_if_expr_1(&parser p) -> tup(@ast::expr,
12231223
ast::block, option::t[@ast::expr],
12241224
uint, uint) {
12251225
auto lo = p.get_last_lo_pos();
1226-
expect(p, token::LPAREN);
12271226
auto cond = parse_expr(p);
1228-
expect(p, token::RPAREN);
12291227
auto thn = parse_block(p);
12301228
let option::t[@ast::expr] els = none;
12311229
auto hi = thn.span.hi;
@@ -1292,9 +1290,7 @@ fn parse_for_expr(&parser p) -> @ast::expr {
12921290

12931291
fn parse_while_expr(&parser p) -> @ast::expr {
12941292
auto lo = p.get_last_lo_pos();
1295-
expect(p, token::LPAREN);
12961293
auto cond = parse_expr(p);
1297-
expect(p, token::RPAREN);
12981294
auto body = parse_block(p);
12991295
auto hi = body.span.hi;
13001296
ret mk_expr(p, lo, hi, ast::expr_while(cond, body));
@@ -1304,34 +1300,27 @@ fn parse_do_while_expr(&parser p) -> @ast::expr {
13041300
auto lo = p.get_last_lo_pos();
13051301
auto body = parse_block(p);
13061302
expect_word(p, "while");
1307-
expect(p, token::LPAREN);
13081303
auto cond = parse_expr(p);
1309-
expect(p, token::RPAREN);
13101304
auto hi = cond.span.hi;
13111305
ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond));
13121306
}
13131307

13141308
fn parse_alt_expr(&parser p) -> @ast::expr {
13151309
auto lo = p.get_last_lo_pos();
1316-
expect(p, token::LPAREN);
13171310
auto discriminant = parse_expr(p);
1318-
expect(p, token::RPAREN);
13191311
expect(p, token::LBRACE);
13201312
let vec[ast::arm] arms = [];
13211313
while (p.peek() != token::RBRACE) {
1322-
if (eat_word(p, "case")) {
1323-
expect(p, token::LPAREN);
1324-
auto pat = parse_pat(p);
1325-
expect(p, token::RPAREN);
1326-
auto block = parse_block(p);
1327-
arms += [rec(pat=pat, block=block)];
1328-
} else if (p.peek() == token::RBRACE) {
1329-
/* empty */
1330-
1331-
} else {
1332-
p.fatal("expected 'case' or '}' when parsing 'alt' statement " +
1333-
"but found " + token::to_str(p.get_reader(), p.peek()));
1334-
}
1314+
// Optionally eat the case keyword.
1315+
// FIXME remove this (and the optional parens) once we've updated our
1316+
// code to not use the old syntax
1317+
eat_word(p, "case");
1318+
auto parens = false;
1319+
if (p.peek() == token::LPAREN) { parens = true; p.bump(); }
1320+
auto pat = parse_pat(p);
1321+
if (parens) { expect(p, token::RPAREN); }
1322+
auto block = parse_block(p);
1323+
arms += [rec(pat=pat, block=block)];
13351324
}
13361325
auto hi = p.get_hi_pos();
13371326
p.bump();

trunk/src/test/run-pass/paren-free.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {
2+
auto x = true;
3+
if x {
4+
auto i = 10;
5+
while i > 0 { i -= 1; }
6+
}
7+
alt x {
8+
true { log "right"; }
9+
false { log "wrong"; }
10+
}
11+
}

0 commit comments

Comments
 (0)