diff options
author | Florian Diebold <[email protected]> | 2018-12-25 13:48:54 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-25 14:16:42 +0000 |
commit | 0d724ea572a5dd26acbbf2eb4538eabe454fb894 (patch) | |
tree | 077ffa2bda1405af9a91ea9c7ad61f9cb1fc0098 /crates/ra_syntax/src/grammar | |
parent | 55c941cd9fb90c9340f01981e113aabd058b185b (diff) |
Improve parsing of incomplete field accesses in preparation for field completion
We need to be able to get the receiver even if there is no field name yet, and
currently "a." wouldn't get parsed as a field name at all. This seems to help.
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index da78d85a2..2d1f17491 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs | |||
@@ -283,14 +283,10 @@ fn postfix_expr( | |||
283 | // } | 283 | // } |
284 | L_PAREN if allow_calls => call_expr(p, lhs), | 284 | L_PAREN if allow_calls => call_expr(p, lhs), |
285 | L_BRACK if allow_calls => index_expr(p, lhs), | 285 | L_BRACK if allow_calls => index_expr(p, lhs), |
286 | DOT if p.nth(1) == IDENT => { | 286 | DOT if p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON) => { |
287 | if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { | 287 | method_call_expr(p, lhs) |
288 | method_call_expr(p, lhs) | ||
289 | } else { | ||
290 | field_expr(p, lhs) | ||
291 | } | ||
292 | } | 288 | } |
293 | DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs), | 289 | DOT => field_expr(p, lhs), |
294 | // test postfix_range | 290 | // test postfix_range |
295 | // fn foo() { let x = 1..; } | 291 | // fn foo() { let x = 1..; } |
296 | DOTDOT | DOTDOTEQ if !EXPR_FIRST.contains(p.nth(1)) => { | 292 | DOTDOT | DOTDOTEQ if !EXPR_FIRST.contains(p.nth(1)) => { |
@@ -355,13 +351,15 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | |||
355 | // x.0.bar; | 351 | // x.0.bar; |
356 | // } | 352 | // } |
357 | fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | 353 | fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { |
358 | assert!(p.at(DOT) && (p.nth(1) == IDENT || p.nth(1) == INT_NUMBER)); | 354 | assert!(p.at(DOT)); |
359 | let m = lhs.precede(p); | 355 | let m = lhs.precede(p); |
360 | p.bump(); | 356 | p.bump(); |
361 | if p.at(IDENT) { | 357 | if p.at(IDENT) { |
362 | name_ref(p) | 358 | name_ref(p) |
363 | } else { | 359 | } else if p.at(INT_NUMBER) { |
364 | p.bump() | 360 | p.bump() |
361 | } else { | ||
362 | p.error("expected field name or number") | ||
365 | } | 363 | } |
366 | m.complete(p, FIELD_EXPR) | 364 | m.complete(p, FIELD_EXPR) |
367 | } | 365 | } |