Skip to content

Add the GLOB path-aware regex engine + extract the shared xff/glob lib (#85, #121) - #316

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

Add the GLOB path-aware regex engine + extract the shared xff/glob lib (#85, #121)#316
helly25 merged 1 commit into
mainfrom
feat/regex-glob-engine

Conversation

@helly25

@helly25 helly25 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

GLOB is the path-segment-aware shell glob (*/? stop at /, ** crosses directories - the shell / gitignore semantics), the fourth core engine behind the RegexBackend seam. It reuses the escape-aware glob->RE2 translation that already powered the gitignore engine, now factored into a shared user-lib.

What this does

  • New //xff/glob: glob::GlobToRegex(pattern) translates a shell glob to an RE2 pattern (*->[^/]*, ?->[^/], ** segment -> cross-directory, [!]->[^], RE2 metacharacters + \-escapes handled). Extracted verbatim from ignore.cc, with its own glob_test.
  • ignore now calls glob::GlobToRegex (behavior unchanged; ignore_test still green).
  • regex: Grammar::kGlob compiles the translated pattern as RE2 and reuses Re2Backend, so FullMatch/PartialMatch/FindFirst (a real span, not fnmatch's whole-string) / Rewrite all come from RE2. A shared compile_re2 lambda backs kRe2 and kGlob.
  • parser/run/help: --regextype=GLOB -> kGlob (reaches -regex/-rxc/-grep); a core engine, always available; the summary lists all five engines.

GLOB vs FNMATCH

Both are shell wildcards, but FNMATCH is flat (* matches any char incl /, the -name/-path behavior) while GLOB is path-aware (* stops at /, ** crosses directories, the gitignore/shell-pathspec behavior). They serve different purposes, hence independent engines.

Test

glob_test (the translation), regex_test (path-aware */**, RE2-backed span + partial match), parser_test (GLOB -> kGlob), evaluate_test (-rxc path-aware). bazel test //xff/... -> 73/73.

Engine family status

RE2 (default) + EXACT + FNMATCH + GLOB are the four core engines, all behind one RegexBackend seam. Last up: PCRE2 - the build extra (third_party/pcre2 self-registering backend + BSD notice + full CI cell), landing into xff_full via the //xff:xff_pcre select.

#85, #121)

GLOB is the path-segment-aware shell glob (`*`/`?` stop at `/`, `**` crosses
directories - the shell / gitignore semantics), the fourth core engine behind the
RegexBackend seam. It reuses the escape-aware glob->RE2 translation already in the
gitignore engine, now factored into a shared user-lib.

- new //xff/glob: `glob::GlobToRegex(pattern)` translates a shell glob to an RE2
  pattern (`*`->`[^/]*`, `?`->`[^/]`, `**` segment->cross-directory, `[!]`->`[^]`,
  RE2 metacharacters + `\`-escapes handled). Extracted verbatim from ignore.cc.
- ignore: now calls glob::GlobToRegex (behavior unchanged; ignore_test still green).
- regex: Grammar::kGlob compiles the translated pattern as RE2 and reuses Re2Backend,
  so FullMatch/PartialMatch/FindFirst (a real span)/Rewrite all come from RE2 - no
  fnmatch whole-string limitation. A shared `compile_re2` lambda backs kRe2 and kGlob.
- parser/run/help: --regextype=GLOB -> kGlob (reaches -regex/-rxc/-grep); a core
  engine, always available; the summary lists all five engines.

Tests: glob_test (the translation), regex_test (path-aware `*`/`**`, RE2-backed span
+ partial), parser_test (GLOB -> kGlob), evaluate_test (-rxc path-aware). //xff/... -> 73/73.
@helly25
helly25 enabled auto-merge (squash) July 10, 2026 01:31
@helly25
helly25 merged commit 9f54049 into main Jul 10, 2026
8 checks passed
@helly25
helly25 deleted the feat/regex-glob-engine branch July 10, 2026 01:41
helly25 added a commit that referenced this pull request Jul 10, 2026
Record the follow-up surfaced after #316: //xff/glob:GlobToRegex duplicates
mbo::file::Glob2Re2Expression / Glob2Re2 (mbo/file/glob.h, already in the pinned
mbo), which #316 did not check before factoring the gitignore translator into a
shared lib. Capture the known `**`/range semantic divergences and the decision to
make (keep both / migrate onto mbo + delete //xff/glob / fix mbo upstream / keep
ours), gated on ignore_test + the GLOB regex_test.
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