Skip to content

Commit

Permalink
Merge pull request #158 from brandonspark/switch-pattern-matching
Browse files Browse the repository at this point in the history
feat(java 21): complete pattern matching for switch statements
  • Loading branch information
aryx authored Aug 22, 2023
2 parents 0b3f9cf + 65cf2e0 commit 2a15634
Show file tree
Hide file tree
Showing 5 changed files with 28,214 additions and 27,547 deletions.
10 changes: 9 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,13 @@ module.exports = grammar({
),

switch_label: $ => choice(
seq('case', choice($.pattern, commaSep1($.expression))),
seq('case',
choice(
$.pattern,
commaSep1($.expression)
),
optional($.guard)
),
'default'
),

Expand All @@ -498,6 +504,8 @@ module.exports = grammar({
choice($.identifier, $._reserved_identifier)
),

guard: $ => seq('when', $.expression),

// Statements

statement: $ => choice(
Expand Down
25 changes: 25 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,18 @@
]
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "guard"
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -3840,6 +3852,19 @@
}
]
},
"guard": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "when"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
},
"statement": {
"type": "CHOICE",
"members": [
Expand Down
23 changes: 23 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,21 @@
]
}
},
{
"type": "guard",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "if_statement",
"named": true,
Expand Down Expand Up @@ -3503,6 +3518,10 @@
"type": "expression",
"named": true
},
{
"type": "guard",
"named": true
},
{
"type": "pattern",
"named": true
Expand Down Expand Up @@ -4512,6 +4531,10 @@
"type": "volatile",
"named": false
},
{
"type": "when",
"named": false
},
{
"type": "while",
"named": false
Expand Down
Loading

0 comments on commit 2a15634

Please sign in to comment.