Skip to content

Commit 9d9f1a1

Browse files
committed
WIP: issue 1479 subslice patterns
1 parent fee552d commit 9d9f1a1

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

crates/ra_parser/src/grammar/patterns.rs

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ 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+
}
6167
if la0 == T![ref]
6268
|| la0 == T![mut]
6369
|| la0 == T![box]
@@ -225,6 +231,7 @@ fn tuple_pat(p: &mut Parser) -> CompletedMarker {
225231
// test slice_pat
226232
// fn main() {
227233
// let [a, b, ..] = [];
234+
// let [a, b..] = [];
228235
// }
229236
fn slice_pat(p: &mut Parser) -> CompletedMarker {
230237
assert!(p.at(T!['[']));

crates/ra_parser/src/syntax_kind/generated.rs

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub enum SyntaxKind {
165165
SLICE_PAT,
166166
RANGE_PAT,
167167
LITERAL_PAT,
168+
SUBSLICE_PAT,
168169
TUPLE_EXPR,
169170
ARRAY_EXPR,
170171
PAREN_EXPR,
@@ -632,6 +633,7 @@ impl SyntaxKind {
632633
SLICE_PAT => &SyntaxInfo { name: "SLICE_PAT" },
633634
RANGE_PAT => &SyntaxInfo { name: "RANGE_PAT" },
634635
LITERAL_PAT => &SyntaxInfo { name: "LITERAL_PAT" },
636+
SUBSLICE_PAT => &SyntaxInfo { name: "SUBSLICE_PAT" },
635637
TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" },
636638
ARRAY_EXPR => &SyntaxInfo { name: "ARRAY_EXPR" },
637639
PAREN_EXPR => &SyntaxInfo { name: "PAREN_EXPR" },

crates/ra_syntax/src/grammar.ron

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Grammar(
168168
"SLICE_PAT",
169169
"RANGE_PAT",
170170
"LITERAL_PAT",
171+
"SUBSLICE_PAT",
171172

172173
// atoms
173174
"TUPLE_EXPR",
@@ -686,7 +687,7 @@ Grammar(
686687
"LifetimeArg": (),
687688

688689
"MacroItems": (
689-
traits: [ "ModuleItemOwner", "FnDefOwner" ],
690+
traits: [ "ModuleItemOwner", "FnDefOwner" ],
690691
),
691692

692693
"MacroStmts" : (
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fn main() {
22
let [a, b, ..] = [];
3+
let [a, b..] = [];
34
}

0 commit comments

Comments
 (0)