Thread the regex grammar (--regextype) through the parser to the matchers (#85) - #313
Merged
Conversation
…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.
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.
Plumbing for #85's PCRE2 backend: resolve the regex grammar once from
--regextypeat parse time and carry it onCommand.grammar, so every pattern matcher (-regex/-iregex/-rxc/-irxc/-grepand the-captureextraction regex) compiles under it, and theApplyCaseModecase-insensitive recompile reuses it. Previously the parser always compiled RE2 regardless of--regextype.What this does
GrammarFromGlobalsmaps--regextype(PCRE2->kPcre2, elsekRe2, last occurrence wins);ExprParsercarriesgrammar_and threads it throughMakePredicate->CompileNodeRegex->Matcher::Compile;ApplyCaseModeToNodetakes the grammar for its recompile.Commandgains agrammarfield (defaultkRe2).Safe to land before the backend
With no PCRE2 backend linked,
Matcher::Compile(kPcre2)returnsUnimplementedandrun.cc'sResolveGrepLiteralalready 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.GrammarFromGlobalsis deliberately lenient (unknown / not-built-in -> RE2);ResolveGrepLiteralstays the single validating reader.Test
parser_testassertsCommand.grammartracks--regextype(default/RE2/PCRE2/EXACT/last-wins).bazel test //xff/...-> 72/72 pass.Next (PR 5b, #85)
third_party/pcre2/realPcre2Backend(self-registers viaPcre2Registrar+ BSD-3 notice), linked intoxff_fullviaselect({"//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 carrieskPcre2to the real backend.