Skip to content

Commit 4f220fb

Browse files
committed
tmp
1 parent 78963c9 commit 4f220fb

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

crates/ra_parser/src/grammar/patterns.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ const PAT_RECOVERY_SET: TokenSet =
5858
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
5959
let la0 = p.nth(0);
6060
let la1 = p.nth(1);
61-
if la0 == IDENT && la1 == T![..] {
62-
let m = p.start();
63-
p.bump();
64-
p.bump();
65-
return Some(m.complete(p, SUBSLICE_PAT));
66-
}
6761
if la0 == T![ref]
6862
|| la0 == T![mut]
6963
|| la0 == T![box]
@@ -151,7 +145,21 @@ fn path_pat(p: &mut Parser) -> CompletedMarker {
151145
fn tuple_pat_fields(p: &mut Parser) {
152146
assert!(p.at(T!['(']));
153147
p.bump();
154-
pat_list(p, T![')']);
148+
while !p.at(EOF) && !p.at(T![')']) {
149+
match p.current() {
150+
T![..] => p.bump(),
151+
_ => {
152+
if !p.at_ts(PATTERN_FIRST) {
153+
p.error("expected a pattern");
154+
break;
155+
}
156+
pattern(p)
157+
}
158+
}
159+
if !p.at(T![')']) {
160+
p.expect(T![,]);
161+
}
162+
}
155163
p.expect(T![')']);
156164
}
157165

@@ -237,15 +245,15 @@ fn slice_pat(p: &mut Parser) -> CompletedMarker {
237245
assert!(p.at(T!['[']));
238246
let m = p.start();
239247
p.bump();
240-
pat_list(p, T![']']);
241-
p.expect(T![']']);
242-
m.complete(p, SLICE_PAT)
243-
}
244-
245-
fn pat_list(p: &mut Parser, ket: SyntaxKind) {
246-
while !p.at(EOF) && !p.at(ket) {
248+
while !p.at(EOF) && !p.at(T![']']) {
247249
match p.current() {
248250
T![..] => p.bump(),
251+
IDENT if p.nth(1) == T![..] => {
252+
let m_sub = p.start();
253+
p.bump();
254+
p.bump();
255+
m_sub.complete(p, SUBSLICE_PAT);
256+
}
249257
_ => {
250258
if !p.at_ts(PATTERN_FIRST) {
251259
p.error("expected a pattern");
@@ -254,10 +262,12 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) {
254262
pattern(p)
255263
}
256264
}
257-
if !p.at(ket) {
265+
if !p.at(T![']']) {
258266
p.expect(T![,]);
259267
}
260268
}
269+
p.expect(T![']']);
270+
m.complete(p, SLICE_PAT)
261271
}
262272

263273
// test bind_pat

crates/ra_syntax/tests/data/parser/inline/ok/0024_slice_pat.txt

-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ SOURCE_FILE@[0; 62)
6060
WHITESPACE@[59; 60) "\n"
6161
R_CURLY@[60; 61) "}"
6262
WHITESPACE@[61; 62) "\n"
63-

0 commit comments

Comments
 (0)