logo
 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
use super::*;

impl<'a> Display for AstGroup<'a> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let children: Vec<_> = self.children.iter().map(|s| s.to_string()).collect();
        write!(f, "{}({})", self.head, children.join(" "))
    }
}

impl<'a> Display for AstGroupItem<'a> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Grouped(g) => Display::fmt(g, f),
            Self::Styled(g) => Display::fmt(g, f),
        }
    }
}

impl<'a> Display for AstStyle<'a> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        for v in &self.variants {
            write!(f, "{}", v)?
        }
        if self.negative {
            write!(f, "-")?
        }
        write!(f, "{}", self.elements.join("-"))?;
        match self.arbitrary {
            None => {}
            Some(s) => write!(f, "-[{}]", s)?,
        }
        Ok(())
    }
}

impl<'a> Display for ASTVariant<'a> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if self.not {
            write!(f, "not-")?
        }
        write!(f, "{}", self.names.join("-"))?;
        match self.pseudo {
            true => write!(f, "::"),
            false => write!(f, ":"),
        }
    }
}