aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar.rs11
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs37
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs50
3 files changed, 52 insertions, 46 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index d0530955e..c2a6e82e9 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -282,13 +282,10 @@ fn name_ref(p: &mut Parser) {
282} 282}
283 283
284fn name_ref_or_index(p: &mut Parser) { 284fn name_ref_or_index(p: &mut Parser) {
285 if p.at(IDENT) || p.at(INT_NUMBER) { 285 assert!(p.at(IDENT) || p.at(INT_NUMBER));
286 let m = p.start(); 286 let m = p.start();
287 p.bump_any(); 287 p.bump_any();
288 m.complete(p, NAME_REF); 288 m.complete(p, NAME_REF);
289 } else {
290 p.err_and_bump("expected identifier");
291 }
292} 289}
293 290
294fn error_block(p: &mut Parser, message: &str) { 291fn error_block(p: &mut Parser, message: &str) {
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) {
619 let m = p.start(); 619 let m = p.start();
620 p.bump(T!['{']); 620 p.bump(T!['{']);
621 while !p.at(EOF) && !p.at(T!['}']) { 621 while !p.at(EOF) && !p.at(T!['}']) {
622 let m = p.start();
623 // test record_literal_field_with_attr
624 // fn main() {
625 // S { #[cfg(test)] field: 1 }
626 // }
627 attributes::outer_attributes(p);
628
622 match p.current() { 629 match p.current() {
623 // test record_literal_field_with_attr 630 IDENT | INT_NUMBER => {
624 // fn main() { 631 // test_err record_literal_before_ellipsis_recovery
625 // S { #[cfg(test)] field: 1 } 632 // fn main() {
626 // } 633 // S { field ..S::default() }
627 IDENT | INT_NUMBER | T![#] => { 634 // }
628 let m = p.start(); 635 if p.nth_at(1, T![:]) || p.nth_at(1, T![..]) {
629 attributes::outer_attributes(p); 636 name_ref_or_index(p);
630 name_ref_or_index(p); 637 p.expect(T![:]);
631 if p.eat(T![:]) {
632 expr(p);
633 } 638 }
639 expr(p);
634 m.complete(p, RECORD_FIELD); 640 m.complete(p, RECORD_FIELD);
635 } 641 }
636 T![.] if p.at(T![..]) => { 642 T![.] if p.at(T![..]) => {
643 m.abandon(p);
637 p.bump(T![..]); 644 p.bump(T![..]);
638 expr(p); 645 expr(p);
639 } 646 }
640 T!['{'] => error_block(p, "expected a field"), 647 T!['{'] => {
641 _ => p.err_and_bump("expected identifier"), 648 error_block(p, "expected a field");
649 m.abandon(p);
650 }
651 _ => {
652 p.err_and_bump("expected identifier");
653 m.abandon(p);
654 }
642 } 655 }
643 if !p.at(T!['}']) { 656 if !p.at(T!['}']) {
644 p.expect(T![,]); 657 p.expect(T![,]);
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs
index 936d27575..68fb2fc73 100644
--- a/crates/ra_parser/src/grammar/patterns.rs
+++ b/crates/ra_parser/src/grammar/patterns.rs
@@ -192,14 +192,30 @@ fn record_field_pat_list(p: &mut Parser) {
192 match p.current() { 192 match p.current() {
193 // A trailing `..` is *not* treated as a DOT_DOT_PAT. 193 // A trailing `..` is *not* treated as a DOT_DOT_PAT.
194 T![.] if p.at(T![..]) => p.bump(T![..]), 194 T![.] if p.at(T![..]) => p.bump(T![..]),
195
196 IDENT | INT_NUMBER if p.nth(1) == T![:] => record_field_pat(p),
197 T!['{'] => error_block(p, "expected ident"), 195 T!['{'] => error_block(p, "expected ident"),
198 T![box] => { 196
199 box_pat(p); 197 c => {
200 } 198 let m = p.start();
201 _ => { 199 match c {
202 bind_pat(p, false); 200 // test record_field_pat
201 // fn foo() {
202 // let S { 0: 1 } = ();
203 // let S { x: 1 } = ();
204 // }
205 IDENT | INT_NUMBER if p.nth(1) == T![:] => {
206 name_ref_or_index(p);
207 p.bump(T![:]);
208 pattern(p);
209 }
210 T![box] => {
211 // FIXME: not all box patterns should be allowed
212 box_pat(p);
213 }
214 _ => {
215 bind_pat(p, false);
216 }
217 }
218 m.complete(p, RECORD_FIELD_PAT);
203 } 219 }
204 } 220 }
205 if !p.at(T!['}']) { 221 if !p.at(T!['}']) {
@@ -210,26 +226,6 @@ fn record_field_pat_list(p: &mut Parser) {
210 m.complete(p, RECORD_FIELD_PAT_LIST); 226 m.complete(p, RECORD_FIELD_PAT_LIST);
211} 227}
212 228
213// test record_field_pat
214// fn foo() {
215// let S { 0: 1 } = ();
216// let S { x: 1 } = ();
217// }
218fn record_field_pat(p: &mut Parser) {
219 assert!(p.at(IDENT) || p.at(INT_NUMBER));
220 assert!(p.nth(1) == T![:]);
221
222 let m = p.start();
223
224 if !p.eat(INT_NUMBER) {
225 name(p)
226 }
227
228 p.bump_any();
229 pattern(p);
230 m.complete(p, RECORD_FIELD_PAT);
231}
232
233// test placeholder_pat 229// test placeholder_pat
234// fn main() { let _ = (); } 230// fn main() { let _ = (); }
235fn placeholder_pat(p: &mut Parser) -> CompletedMarker { 231fn placeholder_pat(p: &mut Parser) -> CompletedMarker {