Skip to content

Thread the regex grammar (--regextype) through the parser to the matchers (#85) - #313

Merged
helly25 merged 1 commit into
mainfrom
feat/pcre2-backend
Jul 10, 2026
Merged

Thread the regex grammar (--regextype) through the parser to the matchers (#85)#313
helly25 merged 1 commit into
mainfrom
feat/pcre2-backend

Conversation

@helly25

@helly25 helly25 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Plumbing for #85's PCRE2 backend: resolve the regex grammar once from --regextype at parse time and carry it on Command.grammar, so every pattern matcher (-regex/-iregex/-rxc/-irxc/-grep and the -capture extraction regex) compiles under it, and the ApplyCaseMode case-insensitive recompile reuses it. Previously the parser always compiled RE2 regardless of --regextype.

What this does

  • parser: GrammarFromGlobals maps --regextype (PCRE2 -> kPcre2, else kRe2, last occurrence wins); ExprParser carries grammar_ and threads it through MakePredicate -> CompileNodeRegex -> Matcher::Compile; ApplyCaseModeToNode takes the grammar for its recompile.
  • ast: Command gains a grammar field (default kRe2).

Safe to land before the backend

With no PCRE2 backend linked, Matcher::Compile(kPcre2) returns Unimplemented and run.cc's ResolveGrepLiteral already rejects --regextype=PCRE2 (exit 2) before the walk. So the grammar is RE2 in every reachable path today - no behavior change, no silent RE2 fallback window. GrammarFromGlobals is deliberately lenient (unknown / not-built-in -> RE2); ResolveGrepLiteral stays the single validating reader.

Test

parser_test asserts Command.grammar tracks --regextype (default/RE2/PCRE2/EXACT/last-wins). bazel test //xff/... -> 72/72 pass.

Next (PR 5b, #85)

third_party/pcre2/ real Pcre2Backend (self-registers via Pcre2Registrar + BSD-3 notice), linked into xff_full via select({"//xff:xff_pcre_enabled": [...]}), ReDoS limits, PCRE2-only tests (lookahead/backreferences) under --config=xff_full, and a CI full cell. Once linked, this PR's threading carries kPcre2 to the real backend.

…hers (#85)

Resolve the regex grammar once from --regextype at parse time and carry it on
Command.grammar, so every pattern matcher (-regex/-iregex/-rxc/-irxc/-grep and
the -capture extraction regex) compiles under it, and the ApplyCaseMode
case-insensitive recompile reuses it. Previously the parser always compiled RE2
regardless of --regextype.

- parser: GrammarFromGlobals maps --regextype (PCRE2 -> kPcre2, else kRe2, last
  wins); ExprParser carries grammar_ and threads it through MakePredicate ->
  CompileNodeRegex -> Matcher::Compile; ApplyCaseModeToNode takes the grammar too.
- ast: Command gains a `grammar` field (default kRe2).

This is the plumbing for #85's PCRE2 backend. It is safe to land before the
backend: with no backend linked, Matcher::Compile(kPcre2) is Unimplemented and
run.cc's ResolveGrepLiteral already rejects --regextype=PCRE2 (exit 2) before the
walk, so the grammar is RE2 in every reachable path today. GrammarFromGlobals is
deliberately lenient (unknown/unavailable -> RE2); ResolveGrepLiteral stays the
single validating reader. parser_test asserts Command.grammar tracks --regextype.
@helly25
helly25 enabled auto-merge (squash) July 10, 2026 00:25
@helly25
helly25 merged commit 3d36199 into main Jul 10, 2026
8 checks passed
@helly25
helly25 deleted the feat/pcre2-backend branch July 10, 2026 00:36
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