From 070c39ca1d4792a96f08d19c22378d5b5b019f02 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 14 Oct 2011 14:57:21 -0700 Subject: [PATCH] Split parsing of fn proto between types, items and anons The meaning of various fn incantations is going to get temporarily confusing --- src/comp/syntax/parse/parser.rs | 36 +++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 3b53dbc89fc..01770aa8a60 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -569,7 +569,7 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { hi = p.get_hi_pos(); expect(p, token::RBRACKET); } else if eat_word(p, "fn") { - let proto = parse_fn_proto(p); + let proto = parse_fn_ty_proto(p); t = parse_ty_fn(proto, p); alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } } } else if eat_word(p, "block") { @@ -846,7 +846,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr { ret parse_spawn_expr(p); */ } else if eat_word(p, "fn") { - let proto = parse_fn_proto(p); + let proto = parse_fn_anon_proto(p); ret parse_fn_expr(p, proto); } else if eat_word(p, "block") { ret parse_fn_expr(p, ast::proto_block); @@ -2143,7 +2143,31 @@ fn parse_auth(p: parser) -> ast::_auth { } else { unexpected(p, p.peek()); } } -fn parse_fn_proto(p: parser) -> ast::proto { +fn parse_fn_item_proto(p: parser) -> ast::proto { + if p.peek() == token::POUND { + p.bump(); + ast::proto_bare + } else if p.peek() == token::AT { + p.bump(); + ast::proto_fn + } else { + ast::proto_fn + } +} + +fn parse_fn_ty_proto(p: parser) -> ast::proto { + if p.peek() == token::POUND { + p.bump(); + ast::proto_bare + } else if p.peek() == token::AT { + p.bump(); + ast::proto_fn + } else { + ast::proto_fn + } +} + +fn parse_fn_anon_proto(p: parser) -> ast::proto { if p.peek() == token::POUND { p.bump(); ast::proto_bare @@ -2160,17 +2184,17 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> { ret some(parse_item_const(p, attrs)); } else if eat_word(p, "inline") { expect_word(p, "fn"); - let proto = parse_fn_proto(p); + let proto = parse_fn_item_proto(p); ret some(parse_item_fn_or_iter(p, ast::impure_fn, proto, attrs, ast::il_inline)); } else if is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN { p.bump(); - let proto = parse_fn_proto(p); + let proto = parse_fn_item_proto(p); ret some(parse_item_fn_or_iter(p, ast::impure_fn, proto, attrs, ast::il_normal)); } else if eat_word(p, "pure") { expect_word(p, "fn"); - let proto = parse_fn_proto(p); + let proto = parse_fn_item_proto(p); ret some(parse_item_fn_or_iter(p, ast::pure_fn, proto, attrs, ast::il_normal)); } else if is_word(p, "unsafe") && p.look_ahead(1u) != token::LBRACE { -- GitLab