Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@ jobs:
examples/framework/tests/Foundation/Fixtures/bad-syntax-strategy.php
examples/phpunit/tests/end-to-end/code-coverage/_files/parse-error/src/CannotBeParsed.php
examples/WordPress/wp-includes/php-compat/readonly.php
examples/WordPress/wp-includes/class-wp-block-processor.php
2 changes: 1 addition & 1 deletion CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/common.mak
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(error Windows is not supported)
endif

HOMEPAGE_URL := https://github.com/tree-sitter/tree-sitter-php
VERSION := 0.25.1
VERSION := 0.25.2

# repository
SRC_DIR := src
Expand Down
36 changes: 30 additions & 6 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ const CAST_TYPES = [
'int', 'integer', 'object', 'real', 'string', 'unset',
];

const CAST_TYPE_CONSTANT_NAMES = CAST_TYPES.filter(type => !['array', 'unset'].includes(type));

const CAST_TYPE_CLASS_NAMES = CAST_TYPE_CONSTANT_NAMES.filter(type => ![
'bool', 'float', 'int', 'object', 'string',
].includes(type));

module.exports = function defineGrammar(dialect) {
if (dialect !== 'php' && dialect !== 'php_only') {
throw new Error(`Unknown dialect ${dialect}`);
Expand Down Expand Up @@ -288,6 +294,7 @@ module.exports = function defineGrammar(dialect) {

_name: $ => choice(
alias(keyword('static', false), $.name),
alias(choice(...CAST_TYPE_CLASS_NAMES.map(type => keyword(type, false))), $.name),
reserved('classes', $.name),
$.qualified_name,
$.relative_name,
Expand Down Expand Up @@ -655,8 +662,25 @@ module.exports = function defineGrammar(dialect) {

_return_type: $ => seq(':', field('return_type', choice($.type, $.bottom_type))),

_const_element: $ => seq($.name, '=', $.expression),
_class_const_element: $ => seq(reserved('nothing', $.name), '=', $.expression),
_const_element: $ => seq(
choice(
$.name,
alias(choice(...[
'bool', 'float', 'int', 'iterable', 'mixed', 'object', 'string', 'void',
].map(type => keyword(type, false))), $.name),
),
'=',
$.expression,
),
_class_const_element: $ => seq(
choice(
reserved('nothing', $.name),
alias($.primitive_type, $.name),
alias(keyword('namespace', false), $.name),
),
'=',
$.expression,
),

echo_statement: $ => seq(keyword('echo'), $._expressions, $._semicolon),

Expand Down Expand Up @@ -1008,6 +1032,10 @@ module.exports = function defineGrammar(dialect) {
$.qualified_name,
$.relative_name,
$.name,
prec(-1, alias(
choice(...CAST_TYPE_CONSTANT_NAMES.map(type => keyword(type, false))),
$.name,
)),
$.array_creation_expression,
$.print_intrinsic,
$.anonymous_function,
Expand Down Expand Up @@ -1282,10 +1310,6 @@ module.exports = function defineGrammar(dialect) {
$.variadic_unpacking,
$.expression,
$.argument_placeholder,
prec(-1, alias(
choice(...CAST_TYPES.map(type => keyword(type, false))),
$.name,
)),
),
),

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading