Allow non-semicolon-requiring expressions to be followed by .field

There is no valid expression that starts with a dot token (.5 is a number token),
so this introduces no ambiguities.

Issue #1716
This commit is contained in:
Marijn Haverbeke 2012-01-31 13:31:02 +01:00
parent da61e1ff15
commit 5c42e3df9c

View File

@ -1039,7 +1039,28 @@ fn parse_dot_or_call_expr_with(p: parser, e0: pexpr) -> pexpr {
let e = e0;
let lo = e.span.lo;
let hi = e.span.hi;
while !expr_is_complete(p, e) {
while true {
// expr.f
if eat(p, token::DOT) {
alt p.token {
token::IDENT(i, _) {
hi = p.span.hi;
p.bump();
let tys = if eat(p, token::MOD_SEP) {
expect(p, token::LT);
parse_seq_to_gt(some(token::COMMA),
{|p| parse_ty(p, false)}, p)
} else { [] };
e = mk_pexpr(p, lo, hi,
ast::expr_field(to_expr(e),
p.get_str(i),
tys));
}
t { unexpected(p, t); }
}
cont;
}
if expr_is_complete(p, e) { break; }
alt p.token {
// expr(...)
token::LPAREN if permits_call(p) {
@ -1076,27 +1097,6 @@ fn parse_dot_or_call_expr_with(p: parser, e0: pexpr) -> pexpr {
e = mk_pexpr(p, lo, hi, ast::expr_index(to_expr(e), ix));
}
// expr.f
token::DOT {
p.bump();
alt p.token {
token::IDENT(i, _) {
hi = p.span.hi;
p.bump();
let tys = if eat(p, token::MOD_SEP) {
expect(p, token::LT);
parse_seq_to_gt(some(token::COMMA),
{|p| parse_ty(p, false)}, p)
} else { [] };
e = mk_pexpr(p, lo, hi,
ast::expr_field(to_expr(e),
p.get_str(i),
tys));
}
t { unexpected(p, t); }
}
}
_ { ret e; }
}
}