diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-06 17:14:32 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-07 12:23:43 -0700 |
| commit | 2772b2e5c7f85e230bcae13c49eb1386afc6cd0e (patch) | |
| tree | 6161076f339dc2adeffcfbc8bcb6e86882b7b16d /src/libsyntax/parse | |
| parent | abf4421e7c2fce4e768eb20c126989501081f4f9 (diff) | |
| download | rust-2772b2e5c7f85e230bcae13c49eb1386afc6cd0e.tar.gz rust-2772b2e5c7f85e230bcae13c49eb1386afc6cd0e.zip | |
syntax: Make match arm parsing more restrictive again
Require comma separators for all expression types except the plain block
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 6 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 38599907e6f..a77c613cb60 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -13,6 +13,13 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { } } +fn expr_is_simple_block(e: @ast::expr) -> bool { + match e.node { + ast::expr_block({node: {rules: ast::default_blk, _}, _}) => true, + _ => false + } +} + fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { match stmt.node { ast::stmt_decl(d, _) => { @@ -52,7 +59,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool { @{node: ast::lit_int(_, ast::ty_i), _} | @{node: ast::lit_int_unsuffixed(_), _} => true, _ => false - } + }, ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) | ast::expr_move(_, sub) | ast::expr_copy(sub) | ast::expr_assign(_, sub) | @@ -63,7 +70,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool { ast::expr_fail(osub) | ast::expr_ret(osub) => match osub { some(ex) => ends_in_lit_int(ex), _ => false - } + }, _ => false } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5b889b4ad96..c675af6803c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -963,7 +963,7 @@ class parser { hi = self.span.hi; ex = expr_vstore(self.mk_expr(lo, hi, ex), vstore_fixed(v)); } - } + }, _ => () } @@ -1579,7 +1579,7 @@ class parser { let expr = self.parse_expr_res(RESTRICT_STMT_EXPR); let require_comma = - classify::expr_requires_semi_to_be_stmt(expr) + !classify::expr_is_simple_block(expr) && self.token != token::RBRACE; if require_comma { @@ -1839,7 +1839,7 @@ class parser { (token::COMMA), |p| p.parse_pat(refutable)); } - } + }, _ => () } // at this point, we're not sure whether it's a |
