Skip to content

Walk the parser's own tree - #2

Merged
yoeunes merged 1 commit into
read-regex-shapes-through-phpregexfrom
walk-the-phpregex-ast
Oct 23, 2026
Merged

yoeunes merged 1 commit into
read-regex-shapes-through-phpregexfrom
walk-the-phpregex-ast

Conversation

@yoeunes

@yoeunes yoeunes commented Oct 23, 2026

Copy link
Copy Markdown
Member

Stacked on #1 — review that one first.

What

Drops the translation layer the first PR kept so its diff stayed minimal: the shape walkers read the nodes the parser built, no intermediate tree, no vocabulary conversion.

  • PHPRegexReader returns the parser's own RegexNode; the target it judges for (analysed PHP, bundled engine, pin that only narrows) is unchanged.
  • RegexGroupParser walks the native nodes: the separator tokens and the empty-branch patches the old grammar needed are gone by construction, and the quantifier bounds come from the parser's own reading.
  • IgnoredRegexValidator walks the same tree; branch text is sliced from the source between node positions, so escapes come back as written.
  • RegexTreeNode and the builder are deleted: −949 net lines, zero references left.

Why now and not in #1

The first PR ships the reader behind the seam so its diff only swaps the source of the trees the walkers already consumed. This one removes the seam — reviewing them together would ask the reviewer to check a new parser and a walker rewrite in one pass; stacked, each diff says one thing.

Test plan

Same judges as #1: the shape pins (backreference, verbs, \Q..\E, (?J), /x, version-shaped escapes, PcreVersion architecture) and the resolver suite — 1873/1873, every fixture saying what it said through the translation.

The translation layer between the parser's AST and the shape walkers
is gone: the walkers read the nodes the parser built, the alternations
come without their separator tokens and the empty branches without
their patch-up passes, and the quantifier bounds come from the parser's
own reading instead of a re-parse of the token text. IgnoredRegexValidator
reads the same tree, its branch text sliced from the source between
node positions so escapes come back as they were written. A padded hex
escape still types 'ax{ 41 }' for PHP 7.4 and the letter A on 8.x, the
inline (?i:...) groups still drop the constants their caseless body
cannot promise, and every resolver fixture says the same thing it said
through the translation: 1873 of 1873.
@yoeunes
yoeunes force-pushed the walk-the-phpregex-ast branch from 40a0270 to c3b490f Compare October 23, 2026 18:29
@yoeunes
yoeunes merged commit c3b490f into read-regex-shapes-through-phpregex Oct 23, 2026
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