diff options
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar/patterns.rs | 50 |
1 files changed, 23 insertions, 27 deletions
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 { |