diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-07-13 15:00:59 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-07-13 15:00:59 -0700 |
| commit | 5e1a6dac4409ba2f584fb41d0759e6c79ec8a8c4 (patch) | |
| tree | 94f411bec7c364cf41e6361e6e93d0df33dd3b49 /src/comp/syntax/parse | |
| parent | 0c913e63d926fc8cf1dd06260546b16f5aa90402 (diff) | |
| download | rust-5e1a6dac4409ba2f584fb41d0759e6c79ec8a8c4.tar.gz rust-5e1a6dac4409ba2f584fb41d0759e6c79ec8a8c4.zip | |
Parse nullary ret correctly
ret is similar to fail: if not followed by an expression, it should be parsed as a ret without an argument. The old version would fail if ret was followed by a close paren (for example). Fixed it. Closes #676.
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index fb9eca8640d..b2aa0e7b4dc 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -948,15 +948,13 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { hi = e.span.hi; ex = ast::expr_check(ast::unchecked, e); } else if (eat_word(p, "ret")) { - alt (p.peek()) { - case (token::SEMI) { ex = ast::expr_ret(none); } - // Handle ret as the block result expression - case (token::RBRACE) { ex = ast::expr_ret(none); } - case (_) { - auto e = parse_expr(p); - hi = e.span.hi; - ex = ast::expr_ret(some(e)); - } + if (can_begin_expr(p.peek())) { + auto e = parse_expr(p); + hi = e.span.hi; + ex = ast::expr_ret(some(e)); + } + else { + ex = ast::expr_ret(none); } } else if (eat_word(p, "break")) { ex = ast::expr_break; |
