File tree 4 files changed +157
-35
lines changed
test_data/parser/inline/ok
4 files changed +157
-35
lines changed Original file line number Diff line number Diff line change @@ -62,39 +62,50 @@ fn pattern_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
62
62
}
63
63
64
64
fn pattern_single_r ( p : & mut Parser < ' _ > , recovery_set : TokenSet ) {
65
- if let Some ( lhs) = atom_pat ( p, recovery_set) {
66
- // test range_pat
67
- // fn main() {
68
- // match 92 {
69
- // 0 ... 100 => (),
70
- // 101 ..= 200 => (),
71
- // 200 .. 301 => (),
72
- // 302 .. => (),
73
- // }
74
- //
75
- // match Some(10 as u8) {
76
- // Some(0) | None => (),
77
- // Some(1..) => ()
78
- // }
79
- //
80
- // match () {
81
- // S { a: 0 } => (),
82
- // S { a: 1.. } => (),
83
- // }
84
- //
85
- // match () {
86
- // [0] => (),
87
- // [1..] => (),
88
- // }
89
- //
90
- // match (10 as u8, 5 as u8) {
91
- // (0, _) => (),
92
- // (1.., _) => ()
93
- // }
94
- // }
65
+ // test range_pat
66
+ // fn main() {
67
+ // match 92 {
68
+ // 0 ... 100 => (),
69
+ // 101 ..= 200 => (),
70
+ // 200 .. 301 => (),
71
+ // 302 .. => (),
72
+ // ..= 303 => (),
73
+ // }
74
+ //
75
+ // match Some(10 as u8) {
76
+ // Some(0) | None => (),
77
+ // Some(1..) => (),
78
+ // Some(..=2) => (),
79
+ // }
80
+ //
81
+ // match () {
82
+ // S { a: 0 } => (),
83
+ // S { a: 1.. } => (),
84
+ // S { a: ..=2 } => (),
85
+ // }
86
+ //
87
+ // match () {
88
+ // [0] => (),
89
+ // [1..] => (),
90
+ // [..=2] => (),
91
+ // }
92
+ //
93
+ // match (10 as u8, 5 as u8) {
94
+ // (0, _) => (),
95
+ // (1.., _) => (),
96
+ // (..=2, _) => (),
97
+ // }
98
+ // }
99
+
100
+ if p. at ( T ! [ ..=] ) {
101
+ let m = p. start ( ) ;
102
+ p. bump ( T ! [ ..=] ) ;
103
+ atom_pat ( p, recovery_set) ;
104
+ m. complete ( p, RANGE_PAT ) ;
105
+ return ;
106
+ }
95
107
96
- // FIXME: support half_open_range_patterns (`..=2`),
97
- // exclusive_range_pattern (`..5`) with missing lhs
108
+ if let Some ( lhs) = atom_pat ( p, recovery_set) {
98
109
for range_op in [ T ! [ ...] , T ! [ ..=] , T ! [ ..] ] {
99
110
if p. at ( range_op) {
100
111
let m = lhs. precede ( p) ;
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ impl<'t> Parser<'t> {
162
162
Marker :: new ( pos)
163
163
}
164
164
165
- /// Consume the next token if `kind` matches .
165
+ /// Consume the next token. Panics if the parser isn't currently at `kind`.
166
166
pub ( crate ) fn bump ( & mut self , kind : SyntaxKind ) {
167
167
assert ! ( self . eat( kind) ) ;
168
168
}
Original file line number Diff line number Diff line change @@ -93,6 +93,21 @@ SOURCE_FILE
93
93
L_PAREN "("
94
94
R_PAREN ")"
95
95
COMMA ","
96
+ WHITESPACE "\n "
97
+ MATCH_ARM
98
+ RANGE_PAT
99
+ DOT2EQ "..="
100
+ WHITESPACE " "
101
+ LITERAL_PAT
102
+ LITERAL
103
+ INT_NUMBER "303"
104
+ WHITESPACE " "
105
+ FAT_ARROW "=>"
106
+ WHITESPACE " "
107
+ TUPLE_EXPR
108
+ L_PAREN "("
109
+ R_PAREN ")"
110
+ COMMA ","
96
111
WHITESPACE "\n "
97
112
R_CURLY "}"
98
113
WHITESPACE "\n\n "
@@ -169,6 +184,28 @@ SOURCE_FILE
169
184
TUPLE_EXPR
170
185
L_PAREN "("
171
186
R_PAREN ")"
187
+ COMMA ","
188
+ WHITESPACE "\n "
189
+ MATCH_ARM
190
+ TUPLE_STRUCT_PAT
191
+ PATH
192
+ PATH_SEGMENT
193
+ NAME_REF
194
+ IDENT "Some"
195
+ L_PAREN "("
196
+ RANGE_PAT
197
+ DOT2EQ "..="
198
+ LITERAL_PAT
199
+ LITERAL
200
+ INT_NUMBER "2"
201
+ R_PAREN ")"
202
+ WHITESPACE " "
203
+ FAT_ARROW "=>"
204
+ WHITESPACE " "
205
+ TUPLE_EXPR
206
+ L_PAREN "("
207
+ R_PAREN ")"
208
+ COMMA ","
172
209
WHITESPACE "\n "
173
210
R_CURLY "}"
174
211
WHITESPACE "\n\n "
@@ -240,6 +277,36 @@ SOURCE_FILE
240
277
L_PAREN "("
241
278
R_PAREN ")"
242
279
COMMA ","
280
+ WHITESPACE "\n "
281
+ MATCH_ARM
282
+ RECORD_PAT
283
+ PATH
284
+ PATH_SEGMENT
285
+ NAME_REF
286
+ IDENT "S"
287
+ WHITESPACE " "
288
+ RECORD_PAT_FIELD_LIST
289
+ L_CURLY "{"
290
+ WHITESPACE " "
291
+ RECORD_PAT_FIELD
292
+ NAME_REF
293
+ IDENT "a"
294
+ COLON ":"
295
+ WHITESPACE " "
296
+ RANGE_PAT
297
+ DOT2EQ "..="
298
+ LITERAL_PAT
299
+ LITERAL
300
+ INT_NUMBER "2"
301
+ WHITESPACE " "
302
+ R_CURLY "}"
303
+ WHITESPACE " "
304
+ FAT_ARROW "=>"
305
+ WHITESPACE " "
306
+ TUPLE_EXPR
307
+ L_PAREN "("
308
+ R_PAREN ")"
309
+ COMMA ","
243
310
WHITESPACE "\n "
244
311
R_CURLY "}"
245
312
WHITESPACE "\n\n "
@@ -285,6 +352,23 @@ SOURCE_FILE
285
352
L_PAREN "("
286
353
R_PAREN ")"
287
354
COMMA ","
355
+ WHITESPACE "\n "
356
+ MATCH_ARM
357
+ SLICE_PAT
358
+ L_BRACK "["
359
+ RANGE_PAT
360
+ DOT2EQ "..="
361
+ LITERAL_PAT
362
+ LITERAL
363
+ INT_NUMBER "2"
364
+ R_BRACK "]"
365
+ WHITESPACE " "
366
+ FAT_ARROW "=>"
367
+ WHITESPACE " "
368
+ TUPLE_EXPR
369
+ L_PAREN "("
370
+ R_PAREN ")"
371
+ COMMA ","
288
372
WHITESPACE "\n "
289
373
R_CURLY "}"
290
374
WHITESPACE "\n\n "
@@ -360,6 +444,28 @@ SOURCE_FILE
360
444
TUPLE_EXPR
361
445
L_PAREN "("
362
446
R_PAREN ")"
447
+ COMMA ","
448
+ WHITESPACE "\n "
449
+ MATCH_ARM
450
+ TUPLE_PAT
451
+ L_PAREN "("
452
+ RANGE_PAT
453
+ DOT2EQ "..="
454
+ LITERAL_PAT
455
+ LITERAL
456
+ INT_NUMBER "2"
457
+ COMMA ","
458
+ WHITESPACE " "
459
+ WILDCARD_PAT
460
+ UNDERSCORE "_"
461
+ R_PAREN ")"
462
+ WHITESPACE " "
463
+ FAT_ARROW "=>"
464
+ WHITESPACE " "
465
+ TUPLE_EXPR
466
+ L_PAREN "("
467
+ R_PAREN ")"
468
+ COMMA ","
363
469
WHITESPACE "\n "
364
470
R_CURLY "}"
365
471
WHITESPACE "\n"
Original file line number Diff line number Diff line change @@ -4,25 +4,30 @@ fn main() {
4
4
101 ..= 200 => ( ) ,
5
5
200 .. 301 => ( ) ,
6
6
302 .. => ( ) ,
7
+ ..= 303 => ( ) ,
7
8
}
8
9
9
10
match Some ( 10 as u8 ) {
10
11
Some ( 0 ) | None => ( ) ,
11
- Some ( 1 ..) => ( )
12
+ Some ( 1 ..) => ( ) ,
13
+ Some ( ..=2 ) => ( ) ,
12
14
}
13
15
14
16
match ( ) {
15
17
S { a : 0 } => ( ) ,
16
18
S { a : 1 .. } => ( ) ,
19
+ S { a : ..=2 } => ( ) ,
17
20
}
18
21
19
22
match ( ) {
20
23
[ 0 ] => ( ) ,
21
24
[ 1 ..] => ( ) ,
25
+ [ ..=2 ] => ( ) ,
22
26
}
23
27
24
28
match ( 10 as u8 , 5 as u8 ) {
25
29
( 0 , _) => ( ) ,
26
- ( 1 .., _) => ( )
30
+ ( 1 .., _) => ( ) ,
31
+ ( ..=2 , _) => ( ) ,
27
32
}
28
33
}
You can’t perform that action at this time.
0 commit comments