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
54
55
56
57
58
59
60
61
62
use super::*;

impl Debug for FlagDeclaration {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        let w = &mut match self.kind {
            FlagKind::Enumerate => f.debug_struct("Enumerate"),
            FlagKind::Flags => f.debug_struct("Flags"),
        };
        if !self.annotations.is_empty() {
            w.field("annotations", &self.annotations);
        }
        w.field("name", &self.name);
        w.field("terms", &self.body);
        if let Some(inherits) = &self.layout {
            w.field("layout", inherits);
        }
        if let Some(inherits) = &self.implements {
            w.field("implements", inherits);
        }
        w.field("body", &self.body);
        w.field("span", &self.span);
        w.finish()
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for FlagDeclaration {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        terms += theme.keyword("enumerate");
        terms += " ";
        terms += self.namepath.pretty(theme);
        terms += self.body.pretty(theme);
        terms.into()
    }
}

impl Debug for FlagTerm {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Macro(v) => Debug::fmt(v, f),
            Self::Encode(v) => Debug::fmt(v, f),
            Self::Method(v) => Debug::fmt(v, f),
        }
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for EncodeDeclaration {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(3);
        terms += self.name.pretty(theme);
        if let Some(value) = &self.value {
            terms += " ";
            terms += theme.operator("=");
            terms += " ";
            terms += value.pretty(theme);
        }
        terms += ",";
        terms.into()
    }
}