Skip to content

Commit e714736

Browse files
authored
Merge pull request #281 from eed3si9n/wip/repeat_pattern
2 parents 2e32a0b + a48f466 commit e714736

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

corpus/patterns.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ val x = y match {
141141
case a @ B(1) => a
142142
case b @ C(d @ (e @ X, _: Y)) => e
143143
case req @ (POST | GET) -> Root / "test" => 5
144+
case Array(a: Type, _@_*) => y
144145
}
145146

146147
---
@@ -168,7 +169,18 @@ val x = y match {
168169
(capture_pattern (identifier)
169170
(tuple_pattern (alternative_pattern (identifier) (identifier))))
170171
(operator_identifier) (identifier)) (operator_identifier) (string))
171-
(integer_literal))))))
172+
(integer_literal))
173+
(case_clause
174+
(case_class_pattern
175+
(type_identifier)
176+
(typed_pattern
177+
(identifier)
178+
(type_identifier))
179+
(repeat_pattern
180+
(capture_pattern
181+
(wildcard)
182+
(wildcard))))
183+
(identifier))))))
172184

173185
============================
174186
Quoted patterns (Scala 3 syntax)

grammar.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,8 @@ module.exports = grammar({
913913
$.typed_pattern,
914914
$.quote_expression,
915915
$.literal,
916-
$.wildcard
916+
$.wildcard,
917+
$.repeat_pattern,
917918
),
918919

919920
case_class_pattern: $ => seq(
@@ -929,10 +930,15 @@ module.exports = grammar({
929930
field('right', $._pattern),
930931
)),
931932

932-
capture_pattern: $ => prec(PREC.field, seq(
933-
field('name', $._identifier),
933+
capture_pattern: $ => prec.right(PREC.field, seq(
934+
field('name', choice($._identifier, $.wildcard)),
934935
'@',
935-
field('pattern', $._pattern)
936+
field('pattern', $._pattern),
937+
)),
938+
939+
repeat_pattern: $ => prec.right(seq(
940+
field('pattern', $._pattern),
941+
'*',
936942
)),
937943

938944
typed_pattern: $ => prec.right(seq(

0 commit comments

Comments
 (0)