New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the matchers crate #2945
Open
wyatt-herkamp
wants to merge
3
commits into
tokio-rs:master
Choose a base branch
from
wyatt-herkamp:matchers-crate
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−8
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ rust-version = "1.63.0" | |
default = ["smallvec", "fmt", "ansi", "tracing-log", "std"] | ||
alloc = ["tracing-core/alloc"] | ||
std = ["alloc", "tracing-core/std"] | ||
env-filter = ["matchers", "regex", "once_cell", "tracing", "std", "thread_local"] | ||
env-filter = ["regex-automata", "regex", "once_cell", "tracing", "std", "thread_local"] | ||
fmt = ["registry", "std"] | ||
ansi = ["fmt", "nu-ansi-term"] | ||
registry = ["sharded-slab", "thread_local", "std"] | ||
|
@@ -42,7 +42,7 @@ tracing-core = { path = "../tracing-core", version = "0.2", default-features = f | |
|
||
# only required by the `env-filter` feature | ||
tracing = { optional = true, path = "../tracing", version = "0.2", default-features = false } | ||
matchers = { optional = true, version = "0.1.0" } | ||
regex-automata = { optional = true, version = "0.4.6",default-features = false, features = ["syntax", "dfa-build", "dfa-search"] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, you're missing a space after the comma after version. |
||
regex = { optional = true, version = "1.6.0", default-features = false, features = ["std", "unicode-case", "unicode-perl"] } | ||
smallvec = { optional = true, version = "1.9.0" } | ||
once_cell = { optional = true, version = "1.13.0" } | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use matchers::Pattern; | ||
use std::{ | ||
cmp::Ordering, | ||
error::Error, | ||
|
@@ -10,7 +9,8 @@ use std::{ | |
}, | ||
}; | ||
|
||
use super::{FieldMap, LevelFilter}; | ||
use super::{matchers::Pattern, FieldMap, LevelFilter}; | ||
use regex_automata::dfa::dense::BuildError; | ||
use tracing_core::field::{Field, Visit}; | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone)] | ||
|
@@ -234,7 +234,7 @@ impl ValueMatch { | |
/// This returns an error if the string didn't contain a valid `bool`, | ||
/// `u64`, `i64`, or `f64` literal, and couldn't be parsed as a regular | ||
/// expression. | ||
fn parse_regex(s: &str) -> Result<Self, matchers::Error> { | ||
fn parse_regex(s: &str) -> Result<Self, BuildError> { | ||
s.parse::<bool>() | ||
.map(ValueMatch::Bool) | ||
.or_else(|_| s.parse::<u64>().map(ValueMatch::U64)) | ||
|
@@ -279,9 +279,9 @@ impl fmt::Display for ValueMatch { | |
// === impl MatchPattern === | ||
|
||
impl FromStr for MatchPattern { | ||
type Err = matchers::Error; | ||
type Err = regex_automata::dfa::dense::BuildError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have the type imported so there is no need to fully name it. |
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let matcher = Pattern::new_anchored(s)?; | ||
let matcher = Pattern::new(s)?; | ||
Ok(Self { | ||
matcher, | ||
pattern: s.to_owned().into(), | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/// Regex Matchers on characters and byte streams. This code is inspired by the [matchers](https://github.com/hawkw/matchers) crate | ||
/// The code was stripped down as everything was not needed and uses an updated version of regex-automata. | ||
use regex_automata::dfa::dense::{BuildError, DFA}; | ||
use regex_automata::dfa::Automaton; | ||
use regex_automata::util::primitives::StateID; | ||
use regex_automata::util::start::Config; | ||
use regex_automata::Anchored; | ||
use std::{fmt, fmt::Write}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub(crate) struct Pattern<A = DFA<Vec<u32>>> { | ||
automaton: A, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub(crate) struct Matcher<A = DFA<Vec<u32>>> { | ||
automaton: A, | ||
state: StateID, | ||
} | ||
|
||
impl Pattern { | ||
pub(crate) fn new(pattern: &str) -> Result<Self, BuildError> { | ||
let automaton = DFA::new(pattern)?; | ||
Ok(Pattern { automaton }) | ||
} | ||
} | ||
|
||
impl<A: Automaton> Pattern<A> { | ||
pub(crate) fn matcher(&self) -> Matcher<&'_ A> { | ||
Matcher { | ||
automaton: &self.automaton, | ||
state: self | ||
.automaton | ||
.start_state(&Config::new().anchored(Anchored::Yes)) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub(crate) fn matches(&self, s: &impl AsRef<str>) -> bool { | ||
self.matcher().matches(s) | ||
} | ||
|
||
pub(crate) fn debug_matches(&self, d: &impl fmt::Debug) -> bool { | ||
self.matcher().debug_matches(d) | ||
} | ||
} | ||
|
||
// === impl Matcher === | ||
|
||
impl<A> Matcher<A> | ||
where | ||
A: Automaton, | ||
{ | ||
#[inline] | ||
fn advance(&mut self, input: u8) { | ||
self.state = unsafe { self.automaton.next_state_unchecked(self.state, input) }; | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn is_matched(&self) -> bool { | ||
let eoi_state = self.automaton.next_eoi_state(self.state); | ||
self.automaton.is_match_state(eoi_state) | ||
} | ||
|
||
/// Returns `true` if this pattern matches the formatted output of the given | ||
/// type implementing `fmt::Debug`. | ||
pub(crate) fn matches(mut self, s: &impl AsRef<str>) -> bool { | ||
for &byte in s.as_ref().as_bytes() { | ||
self.advance(byte); | ||
if self.automaton.is_dead_state(self.state) { | ||
return false; | ||
} | ||
} | ||
self.is_matched() | ||
} | ||
|
||
pub(crate) fn debug_matches(mut self, d: &impl fmt::Debug) -> bool { | ||
write!(&mut self, "{:?}", d).expect("matcher write impl should not fail"); | ||
self.is_matched() | ||
} | ||
} | ||
|
||
impl<A: Automaton> fmt::Write for Matcher<A> { | ||
fn write_str(&mut self, s: &str) -> fmt::Result { | ||
for &byte in s.as_bytes() { | ||
self.advance(byte); | ||
if self.automaton.is_dead_state(self.state) { | ||
break; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of these changes should be in this PR. Whether it should be ignored or not is for a different discussion.