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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use super::*;

impl FunctionKind {
    /// Get the string representation of the function kind
    pub fn as_str(&self) -> &'static str {
        match self {
            FunctionKind::Macro => "macro",
            FunctionKind::Micro => "micro",
        }
    }
}

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

#[cfg(feature = "pretty-print")]
impl PrettyPrint for FunctionDeclaration {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        for m in &self.modifiers {
            terms += theme.keyword(m.name.clone());
            terms += " ";
        }
        terms += theme.keyword(self.r#type.as_str());
        terms += " ";
        terms += self.name.pretty(theme);
        if let Some(gen) = &self.generics {
            terms += gen.pretty(theme);
        }
        terms += self.parameters.pretty(theme);
        if let Some(ret) = &self.r#return {
            terms += ": ";
            terms += ret.typing.pretty(theme);
        }
        terms += self.body.pretty(theme);
        terms.into()
    }
}
#[cfg(feature = "lispify")]
impl Lispify for FunctionDeclaration {
    type Output = Lisp;

    fn lispify(&self) -> Self::Output {
        let mut lisp = Lisp::new(6);
        // lisp += self.r#type.lispify();
        lisp += self.name.lispify();
        if let Some(generic) = &self.generics {
            lisp += generic.lispify();
        }
        lisp += self.parameters.lispify();
        if let Some(r#return) = &self.r#return {
            lisp += r#return.lispify();
        }
        // lisp += self.body.lispify();
        lisp
    }
}

impl Debug for FunctionReturnNode {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        if self.is_empty() {
            f.debug_struct("Auto").finish()
        }
        else {
            let w = &mut f.debug_struct("ReturnType");
            if let Some(s) = &self.typing {
                w.field("main", &s);
            }
            if !self.effect.is_empty() {
                w.field("effects", &self.effect);
            }
            w.finish()
        }
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for FunctionReturnNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        terms += theme.operator(":");
        terms += " ";
        terms += self.typing.pretty(theme);
        terms.into()
    }
}
#[cfg(feature = "lispify")]
impl Lispify for FunctionReturnNode {
    type Output = Lisp;

    fn lispify(&self) -> Self::Output {
        todo!()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for FunctionEffectNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        terms += theme.operator("/");
        terms += " ";
        terms += SoftBlock::brackets().join_slice(&self.effects, theme);
        terms.into()
    }
}
#[cfg(feature = "lispify")]
impl Lispify for FunctionEffectNode {
    type Output = Lisp;

    fn lispify(&self) -> Self::Output {
        todo!()
    }
}

impl Debug for StatementBlock {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        f.debug_list().entries(self.terms.iter()).finish()
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for StatementBlock {
    /// ```vk
    /// # inline style
    /// { ... }
    ///
    /// # block style
    /// {
    ///    ...
    /// }
    /// ```
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let block = SoftBlock::curly_braces();
        block.join_slice(&self.terms, theme)
    }
}
#[cfg(feature = "pretty-print")]
impl<K: PrettyPrint, V: PrettyPrint, D: PrettyPrint> PrettyPrint for ArgumentTermNode<K, V, D> {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(3);
        terms += self.key.pretty(theme);
        if let Some(value) = &self.value {
            terms += ": ";
            terms += value.pretty(theme);
        }
        if let Some(default) = &self.default {
            terms += " = ";
            terms += default.pretty(theme);
        }
        terms.into()
    }
}