From 957b5ed23a4860fe3c9b80687a801b5d7870fe00 Mon Sep 17 00:00:00 2001 From: Evgenii P Date: Fri, 9 Aug 2019 15:38:52 +0700 Subject: Parse tuple struct field initialization --- crates/ra_parser/src/grammar.rs | 2 +- crates/ra_parser/src/grammar/expressions.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 658034097..00fb1bac9 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -274,7 +274,7 @@ fn name(p: &mut Parser) { } fn name_ref(p: &mut Parser) { - if p.at(IDENT) { + if p.at(IDENT) || p.at(INT_NUMBER) { let m = p.start(); p.bump(); m.complete(p, NAME_REF); diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 3e49e70c7..50c938a23 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -572,6 +572,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { // S {}; // S { x, y: 32, }; // S { x, y: 32, ..Default::default() }; +// TupleStruct { 0: 1 }; // } pub(crate) fn named_field_list(p: &mut Parser) { assert!(p.at(T!['{'])); @@ -583,7 +584,7 @@ pub(crate) fn named_field_list(p: &mut Parser) { // fn main() { // S { #[cfg(test)] field: 1 } // } - IDENT | T![#] => { + IDENT | INT_NUMBER | T![#] => { let m = p.start(); attributes::outer_attributes(p); name_ref(p); -- cgit v1.2.3 From fa24e20867893178ed7265ecadb2bcb09cf76dac Mon Sep 17 00:00:00 2001 From: Evgenii P Date: Fri, 9 Aug 2019 16:08:36 +0700 Subject: Make name_ref to accept numeric names optionally --- crates/ra_parser/src/grammar.rs | 4 ++-- crates/ra_parser/src/grammar/expressions.rs | 6 +++--- crates/ra_parser/src/grammar/items.rs | 2 +- crates/ra_parser/src/grammar/paths.rs | 2 +- crates/ra_parser/src/grammar/type_args.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 00fb1bac9..2ee121ccd 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -273,8 +273,8 @@ fn name(p: &mut Parser) { name_r(p, TokenSet::empty()) } -fn name_ref(p: &mut Parser) { - if p.at(IDENT) || p.at(INT_NUMBER) { +fn name_ref(p: &mut Parser, allow_numeric_names: bool) { + if p.at(IDENT) || (allow_numeric_names && p.at(INT_NUMBER)) { let m = p.start(); p.bump(); m.complete(p, NAME_REF); diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 50c938a23..9f9e9cb0e 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -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); + name_ref(p, false); type_args::opt_type_arg_list(p, true); if p.at(T!['(']) { arg_list(p); @@ -485,7 +485,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { let m = lhs.precede(p); p.bump(); if p.at(IDENT) { - name_ref(p) + name_ref(p, false) } else if p.at(INT_NUMBER) { p.bump(); } else if p.at(FLOAT_NUMBER) { @@ -587,7 +587,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); + name_ref(p, true); if p.eat(T![:]) { expr(p); } diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 543af7c4b..b0081f396 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -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); + name_ref(p, false); opt_alias(p); p.expect(T![;]); m.complete(p, EXTERN_CRATE_ITEM); diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index 3537b0da1..2c8f0f7e8 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs @@ -71,7 +71,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { } match p.current() { IDENT => { - name_ref(p); + name_ref(p, false); opt_path_type_args(p, mode); } // test crate_path diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs index 3db08b280..f1d999dea 100644 --- a/crates/ra_parser/src/grammar/type_args.rs +++ b/crates/ra_parser/src/grammar/type_args.rs @@ -38,12 +38,12 @@ fn type_arg(p: &mut Parser) { // test associated_type_bounds // fn print_all>(printables: T) {} IDENT if p.nth(1) == T![:] => { - name_ref(p); + name_ref(p, false); type_params::bounds(p); m.complete(p, ASSOC_TYPE_ARG); } IDENT if p.nth(1) == T![=] => { - name_ref(p); + name_ref(p, false); p.bump(); types::type_(p); m.complete(p, ASSOC_TYPE_ARG); -- cgit v1.2.3