Namerefs in methods&fields

This commit is contained in:
Aleksey Kladov 2018-07-31 23:57:14 +03:00
parent a26390b06b
commit 5b43010083
3 changed files with 16 additions and 7 deletions

View File

@ -39,6 +39,7 @@ pub(super) fn expr(p: &mut Parser) {
} else {
field_expr(p, lhs)
},
DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs),
_ => break,
}
}
@ -202,7 +203,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(DOT) && p.nth(1) == IDENT && p.nth(2) == L_PAREN);
let m = lhs.precede(p);
p.bump();
p.bump();
name_ref(p);
arg_list(p);
m.complete(p, METHOD_CALL_EXPR)
}
@ -212,10 +213,14 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
// x.foo.bar;
// }
fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(DOT) && p.nth(1) == IDENT);
assert!(p.at(DOT) && (p.nth(1) == IDENT || p.nth(1) == INT_NUMBER));
let m = lhs.precede(p);
p.bump();
p.bump();
if p.at(IDENT) {
name_ref(p)
} else {
p.bump()
}
m.complete(p, FIELD_EXPR)
}

View File

@ -19,7 +19,8 @@ FILE@[0; 44)
WHITESPACE@[10; 15)
IDENT@[15; 16) "x"
DOT@[16; 17)
IDENT@[17; 20) "foo"
NAME_REF@[17; 20)
IDENT@[17; 20) "foo"
ARG_LIST@[20; 22)
L_PAREN@[20; 21)
R_PAREN@[21; 22)
@ -33,7 +34,8 @@ FILE@[0; 44)
NAME_REF@[28; 29)
IDENT@[28; 29) "y"
DOT@[29; 30)
IDENT@[30; 33) "bar"
NAME_REF@[30; 33)
IDENT@[30; 33) "bar"
ARG_LIST@[33; 40)
L_PAREN@[33; 34)
LITERAL@[34; 35)

View File

@ -20,9 +20,11 @@ FILE@[0; 28)
WHITESPACE@[10; 15)
IDENT@[15; 16) "x"
DOT@[16; 17)
IDENT@[17; 20) "foo"
NAME_REF@[17; 20)
IDENT@[17; 20) "foo"
DOT@[20; 21)
IDENT@[21; 24) "bar"
NAME_REF@[21; 24)
IDENT@[21; 24) "bar"
SEMI@[24; 25)
WHITESPACE@[25; 26)
R_CURLY@[26; 27)