From 5c5bde47fb759440d007c90fd83021de538120b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 17:06:57 +0200 Subject: Rename some tokens --- crates/ra_parser/src/grammar/expressions.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser/src/grammar/expressions.rs') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index c486c0211..a1bd53063 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -339,7 +339,8 @@ fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option Option<(CompletedMarker, BlockLike)> { let m; -- cgit v1.2.3 From 7a39bc3ba29351feabcd4a16e12568a9e12818ca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 16:42:24 +0200 Subject: Make records grammar more orthogonal We used name [: expr] grammar before, now it is [name :] expr which makes things simpler --- crates/ra_parser/src/grammar/expressions.rs | 37 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'crates/ra_parser/src/grammar/expressions.rs') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index a1bd53063..cb30b25a8 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -619,26 +619,39 @@ pub(crate) fn record_field_list(p: &mut Parser) { let m = p.start(); p.bump(T!['{']); while !p.at(EOF) && !p.at(T!['}']) { + let m = p.start(); + // test record_literal_field_with_attr + // fn main() { + // S { #[cfg(test)] field: 1 } + // } + attributes::outer_attributes(p); + match p.current() { - // test record_literal_field_with_attr - // fn main() { - // S { #[cfg(test)] field: 1 } - // } - IDENT | INT_NUMBER | T![#] => { - let m = p.start(); - attributes::outer_attributes(p); - name_ref_or_index(p); - if p.eat(T![:]) { - expr(p); + IDENT | INT_NUMBER => { + // test_err record_literal_before_ellipsis_recovery + // fn main() { + // S { field ..S::default() } + // } + if p.nth_at(1, T![:]) || p.nth_at(1, T![..]) { + name_ref_or_index(p); + p.expect(T![:]); } + expr(p); m.complete(p, RECORD_FIELD); } T![.] if p.at(T![..]) => { + m.abandon(p); p.bump(T![..]); expr(p); } - T!['{'] => error_block(p, "expected a field"), - _ => p.err_and_bump("expected identifier"), + T!['{'] => { + error_block(p, "expected a field"); + m.abandon(p); + } + _ => { + p.err_and_bump("expected identifier"); + m.abandon(p); + } } if !p.at(T!['}']) { p.expect(T![,]); -- cgit v1.2.3