Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for final class constants introduced in PHP 8.1 #88

Merged
merged 2 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ module.exports = grammar({

class_declaration: $ => prec.right(seq(
optional(field('attributes', $.attribute_list)),
optional($.class_modifier),
optional(field('modifier', choice($.final_modifier, $.abstract_modifier))),
keyword('class'),
field('name', $.name),
optional($.base_clause),
Expand All @@ -259,10 +259,8 @@ module.exports = grammar({
'}'
),

class_modifier: $ => choice(
keyword('abstract'),
keyword('final')
),
final_modifier: $ => keyword('final'),
abstract_modifier: $ => keyword('abstract'),

class_interface_clause: $ => seq(
keyword('implements'),
Expand All @@ -280,6 +278,7 @@ module.exports = grammar({

_class_const_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
optional(field('modifier', $.final_modifier)),
$._const_declaration
),

Expand All @@ -298,12 +297,13 @@ module.exports = grammar({
$._semicolon
),

_modifier: $ => choice(
_modifier: $ => prec.left(choice(
$.var_modifier,
$.visibility_modifier,
$.static_modifier,
$.class_modifier
),
$.final_modifier,
$.abstract_modifier
)),

property_element: $ => seq(
$.variable_name, optional($.property_initializer)
Expand Down
118 changes: 75 additions & 43 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,21 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "class_modifier"
"type": "FIELD",
"name": "modifier",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "final_modifier"
},
{
"type": "SYMBOL",
"name": "abstract_modifier"
}
]
}
},
{
"type": "BLANK"
Expand Down Expand Up @@ -1063,28 +1076,23 @@
}
]
},
"class_modifier": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[aA][bB][sS][tT][rR][aA][cC][tT]"
},
"named": false,
"value": "abstract"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[fF][iI][nN][aA][lL]"
},
"named": false,
"value": "final"
}
]
"final_modifier": {
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[fF][iI][nN][aA][lL]"
},
"named": false,
"value": "final"
},
"abstract_modifier": {
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[aA][bB][sS][tT][rR][aA][cC][tT]"
},
"named": false,
"value": "abstract"
},
"class_interface_clause": {
"type": "SEQ",
Expand Down Expand Up @@ -1210,6 +1218,22 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "modifier",
"content": {
"type": "SYMBOL",
"name": "final_modifier"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_const_declaration"
Expand Down Expand Up @@ -1345,25 +1369,33 @@
]
},
"_modifier": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "var_modifier"
},
{
"type": "SYMBOL",
"name": "visibility_modifier"
},
{
"type": "SYMBOL",
"name": "static_modifier"
},
{
"type": "SYMBOL",
"name": "class_modifier"
}
]
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "var_modifier"
},
{
"type": "SYMBOL",
"name": "visibility_modifier"
},
{
"type": "SYMBOL",
"name": "static_modifier"
},
{
"type": "SYMBOL",
"name": "final_modifier"
},
{
"type": "SYMBOL",
"name": "abstract_modifier"
}
]
}
},
"property_element": {
"type": "SEQ",
Expand Down
67 changes: 50 additions & 17 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@
}
]
},
{
"type": "abstract_modifier",
"named": true,
"fields": {}
},
{
"type": "anonymous_function_creation_expression",
"named": true,
Expand Down Expand Up @@ -1178,6 +1183,20 @@
}
]
},
"modifier": {
"multiple": false,
"required": false,
"types": [
{
"type": "abstract_modifier",
"named": true
},
{
"type": "final_modifier",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
Expand All @@ -1200,10 +1219,6 @@
{
"type": "class_interface_clause",
"named": true
},
{
"type": "class_modifier",
"named": true
}
]
}
Expand All @@ -1227,11 +1242,6 @@
]
}
},
{
"type": "class_modifier",
"named": true,
"fields": {}
},
{
"type": "clone_expression",
"named": true,
Expand Down Expand Up @@ -1326,6 +1336,16 @@
"named": true
}
]
},
"modifier": {
"multiple": false,
"required": false,
"types": [
{
"type": "final_modifier",
"named": true
}
]
}
},
"children": {
Expand Down Expand Up @@ -1614,6 +1634,11 @@
]
}
},
{
"type": "final_modifier",
"named": true,
"fields": {}
},
{
"type": "finally_clause",
"named": true,
Expand Down Expand Up @@ -2446,7 +2471,11 @@
"required": false,
"types": [
{
"type": "class_modifier",
"type": "abstract_modifier",
"named": true
},
{
"type": "final_modifier",
"named": true
},
{
Expand Down Expand Up @@ -3061,7 +3090,11 @@
"required": true,
"types": [
{
"type": "class_modifier",
"type": "abstract_modifier",
"named": true
},
{
"type": "final_modifier",
"named": true
},
{
Expand Down Expand Up @@ -4495,11 +4528,11 @@
},
{
"type": "float",
"named": true
"named": false
},
{
"type": "float",
"named": false
"named": true
},
{
"type": "fn",
Expand Down Expand Up @@ -4563,11 +4596,11 @@
},
{
"type": "integer",
"named": true
"named": false
},
{
"type": "integer",
"named": false
"named": true
},
{
"type": "interface",
Expand Down Expand Up @@ -4599,11 +4632,11 @@
},
{
"type": "null",
"named": false
"named": true
},
{
"type": "null",
"named": true
"named": false
},
{
"type": "object",
Expand Down
Loading