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

impl FunctionType {
    pub fn as_str(&self) -> &'static str {
        match self {
            FunctionType::Macro => "macro",
            FunctionType::Micro => "micro",
        }
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for FunctionType {
    fn build<'a>(&self, allocator: &'a PrettyProvider<'a>) -> PrettyTree<'a> {
        allocator.keyword(self.as_str())
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for FunctionDeclaration {
    fn build<'a>(&self, allocator: &'a PrettyProvider<'a>) -> PrettyTree<'a> {
        let mut terms = Vec::with_capacity(4);
        for m in &self.modifiers {
            terms.push(allocator.keyword(m.name.clone()));
            terms.push(allocator.space());
        }
        terms.push(allocator.keyword(self.r#type.as_str()));
        terms.push(allocator.space());
        terms.push(self.namepath.build(allocator));
        if let Some(gen) = &self.generic {
            terms.push(gen.build(allocator));
        }
        terms.push(self.arguments.build(allocator));
        if let Some(ret) = &self.r#return {
            terms.push(allocator.text(": "));
            terms.push(ret.returns.build(allocator));
        }
        terms.push(self.body.build(allocator));
        allocator.concat(terms)
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for FunctionBody {
    /// ```vk
    /// # inline style
    /// { ... }
    ///
    /// # block style
    /// {
    ///    ...
    /// }
    /// ```
    fn build<'a>(&self, allocator: &'a PrettyProvider<'a>) -> PrettyTree<'a> {
        let mut terms = Vec::with_capacity(9);
        terms.push(allocator.space());
        terms.push(allocator.text("{"));
        terms.push(allocator.hardline());
        terms.push(allocator.intersperse(&self.statements, allocator.hardline()).indent(4));
        terms.push(allocator.hardline());
        terms.push(allocator.text("}"));
        allocator.concat(terms)
    }
}
#[cfg(feature = "pretty-print")]
impl<K: PrettyPrint, V: PrettyPrint, D: PrettyPrint> PrettyPrint for ArgumentTermNode<K, V, D> {
    fn build<'a>(&self, allocator: &'a PrettyProvider<'a>) -> PrettyTree<'a> {
        let mut terms = Vec::with_capacity(3);
        terms.push(self.key.build(allocator));
        if let Some(value) = &self.value {
            terms.push(allocator.text(": "));
            terms.push(value.build(allocator));
        }
        if let Some(default) = &self.default {
            terms.push(allocator.text(" = "));
            terms.push(default.build(allocator));
        }
        allocator.concat(terms)
    }
}