Skip to content

Commit

Permalink
feat: add support for dynamic class constant fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jan 5, 2024
1 parent 657546d commit e0c5bd9
Show file tree
Hide file tree
Showing 6 changed files with 130,088 additions and 127,117 deletions.
11 changes: 10 additions & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,20 @@ module.exports = function defineGrammar(dialect) {

parenthesized_expression: $ => seq('(', $._expression, ')'),

class_constant_access_expression: $ => seq(
class_constant_access_expression: $ => choice(
$._class_constant_access_expression,
$._dynamic_class_constant_access_expression,
),
_class_constant_access_expression: $ => seq(
$._scope_resolution_qualifier,
'::',
choice($.name, alias($._reserved_identifier, $.name)),
),
_dynamic_class_constant_access_expression: $ => seq(
$._scope_resolution_qualifier,
'::',
alias(seq('{', $._expression, '}'), $.name),
),

print_intrinsic: $ => seq(
keyword('print'), $._expression,
Expand Down
17 changes: 17 additions & 0 deletions common/test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1543,3 +1543,20 @@ $statement = match ($a) {
)
)

===============================================
Dynamic class constant access
===============================================

<?php
Foo::{$bar};

---

(program
(php_tag)
(expression_statement
(class_constant_access_expression
(name)
(name)
(name (variable_name (name)))
(name))))
48 changes: 48 additions & 0 deletions php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4763,6 +4763,19 @@
]
},
"class_constant_access_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_class_constant_access_expression"
},
{
"type": "SYMBOL",
"name": "_dynamic_class_constant_access_expression"
}
]
},
"_class_constant_access_expression": {
"type": "SEQ",
"members": [
{
Expand Down Expand Up @@ -4793,6 +4806,41 @@
}
]
},
"_dynamic_class_constant_access_expression": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_scope_resolution_qualifier"
},
{
"type": "STRING",
"value": "::"
},
{
"type": "ALIAS",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "}"
}
]
},
"named": true,
"value": "name"
}
]
},
"print_intrinsic": {
"type": "SEQ",
"members": [
Expand Down
Loading

0 comments on commit e0c5bd9

Please sign in to comment.