diff options
| author | Brian Anderson <[email protected]> | 2011-01-30 14:15:22 -0500 |
|---|---|---|
| committer | Brian Anderson <[email protected]> | 2011-01-30 14:15:22 -0500 |
| commit | 214c32393a9d28436dd782c9ea6e3e32d3baba2e (patch) | |
| tree | 129672e9cd9a9f43f6df7547e951bc742bade0d9 /src/comp/front | |
| parent | Fix a bug in linearize and get the captured tydescs type right. (diff) | |
| download | rust-214c32393a9d28436dd782c9ea6e3e32d3baba2e.tar.xz rust-214c32393a9d28436dd782c9ea6e3e32d3baba2e.zip | |
Teach rustc to parse 'else if'
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/parser.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index bef37a3c..fbed877f 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -895,8 +895,7 @@ impure fn parse_if_expr(parser p) -> @ast.expr { hi = thn.span; alt (p.peek()) { case (token.ELSE) { - p.bump(); - auto eblk = parse_block(p); + auto eblk = parse_else_block(p); els = some(eblk); hi = eblk.span; } @@ -905,6 +904,21 @@ impure fn parse_if_expr(parser p) -> @ast.expr { ret @spanned(lo, hi, ast.expr_if(cond, thn, els, ast.ann_none)); } +impure fn parse_else_block(parser p) -> ast.block { + expect(p, token.ELSE); + alt (p.peek()) { + case (token.IF) { + let vec[@ast.stmt] stmts = vec(); + auto ifexpr = parse_if_expr(p); + auto bloc = index_block(stmts, some(ifexpr)); + ret spanned(ifexpr.span, ifexpr.span, bloc); + } + case (_) { + ret parse_block(p); + } + } +} + impure fn parse_head_local(parser p) -> @ast.decl { auto lo = p.get_span(); let @ast.local local; |