diff --git a/src/ast/lit.rs b/src/ast/lit.rs index ea87ab7..299bc1c 100644 --- a/src/ast/lit.rs +++ b/src/ast/lit.rs @@ -53,7 +53,7 @@ impl HasSpan for NumLit { } } -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum StringLitElem { /// Normal unescaped characters Plain(String), @@ -71,6 +71,20 @@ pub enum StringLitElem { 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"` /// - `""` #[derive(Debug, Clone)] @@ -156,7 +170,10 @@ impl fmt::Debug for Lit { Self::Bool(b, _) => write!(f, "l#{b:?}"), Self::Builtin(b, _) => write!(f, "l#{b:?}"), 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) => { write!(f, "l#")?; t.fmt(f)