Skip to content

Commit b1a25db

Browse files
committed
syntax: improve Debug impl for Class
Previously, classes would show up in the debug representation as very deeply nested things, making them more difficult to read than they need to be. This removes at least a few pretty redundant layers and uses a more compact range notation.
1 parent a742a7d commit b1a25db

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

regex-syntax/src/hir/mod.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl core::fmt::Debug for Literal {
787787
/// the author of the regular expression to disable Unicode mode, which in turn
788788
/// impacts the semantics of case insensitive matching. For example, `(?i)k`
789789
/// and `(?i-u)k` will not match the same set of strings.
790-
#[derive(Clone, Debug, Eq, PartialEq)]
790+
#[derive(Clone, Eq, PartialEq)]
791791
pub enum Class {
792792
/// A set of characters represented by Unicode scalar values.
793793
Unicode(ClassUnicode),
@@ -986,6 +986,27 @@ impl Class {
986986
}
987987
}
988988

989+
impl core::fmt::Debug for Class {
990+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
991+
use crate::debug::Byte;
992+
993+
let mut fmter = f.debug_set();
994+
match *self {
995+
Class::Unicode(ref cls) => {
996+
for r in cls.ranges().iter() {
997+
fmter.entry(&(r.start..=r.end));
998+
}
999+
}
1000+
Class::Bytes(ref cls) => {
1001+
for r in cls.ranges().iter() {
1002+
fmter.entry(&(Byte(r.start)..=Byte(r.end)));
1003+
}
1004+
}
1005+
}
1006+
fmter.finish()
1007+
}
1008+
}
1009+
9891010
/// A set of characters represented by Unicode scalar values.
9901011
#[derive(Clone, Debug, Eq, PartialEq)]
9911012
pub struct ClassUnicode {

0 commit comments

Comments
 (0)