diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-01-12 12:31:45 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-01-12 13:47:38 -0800 |
| commit | 8818f42b19efbf8832c856058519644a8657b04c (patch) | |
| tree | 332008d75ca0b1c59c440024958619ff5e35ed11 /src/comp/syntax/parse | |
| parent | 263f4c58a0c9409f257d45ae03d4b19700ef232b (diff) | |
| download | rust-8818f42b19efbf8832c856058519644a8657b04c.tar.gz rust-8818f42b19efbf8832c856058519644a8657b04c.zip | |
make parser disambiguate fn~ at top level correctly
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 13396d68227..4e5620efed6 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -2166,13 +2166,24 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto { } } +fn fn_expr_lookahead(tok: token::token) -> bool { + alt tok { + token::LPAREN. | token::AT. | token::TILDE. | token::BINOP(_) { + true + } + _ { + false + } + } +} + fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> { if eat_word(p, "const") { ret some(parse_item_const(p, attrs)); } else if eat_word(p, "inline") { expect_word(p, "fn"); ret some(parse_item_fn(p, ast::impure_fn, attrs)); - } else if is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN { + } else if is_word(p, "fn") && !fn_expr_lookahead(p.look_ahead(1u)) { p.bump(); ret some(parse_item_fn(p, ast::impure_fn, attrs)); } else if eat_word(p, "pure") { |
