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.
This commit is contained in:
parent
0c913e63d9
commit
5e1a6dac44
2 changed files with 13 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue