Skip to content

Commit b90ed92

Browse files
committed
Support exclusive_range_pattern
Fix #9779
1 parent e3a67cc commit b90ed92

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

crates/parser/src/grammar/patterns.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
6565
// match 92 {
6666
// 0 ... 100 => (),
6767
// 101 ..= 200 => (),
68-
// 200 .. 301=> (),
68+
// 200 .. 301 => (),
69+
// 302 .. => (),
6970
// }
7071
// }
7172
for &range_op in [T![...], T![..=], T![..]].iter() {
7273
if p.at(range_op) {
7374
let m = lhs.precede(p);
7475
p.bump(range_op);
75-
atom_pat(p, recovery_set);
76+
if !p.at(T![=>]) {
77+
// not a range pat like `302 .. => ()`
78+
atom_pat(p, recovery_set);
79+
}
7680
m.complete(p, RANGE_PAT);
7781
return;
7882
}
@@ -84,7 +88,7 @@ const PAT_RECOVERY_SET: TokenSet =
8488
TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,], T![=]]);
8589

8690
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
87-
let m = match p.nth(0) {
91+
let m = match p.current() {
8892
T![box] => box_pat(p),
8993
T![ref] | T![mut] => ident_pat(p, true),
9094
T![const] => const_block_pat(p),

crates/syntax/test_data/parser/inline/ok/0058_range_pat.rast

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
SOURCE_FILE@0..112
2-
FN@0..111
1+
SOURCE_FILE@0..135
2+
FN@0..134
33
44
55
@@ -8,16 +8,16 @@ [email protected]
88
99
1010
11-
BLOCK_EXPR@10..111
11+
BLOCK_EXPR@10..134
1212
1313
14-
MATCH_EXPR@16..109
14+
MATCH_EXPR@16..132
1515
1616
1717
1818
1919
20-
MATCH_ARM_LIST@25..109
20+
MATCH_ARM_LIST@25..132
2121
2222
2323
@@ -58,7 +58,7 @@ [email protected]
5858
5959
6060
61-
MATCH_ARM@87..103
61+
MATCH_ARM@87..104
6262
6363
6464
@@ -69,14 +69,30 @@ [email protected]
6969
7070
7171
72-
73-
74-
75-
76-
77-
78-
79-
80-
81-
82-
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+

crates/syntax/test_data/parser/inline/ok/0058_range_pat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fn main() {
22
match 92 {
33
0 ... 100 => (),
44
101 ..= 200 => (),
5-
200 .. 301=> (),
5+
200 .. 301 => (),
6+
302 .. => (),
67
}
78
}

0 commit comments

Comments
 (0)