make parser disambiguate fn~ at top level correctly

This commit is contained in:
Niko Matsakis 2012-01-12 12:31:45 -08:00
parent 263f4c58a0
commit 8818f42b19
3 changed files with 17 additions and 6 deletions

View File

@ -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") {

View File

@ -5,11 +5,11 @@ tag maybe_pointy {
type pointy = {
mutable a : maybe_pointy,
d : sendfn() -> uint,
d : fn~() -> uint,
};
fn make_uniq_closure<A:send>(a: A) -> sendfn() -> uint {
sendfn() -> uint { ptr::addr_of(a) as uint }
fn make_uniq_closure<A:send>(a: A) -> fn~() -> uint {
fn~() -> uint { ptr::addr_of(a) as uint }
}
fn empty_pointy() -> @pointy {

View File

@ -6,14 +6,14 @@ tag maybe_pointy {
type pointy = {
mutable a : maybe_pointy,
c : ~int,
d : sendfn()->(),
d : fn~()->(),
};
fn empty_pointy() -> @pointy {
ret @{
mutable a : none,
c : ~22,
d : sendfn()->(){},
d : fn~()->(){},
}
}