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 25, 2024
1 parent 5a779d3 commit fab0c75
Show file tree
Hide file tree
Showing 6 changed files with 129,099 additions and 128,284 deletions.
6 changes: 5 additions & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,11 @@ module.exports = function defineGrammar(dialect) {
class_constant_access_expression: $ => seq(
$._scope_resolution_qualifier,
'::',
choice($.name, alias($._reserved_identifier, $.name)),
choice(
$.name,
alias($._reserved_identifier, $.name),
seq('{', alias($._expression, $.name), '}'),
),
),

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

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

<?php
Foo::{$bar};

---

(program
(php_tag)
(expression_statement
(class_constant_access_expression
(name)
(name (variable_name (name))))))
22 changes: 22 additions & 0 deletions php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4881,6 +4881,28 @@
},
"named": true,
"value": "name"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_expression"
},
"named": true,
"value": "name"
},
{
"type": "STRING",
"value": "}"
}
]
}
]
}
Expand Down
Loading

0 comments on commit fab0c75

Please sign in to comment.