Skip to content

Commit

Permalink
Merge pull request #124 from bkramer-relyance/bkramer/records_and_ins…
Browse files Browse the repository at this point in the history
…tanceof_final

Fix issues with records and support instanceof final
  • Loading branch information
aryx authored Sep 19, 2022
2 parents e74abfa + ee2d345 commit 09d650d
Show file tree
Hide file tree
Showing 7 changed files with 32,299 additions and 32,608 deletions.
10 changes: 10 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ module.exports = grammar({
instanceof_expression: $ => prec(PREC.REL, seq(
field('left', $.expression),
'instanceof',
optional('final'),
field('right', $._type),
field('name', optional(choice($.identifier, $._reserved_identifier)))
)),
Expand Down Expand Up @@ -833,6 +834,7 @@ module.exports = grammar({
$.field_declaration,
$.record_declaration,
$.method_declaration,
$.compact_constructor_declaration, // For records.
$.class_declaration,
$.interface_declaration,
$.annotation_type_declaration,
Expand Down Expand Up @@ -910,6 +912,7 @@ module.exports = grammar({
field('name', $.identifier),
optional(field('type_parameters', $.type_parameters)),
field('parameters', $.formal_parameters),
optional(field('interfaces', $.super_interfaces)),
field('body', $.class_body)
),

Expand Down Expand Up @@ -970,6 +973,7 @@ module.exports = grammar({
$.method_declaration,
$.class_declaration,
$.interface_declaration,
$.record_declaration,
$.annotation_type_declaration,
';'
)),
Expand Down Expand Up @@ -1137,6 +1141,12 @@ module.exports = grammar({
choice(field('body', $.block), ';')
),

compact_constructor_declaration: $ => seq(
optional($.modifiers),
field('name', $.identifier),
field('body', $.block)
),

_reserved_identifier: $ => alias(choice(
'open',
'module',
Expand Down
69 changes: 69 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,18 @@
"type": "STRING",
"value": "instanceof"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "final"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "right",
Expand Down Expand Up @@ -5421,6 +5433,10 @@
"type": "SYMBOL",
"name": "method_declaration"
},
{
"type": "SYMBOL",
"name": "compact_constructor_declaration"
},
{
"type": "SYMBOL",
"name": "class_declaration"
Expand Down Expand Up @@ -5810,6 +5826,22 @@
"name": "formal_parameters"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "interfaces",
"content": {
"type": "SYMBOL",
"name": "super_interfaces"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "body",
Expand Down Expand Up @@ -6118,6 +6150,10 @@
"type": "SYMBOL",
"name": "interface_declaration"
},
{
"type": "SYMBOL",
"name": "record_declaration"
},
{
"type": "SYMBOL",
"name": "annotation_type_declaration"
Expand Down Expand Up @@ -6952,6 +6988,39 @@
}
]
},
"compact_constructor_declaration": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "modifiers"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "block"
}
}
]
},
"_reserved_identifier": {
"type": "ALIAS",
"content": {
Expand Down
58 changes: 58 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,10 @@
"type": "class_declaration",
"named": true
},
{
"type": "compact_constructor_declaration",
"named": true
},
{
"type": "constructor_declaration",
"named": true
Expand Down Expand Up @@ -1237,6 +1241,42 @@
]
}
},
{
"type": "compact_constructor_declaration",
"named": true,
"fields": {
"body": {
"multiple": false,
"required": true,
"types": [
{
"type": "block",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "modifiers",
"named": true
}
]
}
},
{
"type": "constant_declaration",
"named": true,
Expand Down Expand Up @@ -1605,6 +1645,10 @@
"type": "class_declaration",
"named": true
},
{
"type": "compact_constructor_declaration",
"named": true
},
{
"type": "constructor_declaration",
"named": true
Expand Down Expand Up @@ -2230,6 +2274,10 @@
{
"type": "method_declaration",
"named": true
},
{
"type": "record_declaration",
"named": true
}
]
}
Expand Down Expand Up @@ -2909,6 +2957,16 @@
}
]
},
"interfaces": {
"multiple": false,
"required": false,
"types": [
{
"type": "super_interfaces",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
Expand Down
Loading

0 comments on commit 09d650d

Please sign in to comment.