Add --regextype=RE2|EXACT: -grep literal vs regex mode (#99) - #213
Merged
Conversation
The first -grep enhancement and the answer to "exact vs regex": a --regextype global selects how -grep reads its pattern. RE2 (the default) is the regex engine; EXACT matches the pattern as a literal substring per line (so '.' is a literal dot and an unparseable-as-regex pattern like 'foo(bar' is a fine literal). The grep-flavor MATCH and the PCRE engine are reserved for #85 and refused now with a clear usage error (exit 2), as is any unknown value. Wiring: run.cc ResolveGrepLiteral (RE2->false, EXACT->true, MATCH/PCRE/unknown-> InvalidArgument, refused before the walk) threads EvalContext::grep_literal; EvalGrep branches to a literal StrContains matcher instead of the pre-compiled RE2 one, so EXACT never depends on the pattern being a valid regex. -content/-rxc and find's own -regextype primary are untouched (dash-count convention: --regextype is the xff global superset; #85 unifies them). Self-doc: --regextype in globals.cc + kHelpText; design.md -grep note updated to "shipped RE2|EXACT". Tests: evaluate_test (EXACT literal dot + regex-metachar-as- literal), run_test (EXACT vs RE2 default, reserved value is a usage error), grep_test.sh e2e. bazel test //... green (39).
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.
First
-grepenhancement (#99), and the answer to your "exact vs regex" requirement: a--regextypeglobal that selects how-grepreads its pattern.--regextype=RE2(default) - RE2 regex, as shipped.--regextype=EXACT- literal substring per line, so.is a literal dot and a pattern that isn't valid regex (foo(bar) is a fine literal.MATCH(grep/BRE flavor) andPCRE- reserved for refactor(printf): dispatch -printf directives and escapes via constexpr LimitedMaps #85; refused now with a clear usage error (exit 2), as is any unknown value.Wiring:
run.cc ResolveGrepLiteral(RE2→false, EXACT→true, MATCH/PCRE/unknown→InvalidArgument refused before the walk) threadsEvalContext::grep_literal;EvalGrepbranches to a literalStrContainsinstead of the pre-compiled RE2 matcher, so EXACT never depends on the pattern being a valid regex.-content/-rxcand find's own positional-regextypeprimary are untouched - per the dash-count convention--regextypeis the xff global superset; #85 unifies them.Self-doc:
--regextypein globals.cc +kHelpText; design.md-grepnote updated to "shipped RE2|EXACT". Tests: evaluate_test (EXACT literal dot + regex-metachar-as-literal), run_test (EXACT vs RE2 default, reserved value is a usage error), grep_test.sh e2e.bazel test //...green (39).Next in #99:
-grep=FORMATcustom template with{line}/{text}fields.