summaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2019-04-14 17:39:37 -0400
committerAndrew Gallant <jamslam@gmail.com>2019-04-14 19:29:27 -0400
commit967e7ad0de3e657e8f81c1384a48ca1eea4edde7 (patch)
treecabe8250acf34508fc60724104fa05bbcd257295 /src/args.rs
parent9952ba2068bd0f9baf74a2094d0d1db493b71180 (diff)
ripgrep: add --auto-hybrid-regex flag
This flag, when set, will automatically dispatch to PCRE2 if the given regex cannot be compiled by Rust's regex engine. If both engines fail to compile the regex, then both errors are surfaced. Closes #1155
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs
index 389de1dd..80693da8 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -599,6 +599,25 @@ impl ArgMatches {
if self.is_present("pcre2") {
let matcher = self.matcher_pcre2(patterns)?;
Ok(PatternMatcher::PCRE2(matcher))
+ } else if self.is_present("auto-hybrid-regex") {
+ let rust_err = match self.matcher_rust(patterns) {
+ Ok(matcher) => return Ok(PatternMatcher::RustRegex(matcher)),
+ Err(err) => err,
+ };
+ log::debug!(
+ "error building Rust regex in hybrid mode:\n{}", rust_err,
+ );
+ let pcre_err = match self.matcher_pcre2(patterns) {
+ Ok(matcher) => return Ok(PatternMatcher::PCRE2(matcher)),
+ Err(err) => err,
+ };
+ Err(From::from(format!(
+ "regex could not be compiled with either the default regex \
+ engine or with PCRE2.\n\n\
+ default regex engine error:\n{}\n{}\n{}\n\n\
+ PCRE2 regex engine error:\n{}",
+ "~".repeat(79), rust_err, "~".repeat(79), pcre_err,
+ )))
} else {
let matcher = match self.matcher_rust(patterns) {
Ok(matcher) => matcher,