Skip to content

Commit 3dd2526

Browse files
committed
Read regex shapes with PHPRegex instead of the generated parser
The shapes of preg_match(), preg_match_all() and preg_replace_callback() are read from the AST and the capture shape analysis of PHPRegex, a PCRE2 pattern parser that runs on PHP 7.4. The generated parser, its grammar, its build script and the phplrt runtime are removed, and ignoreErrors patterns are validated with the same parser. Patterns are read for the analysed PHP version and the PCRE2 version it bundles; a pcreVersion parameter, or config.platform.lib-pcre in composer.json, can set that version. With bleeding edge, RegularExpressionPatternRule also reports a pattern the running PHP compiles but the analysed PHP does not. A new test matches every constant pattern of the preg_* fixtures with the engine, on generated subjects and with every flag combination, and checks that the inferred type accepts what the engine writes.
1 parent 035c883 commit 3dd2526

65 files changed

Lines changed: 2584 additions & 5421 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.typos.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[files]
22
extend-exclude = [
33
".git/",
4-
# generated by `make regex-parser`, contains lexer regexes
5-
"src/Type/Regex/Parser/RegexParser.php",
64
]
75
ignore-hidden = false
86

‎Makefile‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ phpstan-generate-baseline-php:
177177
phpstan-pro:
178178
php -d memory_limit=450M bin/phpstan --pro
179179

180-
# Regenerates src/Type/Regex/Parser/RegexParser.php from
181-
# build/regex-parser/RegexGrammar.pp3 with the phplrt compiler. The compiler
182-
# needs PHP 8.4+, the generated parser only needs the phplrt runtime.
183-
.PHONY: regex-parser
184-
regex-parser:
185-
composer install --working-dir build/regex-parser
186-
php build/regex-parser/generate.php
187-
188180
name-collision:
189181
php vendor/bin/detect-collisions --configuration build/collision-detector.json
190182

‎build/phpstan.neon‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ parameters:
3939
- ../tests/PHPStan/Reflection/MixedTypeTest.php
4040
- ../tests/e2e/magic-setter/*
4141
- ../tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php
42-
- ../tests/PHPStan/Command/IgnoredRegexValidatorTest.php
43-
- ../src/Command/IgnoredRegexValidator.php
44-
- ../src/Type/Regex/Parser/RegexParser.php
4542
exceptions:
4643
uncheckedExceptionClasses:
4744
- 'PHPStan\ShouldNotHappenException'

‎build/regex-parser/.gitignore‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)