Skip to content

Add the EXACT literal regex engine (--regextype=EXACT), unify -grep's literal path (#85) - #314

Merged
helly25 merged 1 commit into
mainfrom
feat/regex-exact-engine
Jul 10, 2026
Merged

Add the EXACT literal regex engine (--regextype=EXACT), unify -grep's literal path (#85)#314
helly25 merged 1 commit into
mainfrom
feat/regex-exact-engine

Conversation

@helly25

@helly25 helly25 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

EXACT becomes a first-class match engine (Grammar::kExact) behind the RegexBackend seam, 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

  • 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).
  • --regextype=EXACT now reaches every pattern predicate (-regex/-rxc/-grep), not just -grep: GrammarFromGlobals maps EXACT -> kExact.
  • -grep unified. 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; the grep_literal EvalContext field is gone. Behavior is preserved (the existing EXACT -grep test still passes), and EXACT now respects case-mode uniformly (the old StrContains path 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.
  • Help: --regextype summary reframed as "match engine: RE2 / EXACT / PCRE2".

Test

regex_test (kExact ops + case-insensitive + literal span), parser_test (EXACT -> kExact), evaluate_test (-grep and -rxc under EXACT). bazel test //xff/... -> 72/72.

Next (regextype engine family, #85 / #121)

FNMATCH (flat wildcard via ::fnmatch) and GLOB (path-aware, via the ignore.cc glob->RE2 translator) core engines, then PCRE2 (the build extra: third_party/pcre2 + notice + full CI cell).

… 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.
@helly25
helly25 enabled auto-merge (squash) July 10, 2026 00:52
@helly25
helly25 merged commit 92e791e into main Jul 10, 2026
8 checks passed
@helly25
helly25 deleted the feat/regex-exact-engine branch July 10, 2026 01:04
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