From 932aade25053369393991d45c3d53b9b41689d59 Mon Sep 17 00:00:00 2001 From: Crypto-Spartan Date: Wed, 13 Mar 2024 02:08:52 -0400 Subject: [PATCH 1/2] add 'codes legend' for debug output --- regex-automata/src/dfa/dense.rs | 5 +++++ regex-automata/src/dfa/onepass.rs | 1 + regex-automata/src/dfa/sparse.rs | 5 +++++ regex-automata/src/nfa/thompson/nfa.rs | 1 + 4 files changed, 12 insertions(+) diff --git a/regex-automata/src/dfa/dense.rs b/regex-automata/src/dfa/dense.rs index 8e0f33c03..3ca78ae6f 100644 --- a/regex-automata/src/dfa/dense.rs +++ b/regex-automata/src/dfa/dense.rs @@ -3077,6 +3077,11 @@ impl> DFA { impl> fmt::Debug for DFA { 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())?; diff --git a/regex-automata/src/dfa/onepass.rs b/regex-automata/src/dfa/onepass.rs index e62bbd383..e5cbbf725 100644 --- a/regex-automata/src/dfa/onepass.rs +++ b/regex-automata/src/dfa/onepass.rs @@ -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); diff --git a/regex-automata/src/dfa/sparse.rs b/regex-automata/src/dfa/sparse.rs index 46278c181..7e3657adc 100644 --- a/regex-automata/src/dfa/sparse.rs +++ b/regex-automata/src/dfa/sparse.rs @@ -1073,6 +1073,11 @@ impl<'a> DFA<&'a [u8]> { impl> fmt::Debug for DFA { 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())?; diff --git a/regex-automata/src/nfa/thompson/nfa.rs b/regex-automata/src/nfa/thompson/nfa.rs index 1f57f8ebd..88cb48a57 100644 --- a/regex-automata/src/nfa/thompson/nfa.rs +++ b/regex-automata/src/nfa/thompson/nfa.rs @@ -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 { From 5bf3d5ceee480fcb98a05e93d45e64666a64e34c Mon Sep 17 00:00:00 2001 From: Crypto-Spartan Date: Wed, 13 Mar 2024 02:56:30 -0400 Subject: [PATCH 2/2] fix some clippy lints --- regex-automata/src/dfa/dense.rs | 8 ++++---- regex-automata/src/dfa/onepass.rs | 4 ++-- regex-automata/src/dfa/sparse.rs | 2 +- regex-automata/src/nfa/thompson/nfa.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/regex-automata/src/dfa/dense.rs b/regex-automata/src/dfa/dense.rs index 3ca78ae6f..39e64708a 100644 --- a/regex-automata/src/dfa/dense.rs +++ b/regex-automata/src/dfa/dense.rs @@ -3092,9 +3092,9 @@ impl> fmt::Debug for DFA { }; 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() @@ -3113,7 +3113,7 @@ impl> fmt::Debug for DFA { 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() { @@ -3129,7 +3129,7 @@ impl> fmt::Debug for DFA { } write!(f, "{:?}", pid)?; } - writeln!(f, "")?; + writeln!(f)?; } } writeln!(f, "state length: {:?}", self.state_len())?; diff --git a/regex-automata/src/dfa/onepass.rs b/regex-automata/src/dfa/onepass.rs index e5cbbf725..8a709a3ec 100644 --- a/regex-automata/src/dfa/onepass.rs +++ b/regex-automata/src/dfa/onepass.rs @@ -2413,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())?; diff --git a/regex-automata/src/dfa/sparse.rs b/regex-automata/src/dfa/sparse.rs index 7e3657adc..d9cadd16a 100644 --- a/regex-automata/src/dfa/sparse.rs +++ b/regex-automata/src/dfa/sparse.rs @@ -1083,7 +1083,7 @@ impl> fmt::Debug for DFA { 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 { diff --git a/regex-automata/src/nfa/thompson/nfa.rs b/regex-automata/src/nfa/thompson/nfa.rs index 88cb48a57..fb54046af 100644 --- a/regex-automata/src/nfa/thompson/nfa.rs +++ b/regex-automata/src/nfa/thompson/nfa.rs @@ -1472,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: {:?}",