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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use super::*;

impl Debug for TraitDeclaration {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        let w = &mut match &self.kind {
            TraitKind::Trait => f.debug_struct("Trait"),
            TraitKind::Interface => f.debug_struct("Interface"),
        };
        w.field("name", &self.name);
        if let Some(g) = &self.generics {
            w.field("generics", g);
        }
        if let Some(g) = &self.implements {
            w.field("implements", g);
        }

        w.field("body", &self.body);
        w.finish()
    }
}

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

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

    fn lispify(&self) -> Self::Output {
        let mut out = Lisp::new(10);
        out += Lisp::keyword("trait");
        out += Lisp::string(self.name.to_string());
        for field in &self.body {
            let mut inside = Lisp::new(10);
            inside += Lisp::keyword("trait/field");
            inside += Lisp::string(field.name.to_string());
            out += inside;
        }
        for field in &self.methods {
            let mut inside = Lisp::new(10);
            inside += Lisp::keyword("trait/methods");
            inside += Lisp::string(field.method_name.to_string());
            out += inside;
        }
        out
    }
}

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

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

    fn lispify(&self) -> Self::Output {
        Lisp::keyword("extends")
    }
}

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