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') 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