Skip to content
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

PR: add codes key/legend for debug output in regex-automata #1175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions regex-automata/src/dfa/dense.rs
Expand Up @@ -3077,6 +3077,11 @@ impl<T: AsRef<[u32]>> DFA<T> {

impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"\nCodes:\tD - Dead State, Q - Quit State, > - Start State,\
\n\t\tA - Accel State, * - Match State\n"
)?;
writeln!(f, "dense::DFA(")?;
for state in self.states() {
fmt_state_indicator(f, self, state.id())?;
Expand All @@ -3087,9 +3092,9 @@ impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
};
write!(f, "{:06?}: ", id)?;
state.fmt(f)?;
write!(f, "\n")?;
writeln!(f)?;
}
writeln!(f, "")?;
writeln!(f)?;
for (i, (start_id, anchored, sty)) in self.starts().enumerate() {
let id = if f.alternate() {
start_id.as_usize()
Expand All @@ -3108,7 +3113,7 @@ impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
writeln!(f, " {:?} => {:06?}", sty, id)?;
}
if self.pattern_len() > 1 {
writeln!(f, "")?;
writeln!(f)?;
for i in 0..self.ms.len() {
let id = self.ms.match_state_id(self, i);
let id = if f.alternate() {
Expand All @@ -3124,7 +3129,7 @@ impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
}
write!(f, "{:?}", pid)?;
}
writeln!(f, "")?;
writeln!(f)?;
}
}
writeln!(f, "state length: {:?}", self.state_len())?;
Expand Down
5 changes: 3 additions & 2 deletions regex-automata/src/dfa/onepass.rs
Expand Up @@ -2395,6 +2395,7 @@ impl core::fmt::Debug for DFA {
Ok(())
}

writeln!(f, "\nCodes:\tD - Dead State, * - Match State\n")?;
writeln!(f, "onepass::DFA(")?;
for index in 0..self.state_len() {
let sid = StateID::must(index);
Expand All @@ -2412,9 +2413,9 @@ impl core::fmt::Debug for DFA {
}
write!(f, ": ")?;
debug_state_transitions(f, self, sid)?;
write!(f, "\n")?;
writeln!(f)?;
}
writeln!(f, "")?;
writeln!(f)?;
for (i, &sid) in self.starts.iter().enumerate() {
if i == 0 {
writeln!(f, "START(ALL): {:?}", sid.as_usize())?;
Expand Down
7 changes: 6 additions & 1 deletion regex-automata/src/dfa/sparse.rs
Expand Up @@ -1073,12 +1073,17 @@ impl<'a> DFA<&'a [u8]> {

impl<T: AsRef<[u8]>> fmt::Debug for DFA<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"\nCodes:\tD - Dead State, Q - Quit State, > - Start State,\
\n\t\tA - Accel State, * - Match State\n"
)?;
writeln!(f, "sparse::DFA(")?;
for state in self.tt.states() {
fmt_state_indicator(f, self, state.id())?;
writeln!(f, "{:06?}: {:?}", state.id().as_usize(), state)?;
}
writeln!(f, "")?;
writeln!(f)?;
for (i, (start_id, anchored, sty)) in self.st.iter().enumerate() {
if i % self.st.stride == 0 {
match anchored {
Expand Down
5 changes: 3 additions & 2 deletions regex-automata/src/nfa/thompson/nfa.rs
Expand Up @@ -1458,6 +1458,7 @@ impl Inner {

impl fmt::Debug for Inner {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "\nCodes:\t^ - Start Anchored, > - Start Unanchored\n")?;
writeln!(f, "thompson::NFA(")?;
for (sid, state) in self.states.iter().with_state_ids() {
let status = if sid == self.start_anchored {
Expand All @@ -1471,13 +1472,13 @@ impl fmt::Debug for Inner {
}
let pattern_len = self.start_pattern.len();
if pattern_len > 1 {
writeln!(f, "")?;
writeln!(f)?;
for pid in 0..pattern_len {
let sid = self.start_pattern[pid];
writeln!(f, "START({:06?}): {:?}", pid, sid.as_usize())?;
}
}
writeln!(f, "")?;
writeln!(f)?;
writeln!(
f,
"transition equivalence classes: {:?}",
Expand Down