Skip to content

Commit 690838e

Browse files
committed
Named case class pattern
1 parent f6f6708 commit 690838e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

grammar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,10 @@ module.exports = grammar({
10321032
seq(
10331033
field("type", choice($._type_identifier, $.stable_type_identifier)),
10341034
"(",
1035-
field("pattern", trailingCommaSep($._pattern)),
1035+
choice(
1036+
field("pattern", trailingCommaSep($._pattern)),
1037+
field("pattern", trailingCommaSep($.named_pattern)),
1038+
),
10361039
")",
10371040
),
10381041

test/corpus/patterns.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,35 @@ def showNotification(notification: Notification): String = {
203203
(interpolation
204204
(identifier))))))))))
205205

206+
================================================================================
207+
Case class patterns (Scala 3 syntax)
208+
================================================================================
209+
210+
class A:
211+
c match
212+
case c @ City(name = "Hoboken") => c.population
213+
214+
--------------------------------------------------------------------------------
215+
216+
(compilation_unit
217+
(class_definition
218+
(identifier)
219+
(template_body
220+
(match_expression
221+
(identifier)
222+
(indented_cases
223+
(case_clause
224+
(capture_pattern
225+
(identifier)
226+
(case_class_pattern
227+
(type_identifier)
228+
(named_pattern
229+
(identifier)
230+
(string))))
231+
(field_expression
232+
(identifier)
233+
(identifier))))))))
234+
206235
================================================================================
207236
Infix patterns
208237
================================================================================

0 commit comments

Comments
 (0)