Add the GLOB path-aware regex engine + extract the shared xff/glob lib (#85, #121) - #316
Merged
Conversation
#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
enabled auto-merge (squash)
July 10, 2026 01:31
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.
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.
GLOB is the path-segment-aware shell glob (
*/?stop at/,**crosses directories - the shell / gitignore semantics), the fourth core engine behind theRegexBackendseam. It reuses the escape-aware glob->RE2 translation that already powered the gitignore engine, now factored into a shared user-lib.What this does
//xff/glob:glob::GlobToRegex(pattern)translates a shell glob to an RE2 pattern (*->[^/]*,?->[^/],**segment -> cross-directory,[!]->[^], RE2 metacharacters +\-escapes handled). Extracted verbatim fromignore.cc, with its ownglob_test.ignorenow callsglob::GlobToRegex(behavior unchanged;ignore_teststill green).regex:Grammar::kGlobcompiles the translated pattern as RE2 and reusesRe2Backend, soFullMatch/PartialMatch/FindFirst(a real span, not fnmatch's whole-string) /Rewriteall come from RE2. A sharedcompile_re2lambda backskRe2andkGlob.--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/-pathbehavior) 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(-rxcpath-aware).bazel test //xff/...-> 73/73.Engine family status
RE2 (default) + EXACT + FNMATCH + GLOB are the four core engines, all behind one
RegexBackendseam. Last up: PCRE2 - the build extra (third_party/pcre2self-registering backend + BSD notice + full CI cell), landing intoxff_fullvia the//xff:xff_pcreselect.