Move numeric names inside of NameRef

This commit is contained in:
Aleksey Kladov 2019-08-09 12:16:47 +02:00
parent 5f82012779
commit f3ee5a1509
10 changed files with 52 additions and 37 deletions

View file

@ -273,8 +273,8 @@ fn name(p: &mut Parser) {
name_r(p, TokenSet::empty())
}
fn name_ref(p: &mut Parser, allow_numeric_names: bool) {
if p.at(IDENT) || (allow_numeric_names && p.at(INT_NUMBER)) {
fn name_ref(p: &mut Parser) {
if p.at(IDENT) {
let m = p.start();
p.bump();
m.complete(p, NAME_REF);
@ -287,6 +287,16 @@ fn name_ref(p: &mut Parser, allow_numeric_names: bool) {
}
}
fn name_ref_or_index(p: &mut Parser) {
if p.at(IDENT) || p.at(INT_NUMBER) {
let m = p.start();
p.bump();
m.complete(p, NAME_REF);
} else {
p.err_and_bump("expected identifier");
}
}
fn error_block(p: &mut Parser, message: &str) {
assert!(p.at(T!['{']));
let m = p.start();

View file

@ -458,7 +458,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::]));
let m = lhs.precede(p);
p.bump();
name_ref(p, false);
name_ref(p);
type_args::opt_type_arg_list(p, true);
if p.at(T!['(']) {
arg_list(p);
@ -484,10 +484,8 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![.]));
let m = lhs.precede(p);
p.bump();
if p.at(IDENT) {
name_ref(p, false)
} else if p.at(INT_NUMBER) {
p.bump();
if p.at(IDENT) || p.at(INT_NUMBER) {
name_ref_or_index(p)
} else if p.at(FLOAT_NUMBER) {
// FIXME: How to recover and instead parse INT + T![.]?
p.bump();
@ -587,7 +585,7 @@ pub(crate) fn named_field_list(p: &mut Parser) {
IDENT | INT_NUMBER | T![#] => {
let m = p.start();
attributes::outer_attributes(p);
name_ref(p, true);
name_ref_or_index(p);
if p.eat(T![:]) {
expr(p);
}

View file

@ -279,7 +279,7 @@ fn extern_crate_item(p: &mut Parser, m: Marker) {
p.bump();
assert!(p.at(T![crate]));
p.bump();
name_ref(p, false);
name_ref(p);
opt_alias(p);
p.expect(T![;]);
m.complete(p, EXTERN_CRATE_ITEM);

View file

@ -71,7 +71,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
}
match p.current() {
IDENT => {
name_ref(p, false);
name_ref(p);
opt_path_type_args(p, mode);
}
// test crate_path

View file

@ -38,12 +38,12 @@ fn type_arg(p: &mut Parser) {
// test associated_type_bounds
// fn print_all<T: Iterator<Item: Display>>(printables: T) {}
IDENT if p.nth(1) == T![:] => {
name_ref(p, false);
name_ref(p);
type_params::bounds(p);
m.complete(p, ASSOC_TYPE_ARG);
}
IDENT if p.nth(1) == T![=] => {
name_ref(p, false);
name_ref(p);
p.bump();
types::type_(p);
m.complete(p, ASSOC_TYPE_ARG);