Make string literal Debug more compact

This commit is contained in:
Joscha 2022-11-20 17:36:28 +01:00
parent 82e5b589e1
commit 9658907d76

View file

@ -53,7 +53,7 @@ impl HasSpan for NumLit {
} }
} }
#[derive(Debug, Clone)] #[derive(Clone)]
pub enum StringLitElem { pub enum StringLitElem {
/// Normal unescaped characters /// Normal unescaped characters
Plain(String), Plain(String),
@ -71,6 +71,20 @@ pub enum StringLitElem {
Newline, Newline,
} }
impl fmt::Debug for StringLitElem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Plain(str) => write!(f, "Plain({str:?})"),
Self::Unicode(char) => write!(f, "Unicode(0x{:x})", *char as u32),
Self::Backslash => write!(f, "Backslash"),
Self::DoubleQuote => write!(f, "DoubleQuote"),
Self::Tab => write!(f, "Tab"),
Self::CarriageReturn => write!(f, "CarriageReturn"),
Self::Newline => write!(f, "Newline"),
}
}
}
/// - `"Hello world\n"` /// - `"Hello world\n"`
/// - `""` /// - `""`
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -156,7 +170,10 @@ impl fmt::Debug for Lit {
Self::Bool(b, _) => write!(f, "l#{b:?}"), Self::Bool(b, _) => write!(f, "l#{b:?}"),
Self::Builtin(b, _) => write!(f, "l#{b:?}"), Self::Builtin(b, _) => write!(f, "l#{b:?}"),
Self::Num(n) => write!(f, "l#{n:?}"), Self::Num(n) => write!(f, "l#{n:?}"),
Self::String(s) => write!(f, "l#{s:?}"), Self::String(s) => {
write!(f, "l#")?;
s.fmt(f)
}
Self::Table(t) => { Self::Table(t) => {
write!(f, "l#")?; write!(f, "l#")?;
t.fmt(f) t.fmt(f)