Skip to content

Lexer: read underscore in a tag name - #330

Merged
ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
ondrejmirtes:underscore-in-tag-name
Oct 26, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
ondrejmirtes:underscore-in-tag-name

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

The lexer read @Foo_Bar as the tag @Foo and the text _Bar. A Doctrine annotation class name can contain an underscore, e.g. @Foo_Bar(1). TOKEN_DOCTRINE_TAG already accepts an underscore, but TOKEN_PHPDOC_TAG matches first.

This PR adds _ to the tag name characters in Lexer and in doc/grammars/lexemes.pp3. The namespace prefix (@foo:) does not change.

Rector has a workaround for this in its parser. With this change, the workaround can be removed.

Checks: tests on PHP 8.4 and 7.4, PHPStan, phpcs, the test suite of slevomat/coding-standard and the test suite of rector-src with this lexer.

@ondrejmirtes
ondrejmirtes force-pushed the underscore-in-tag-name branch 2 times, most recently from b27c9aa to 1ec0850 Compare October 26, 2026 19:34
The lexer read @Foo_Bar as the tag @foo and the text _Bar.
A Doctrine annotation class name can contain an underscore,
e.g. @Foo_Bar(1).

Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
@ondrejmirtes
ondrejmirtes force-pushed the underscore-in-tag-name branch from 1ec0850 to 5068a3f Compare October 26, 2026 20:17
@ondrejmirtes
ondrejmirtes merged commit 025f398 into phpstan:2.3.x Oct 26, 2026
61 checks passed
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.

1 participant