Skip to content

Commit 09d650d

Browse files
authored
Merge pull request #124 from bkramer-relyance/bkramer/records_and_instanceof_final
Fix issues with records and support instanceof final
2 parents e74abfa + ee2d345 commit 09d650d

File tree

7 files changed

+32299
-32608
lines changed

7 files changed

+32299
-32608
lines changed

grammar.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ module.exports = grammar({
230230
instanceof_expression: $ => prec(PREC.REL, seq(
231231
field('left', $.expression),
232232
'instanceof',
233+
optional('final'),
233234
field('right', $._type),
234235
field('name', optional(choice($.identifier, $._reserved_identifier)))
235236
)),
@@ -833,6 +834,7 @@ module.exports = grammar({
833834
$.field_declaration,
834835
$.record_declaration,
835836
$.method_declaration,
837+
$.compact_constructor_declaration, // For records.
836838
$.class_declaration,
837839
$.interface_declaration,
838840
$.annotation_type_declaration,
@@ -910,6 +912,7 @@ module.exports = grammar({
910912
field('name', $.identifier),
911913
optional(field('type_parameters', $.type_parameters)),
912914
field('parameters', $.formal_parameters),
915+
optional(field('interfaces', $.super_interfaces)),
913916
field('body', $.class_body)
914917
),
915918

@@ -970,6 +973,7 @@ module.exports = grammar({
970973
$.method_declaration,
971974
$.class_declaration,
972975
$.interface_declaration,
976+
$.record_declaration,
973977
$.annotation_type_declaration,
974978
';'
975979
)),
@@ -1137,6 +1141,12 @@ module.exports = grammar({
11371141
choice(field('body', $.block), ';')
11381142
),
11391143

1144+
compact_constructor_declaration: $ => seq(
1145+
optional($.modifiers),
1146+
field('name', $.identifier),
1147+
field('body', $.block)
1148+
),
1149+
11401150
_reserved_identifier: $ => alias(choice(
11411151
'open',
11421152
'module',

src/grammar.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,18 @@
20062006
"type": "STRING",
20072007
"value": "instanceof"
20082008
},
2009+
{
2010+
"type": "CHOICE",
2011+
"members": [
2012+
{
2013+
"type": "STRING",
2014+
"value": "final"
2015+
},
2016+
{
2017+
"type": "BLANK"
2018+
}
2019+
]
2020+
},
20092021
{
20102022
"type": "FIELD",
20112023
"name": "right",
@@ -5421,6 +5433,10 @@
54215433
"type": "SYMBOL",
54225434
"name": "method_declaration"
54235435
},
5436+
{
5437+
"type": "SYMBOL",
5438+
"name": "compact_constructor_declaration"
5439+
},
54245440
{
54255441
"type": "SYMBOL",
54265442
"name": "class_declaration"
@@ -5810,6 +5826,22 @@
58105826
"name": "formal_parameters"
58115827
}
58125828
},
5829+
{
5830+
"type": "CHOICE",
5831+
"members": [
5832+
{
5833+
"type": "FIELD",
5834+
"name": "interfaces",
5835+
"content": {
5836+
"type": "SYMBOL",
5837+
"name": "super_interfaces"
5838+
}
5839+
},
5840+
{
5841+
"type": "BLANK"
5842+
}
5843+
]
5844+
},
58135845
{
58145846
"type": "FIELD",
58155847
"name": "body",
@@ -6118,6 +6150,10 @@
61186150
"type": "SYMBOL",
61196151
"name": "interface_declaration"
61206152
},
6153+
{
6154+
"type": "SYMBOL",
6155+
"name": "record_declaration"
6156+
},
61216157
{
61226158
"type": "SYMBOL",
61236159
"name": "annotation_type_declaration"
@@ -6952,6 +6988,39 @@
69526988
}
69536989
]
69546990
},
6991+
"compact_constructor_declaration": {
6992+
"type": "SEQ",
6993+
"members": [
6994+
{
6995+
"type": "CHOICE",
6996+
"members": [
6997+
{
6998+
"type": "SYMBOL",
6999+
"name": "modifiers"
7000+
},
7001+
{
7002+
"type": "BLANK"
7003+
}
7004+
]
7005+
},
7006+
{
7007+
"type": "FIELD",
7008+
"name": "name",
7009+
"content": {
7010+
"type": "SYMBOL",
7011+
"name": "identifier"
7012+
}
7013+
},
7014+
{
7015+
"type": "FIELD",
7016+
"name": "body",
7017+
"content": {
7018+
"type": "SYMBOL",
7019+
"name": "block"
7020+
}
7021+
}
7022+
]
7023+
},
69557024
"_reserved_identifier": {
69567025
"type": "ALIAS",
69577026
"content": {

src/node-types.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,10 @@
11151115
"type": "class_declaration",
11161116
"named": true
11171117
},
1118+
{
1119+
"type": "compact_constructor_declaration",
1120+
"named": true
1121+
},
11181122
{
11191123
"type": "constructor_declaration",
11201124
"named": true
@@ -1237,6 +1241,42 @@
12371241
]
12381242
}
12391243
},
1244+
{
1245+
"type": "compact_constructor_declaration",
1246+
"named": true,
1247+
"fields": {
1248+
"body": {
1249+
"multiple": false,
1250+
"required": true,
1251+
"types": [
1252+
{
1253+
"type": "block",
1254+
"named": true
1255+
}
1256+
]
1257+
},
1258+
"name": {
1259+
"multiple": false,
1260+
"required": true,
1261+
"types": [
1262+
{
1263+
"type": "identifier",
1264+
"named": true
1265+
}
1266+
]
1267+
}
1268+
},
1269+
"children": {
1270+
"multiple": false,
1271+
"required": false,
1272+
"types": [
1273+
{
1274+
"type": "modifiers",
1275+
"named": true
1276+
}
1277+
]
1278+
}
1279+
},
12401280
{
12411281
"type": "constant_declaration",
12421282
"named": true,
@@ -1605,6 +1645,10 @@
16051645
"type": "class_declaration",
16061646
"named": true
16071647
},
1648+
{
1649+
"type": "compact_constructor_declaration",
1650+
"named": true
1651+
},
16081652
{
16091653
"type": "constructor_declaration",
16101654
"named": true
@@ -2230,6 +2274,10 @@
22302274
{
22312275
"type": "method_declaration",
22322276
"named": true
2277+
},
2278+
{
2279+
"type": "record_declaration",
2280+
"named": true
22332281
}
22342282
]
22352283
}
@@ -2909,6 +2957,16 @@
29092957
}
29102958
]
29112959
},
2960+
"interfaces": {
2961+
"multiple": false,
2962+
"required": false,
2963+
"types": [
2964+
{
2965+
"type": "super_interfaces",
2966+
"named": true
2967+
}
2968+
]
2969+
},
29122970
"name": {
29132971
"multiple": false,
29142972
"required": true,

0 commit comments

Comments
 (0)