diff options
author | Benjamin Coenen <[email protected]> | 2020-04-14 18:20:30 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-04-14 18:20:30 +0100 |
commit | b092bbc83d13af6a79f8f282632ec1ea0a1560bd (patch) | |
tree | 2638559990ee6a93cd3b6d6d957b67063eb75c2d /crates/ra_parser | |
parent | 064095742980d4c825391f643e437520599f51d8 (diff) | |
parent | c82e7696e6f86cc0843c5aab9f09b5d6dd0d4bac (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_parser')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 11 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/patterns.rs | 50 |
2 files changed, 27 insertions, 34 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 | ||
284 | fn name_ref_or_index(p: &mut Parser) { | 284 | fn 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 | ||
294 | fn error_block(p: &mut Parser, message: &str) { | 291 | fn error_block(p: &mut Parser, message: &str) { |
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 | // } | ||
218 | fn 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 _ = (); } |
235 | fn placeholder_pat(p: &mut Parser) -> CompletedMarker { | 231 | fn placeholder_pat(p: &mut Parser) -> CompletedMarker { |