summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2019-04-05 21:03:22 -0400
committerAndrew Gallant <jamslam@gmail.com>2019-04-05 23:24:08 -0400
commitbe7d6dd9ced86d22f440d5cb79f419a28ca53994 (patch)
treeac0666de7fd35685b96b839a244e2014027b0a90
parent9f15e3b671d64efa261f6de0fd4c6c06e0caa21c (diff)
regex: print out final regex in trace mode
This is useful for debugging to see what regex is actually being run. We put this as a trace since the regex can be quite gnarly. (It is not pretty printed.)
-rw-r--r--grep-regex/src/crlf.rs5
-rw-r--r--grep-regex/src/matcher.rs14
-rw-r--r--grep-regex/src/word.rs5
3 files changed, 23 insertions, 1 deletions
diff --git a/grep-regex/src/crlf.rs b/grep-regex/src/crlf.rs
index 838a28f8..244f536e 100644
--- a/grep-regex/src/crlf.rs
+++ b/grep-regex/src/crlf.rs
@@ -34,6 +34,11 @@ impl CRLFMatcher {
}
Ok(CRLFMatcher { regex, names })
}
+
+ /// Return the underlying regex used by this matcher.
+ pub fn regex(&self) -> &Regex {
+ &self.regex
+ }
}
impl Matcher for CRLFMatcher {
diff --git a/grep-regex/src/matcher.rs b/grep-regex/src/matcher.rs
index b15d824c..391439d9 100644
--- a/grep-regex/src/matcher.rs
+++ b/grep-regex/src/matcher.rs
@@ -50,9 +50,12 @@ impl RegexMatcherBuilder {
if let Some(ref re) = fast_line_regex {
trace!("extracted fast line regex: {:?}", re);
}
+
+ let matcher = RegexMatcherImpl::new(&chir)?;
+ trace!("final regex: {:?}", matcher.regex());
Ok(RegexMatcher {
config: self.config.clone(),
- matcher: RegexMatcherImpl::new(&chir)?,
+ matcher: matcher,
fast_line_regex: fast_line_regex,
non_matching_bytes: non_matching_bytes,
})
@@ -370,6 +373,15 @@ impl RegexMatcherImpl {
Ok(RegexMatcherImpl::Standard(StandardMatcher::new(expr)?))
}
}
+
+ /// Return the underlying regex object used.
+ fn regex(&self) -> &Regex {
+ match *self {
+ RegexMatcherImpl::Word(ref x) => x.regex(),
+ RegexMatcherImpl::CRLF(ref x) => x.regex(),
+ RegexMatcherImpl::Standard(ref x) => &x.regex,
+ }
+ }
}
// This implementation just dispatches on the internal matcher impl except
diff --git a/grep-regex/src/word.rs b/grep-regex/src/word.rs
index be740020..86291f20 100644
--- a/grep-regex/src/word.rs
+++ b/grep-regex/src/word.rs
@@ -55,6 +55,11 @@ impl WordMatcher {
}
Ok(WordMatcher { regex, names, locs })
}
+
+ /// Return the underlying regex used by this matcher.
+ pub fn regex(&self) -> &Regex {
+ &self.regex
+ }
}
impl Matcher for WordMatcher {