Repository navigation
Replace Hoa with a regex parser generated by phplrt - #6851
Merged
Merged
Conversation
The grammar is ported to phplrt's PP3 format in build/regex-parser/RegexGrammar.pp3 and compiled with `make regex-parser` into src/Type/Regex/Parser/RegexParser.php. The compiler runs on PHP 8.4+ and is not a dependency of PHPStan. The generated parser only needs the phplrt runtime, provided by ondrejmirtes/phplrt-runtime, a fork downgraded to PHP 7.4. The parser builds the same trees Hoa did, so RegexGroupParser and IgnoredRegexValidator walk them without changes in behaviour. Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
…h_all() with PREG_SET_ORDER Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
… keyed by match index Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
… separate alternation branches Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
…apes for patterns with subroutine calls Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
…he only top level alternation Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
…subpatterns might match an empty string Amp-Thread-ID: https://ampcode.com/threads/T-01a177b5-960f-71d2-a3e2-fa7649f39d2c
acrobat
reviewed
Oct 26, 2026
Comment on lines
-55
to
-61
| // fix missing key for vendor/hoa/protocol/Wrapper.php | ||
| $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? []; | ||
| $GLOBALS['__composer_autoload_files'] = array_merge( | ||
| $existingComposerAutoloadFiles, | ||
| array_fill_keys(['3e76f7f02b41af8cea96018933f6b7e3'], true), | ||
| ); | ||
|
|
There was a problem hiding this comment.
@ondrejmirtes can this actually be removed? As this was added because of autoload error in projects using hoa/protocol phpstan/phpstan#13369
Member
Author
There was a problem hiding this comment.
Entire Hoa library was removed from PHPStan, so yes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes all
hoa/*packages (and the 16 patches for them) that PHPStan used to parse regexes, and replaces them with a parser generated by phplrt.How it works
build/regex-parser/RegexGrammar.pp3(keeping Hoa's license header). Its reducers build the same tree shape Hoa produced, soRegexGroupParserchanges are minimal.make regex-parserinstalls the phplrt compiler intobuild/regex-parser/vendor(needs PHP 8.4+) and generatessrc/Type/Regex/Parser/RegexParser.php. The generated parser is committed and must not be edited by hand.ondrejmirtes/phplrt-runtimeis needed: a PHP 7.4 compatible fork of the phplrt runtime packages (manual downgrade commit + RectorDOWN_TO_PHP_74), so it works after the PHAR is downgraded.bin/phpstan(autoload files hack) andAutoloadFilesTest. CLAUDE.md documents the regex parser setup.Verification
Every pattern from the php-src test suite (PHP-8.6 branch) and the PCRE2 test suite was run through real
preg_match()/preg_match_all()and compared with the inferred array shape:\Eandx-mode comment edge cases)The follow-up commits fix the shape inference bugs this found. Each comes with regression tests taken from those suites that fail without the fix. Parse trees were also checked to be identical between PHP 8.4 (upstream runtime) and PHP 7.4 (fork + downgraded parser), and identical to Hoa's for all patterns Hoa could parse.
Benchmarks
PHP 8.4, the 3,510 corpus patterns both parsers accept, 5 rounds:
phplrt also parses 191 more of the corpus patterns than Hoa.