mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Make records grammar more orthogonal
We used name [: expr] grammar before, now it is [name :] expr which makes things simpler
This commit is contained in:
parent
e7a68c8f55
commit
7a39bc3ba2
13 changed files with 142 additions and 68 deletions
|
@ -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![,]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue