Add the EXACT literal regex engine (--regextype=EXACT), unify -grep's literal path (#85) - #314
Merged
Merged
Conversation
… literal path (#85) EXACT becomes a first-class match engine (Grammar::kExact) behind the RegexBackend seam, not a -grep-only bool - the first non-RE2 engine, proving the multi-engine architecture with a trivial core (always-linked, no dependency) backend. - regex: ExactBackend implements RegexBackend via std::string comparison - FullMatch = equality, PartialMatch = substring, FindFirst = first occurrence span, Rewrite = literal find/replace (no backreferences); case_insensitive folds ASCII case on both sides. Compile(kExact) never fails (no pattern to compile). - parser: GrammarFromGlobals maps --regextype=EXACT -> kExact, so EXACT now reaches every pattern predicate (-regex/-rxc/-grep), not just -grep. - engine: unify -grep. The old ctx.grep_literal StrContains path is exactly what ExactBackend.PartialMatch/FindFirst do, so -grep now runs through the pre-compiled matcher like -rxc; drop the grep_literal EvalContext field. Behavior is preserved (the existing EXACT -grep test still passes) and EXACT now respects case mode uniformly (the old StrContains path ignored -i/smart-case). - run: ResolveGrepLiteral (returned the literal bool) becomes ValidateRegextype (validates the selector only; PCRE2-not-built / MATCH-reserved / unknown are still usage errors before the walk). The grammar is resolved by the parser. - help: --regextype summary reframed as "match engine: RE2 / EXACT / PCRE2". Tests: regex_test (kExact ops + ci + literal span), parser_test (EXACT -> kExact), evaluate_test (-grep and -rxc under EXACT). bazel test //xff/... -> 72/72.
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.
EXACT becomes a first-class match engine (
Grammar::kExact) behind theRegexBackendseam, not a-grep-only bool. It's the first non-RE2 engine - a trivial, always-linked core backend that proves the multi-engine architecture ahead of the PCRE2 (build-extra) work.What this does
ExactBackendimplementsRegexBackendviastd::stringcomparison:FullMatch= equality,PartialMatch= substring,FindFirst= first-occurrence span,Rewrite= literal find/replace (no backreferences);case_insensitivefolds ASCII case on both sides.Compile(kExact)never fails (no pattern to compile).--regextype=EXACTnow reaches every pattern predicate (-regex/-rxc/-grep), not just-grep:GrammarFromGlobalsmapsEXACT -> kExact.-grepunified. The oldctx.grep_literalStrContainspath is exactly whatExactBackend.PartialMatch/FindFirstdo, so-grepnow runs through the pre-compiled matcher like-rxc; thegrep_literalEvalContextfield is gone. Behavior is preserved (the existing EXACT-greptest still passes), and EXACT now respects case-mode uniformly (the oldStrContainspath silently ignored-i/smart-case).ResolveGrepLiteral->ValidateRegextype(validates the selector only; PCRE2-not-built / MATCH-reserved / unknown remain usage errors before the walk). The grammar is resolved by the parser.--regextypesummary reframed as "match engine: RE2 / EXACT / PCRE2".Test
regex_test(kExact ops + case-insensitive + literal span),parser_test(EXACT -> kExact),evaluate_test(-grepand-rxcunder EXACT).bazel test //xff/...-> 72/72.Next (regextype engine family, #85 / #121)
FNMATCH (flat wildcard via
::fnmatch) and GLOB (path-aware, via theignore.ccglob->RE2 translator) core engines, then PCRE2 (the build extra:third_party/pcre2+ notice + full CI cell).