1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use super::*;

impl Display for StringTextNode {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        f.write_char('\'')?;
        for c in self.text.chars() {
            match c {
                '\n' => f.write_str("\\n")?,
                '\r' => f.write_str("\\r")?,
                '\t' => f.write_str("\\t")?,
                '\\' => f.write_str("\\\\")?,
                '\'' => f.write_str("\\'")?,
                _ => f.write_char(c)?,
            }
        }
        f.write_char('\'')
    }
}

impl Display for StringLiteralNode {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        if let Some(unit) = &self.handler {
            f.write_str(&unit.name)?;
        }
        Display::fmt(&self.literal, f)
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for StringLiteralNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.string(self.to_string())
    }
}

#[cfg(feature = "lispify")]
impl Lispify for StringLiteralNode {
    type Output = Lisp;

    fn lispify(&self) -> Self::Output {
        let literal = Lisp::string(self.literal.to_string());
        match &self.handler {
            Some(s) => Lisp::unit(s.name.clone()) & literal,
            None => literal,
        }
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for StringTextNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.string(self.to_string())
    }
}