diff options
| author | Patrick Walton <[email protected]> | 2010-10-11 17:21:36 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2010-10-11 17:21:36 -0700 |
| commit | a2c98794426209f90ebdb25a9d4c64e3c8546716 (patch) | |
| tree | 90b5f21c41ca4401e8a51a056e158473ed3aa674 /src/comp/front/parser.rs | |
| parent | Use new and delete instead of alloca(). Should put out the burning tinderbox. (diff) | |
| download | rust-a2c98794426209f90ebdb25a9d4c64e3c8546716.tar.xz rust-a2c98794426209f90ebdb25a9d4c64e3c8546716.zip | |
rustc: Say "expected expression" instead of "expected literal" when we expect an expression
Diffstat (limited to 'src/comp/front/parser.rs')
| -rw-r--r-- | src/comp/front/parser.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 8e848afb..2571c5d7 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -141,7 +141,7 @@ io fn parse_seq[T](token.token bra, ret spanned(lo, hi, v); } -io fn parse_lit(parser p) -> @ast.lit { +io fn parse_lit(parser p) -> option[ast.lit] { auto lo = p.get_span(); let ast.lit_ lit; alt (p.peek()) { @@ -166,12 +166,11 @@ io fn parse_lit(parser p) -> @ast.lit { lit = ast.lit_str(s); } case (_) { - lit = ast.lit_nil; - p.err("expected literal"); - fail; + lit = ast.lit_nil; // FIXME: typestate bug requires this + ret none[ast.lit]; } } - ret @spanned(lo, lo, lit); + ret some(spanned(lo, lo, lit)); } io fn parse_name(parser p, ast.ident id) -> ast.name { @@ -263,9 +262,16 @@ io fn parse_bottom_expr(parser p) -> @ast.expr { } case (_) { - auto lit = parse_lit(p); - hi = lit.span; - ex = ast.expr_lit(lit); + alt (parse_lit(p)) { + case (some[ast.lit](?lit)) { + hi = lit.span; + ex = ast.expr_lit(@lit); + } + case (none[ast.lit]) { + p.err("expecting expression"); + fail; + } + } } } ret @spanned(lo, hi, ex); |