Skip to content

fix: parse keyword identifiers in expressions and constants - #307

Open
calebdw wants to merge 3 commits into
masterfrom
calebdw/push-yxztyvnwyxxl
Open

calebdw wants to merge 3 commits into
masterfrom
calebdw/push-yxztyvnwyxxl

Conversation

@calebdw

@calebdw calebdw commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #295

Accept cast keywords as expression names so argument values can continue
into scoped calls and compound expressions. Keep class-name aliases
limited to cast spellings that PHP permits as class identifiers.

Accept type keywords in valid global and class constant declarations,
with coverage for reserved names, typed constants, casts, and named
arguments. Restore example parsing for the affected WordPress file.

Fixes #295.
Regenerate both PHP parsers for keyword identifier and constant fixes.
@calebdw
calebdw requested a review from cfroystad October 8, 2026 15:48
Prepare the keyword identifier and constant parsing fixes for release.
Keep package manifests, lockfiles, and parser metadata in sync.
@alexwrite

alexwrite commented Oct 11, 2026 •

Copy link
Copy Markdown

Tested this branch (head 74de061, built as the Python binding) against real code, and it fixes the typed case too, which the corpus only covers with VOID:

  • Keyword as a typed class constant name (public const string DEFAULT = ..., PRIVATE, CLASS, NEW, FUNCTION...): 61 of the 83 keywords I tried fail on 0.24.1 / master, 0 with this PR. Untyped: 7 fail before (CALLABLE, NAMESPACE, MIXED, VOID, TRUE, FALSE, ITERABLE), 0 after.
  • On two private Symfony codebases (2,943 and 476 PHP files under src/ and tests/), files with parse errors go from 2 to 0 and from 0 to 0. In one of the two broken files, error recovery swallowed the whole class_declaration.
  • tree-sitter test (CLI 0.27.0): 157/157.

In case it helps, here is a corpus case for keyword-named typed constants (final, optional, union and named types, in a class, an interface and an enum). It fails on master and passes on this branch: alexwrite@9678351

Thanks for the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: constant declarations with names matching certain reserved words result in parsing errors

2 participants