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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use super::*;

#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternGuard {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.keyword("when").append(" ").append(self.condition.pretty(theme))
    }
}
impl Debug for PatternsList {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        f.debug_list().entries(self.branches.iter()).finish()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternsList {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(10);
        terms += "{";
        terms += PrettyTree::Hardline;
        let mut inner = PrettySequence::new(10);
        let len = self.branches.len();
        for (idx, branch) in self.branches.iter().enumerate() {
            inner += branch.pretty(theme);
            if idx == len.saturating_sub(1) {
            }
            else {
                inner += PrettyTree::Hardline;
            }
        }
        terms += inner.indent(4);
        terms += PrettyTree::Hardline;
        terms += "}";
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternBranch {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.concat(vec![self.condition.pretty(theme), self.continuation.pretty(theme)])
    }
}
#[cfg(feature = "pretty-print")]

impl PrettyPrint for PatternCondition {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let item = match self {
            Self::Case(v) => v.pretty(theme),
            Self::When(v) => v.pretty(theme),
            Self::Type(v) => v.pretty(theme),
            Self::Else(v) => v.pretty(theme),
        };
        item.append(":").append(PrettyTree::Hardline)
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternStatements {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(self.terms.len() * 2);
        let len = self.terms.len();
        for (idx, term) in self.terms.iter().enumerate() {
            terms += term.pretty(theme);
            if idx == len.saturating_sub(1) {
                terms += ",";
            }
        }
        terms.indent(4)
    }
}

impl Debug for PatternNode {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Symbol(v) => Debug::fmt(v, f),
            Self::Tuple(v) => Debug::fmt(v, f),
            Self::Class(v) => Debug::fmt(v, f),
            Self::Union(v) => Debug::fmt(v, f),
            Self::Array(v) => Debug::fmt(v, f),
            Self::Atom(v) => Debug::fmt(v, f),
        }
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        match self {
            Self::Symbol(v) => v.pretty(theme),
            Self::Tuple(v) => v.pretty(theme),
            Self::Class(v) => v.pretty(theme),
            Self::Array(v) => v.pretty(theme),
            Self::Union(v) => v.pretty(theme),
            Self::Atom(v) => v.pretty(theme),
        }
    }
}
#[cfg(feature = "pretty-print")]

impl PrettyPrint for TuplePatternNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        if let Some(bind) = &self.bind {
            terms += bind.pretty(theme);
            terms += "<-";
        }
        if let Some(name) = &self.name {
            terms += name.pretty(theme);
        }
        let block = SoftBlock::parentheses().with_joint(PrettyTree::line_or_comma());
        terms += block.join_slice(&self.terms, theme);
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]

impl PrettyPrint for ClassPatternNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        if let Some(bind) = &self.bind {
            terms += bind.pretty(theme);
            terms += "<-";
        }
        if let Some(name) = &self.name {
            terms += name.pretty(theme);
        }
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for ArrayPatternNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        if let Some(bind) = &self.bind {
            terms += bind.pretty(theme);
            terms += "<-";
        }
        // if let Some(name) = &self.name {
        //     terms += name.pretty(theme);
        // }
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for UnionPatternNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(4);
        if let Some(bind) = &self.bind {
            terms += bind.pretty(theme);
            terms += "<-";
        }
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for ImplicitCaseNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(10);
        terms += self.pattern.pretty(theme);
        terms += theme.keyword("≔");
        terms += self.body.pretty(theme);
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternCaseNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(5);
        terms += theme.keyword("case");
        terms += " ";
        terms += self.pattern.pretty(theme);
        if let Some(guard) = &self.guard {
            terms += theme.keyword("when");
            terms += guard.pretty(theme);
        }
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for IdentifierPattern {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        let mut terms = PrettySequence::new(10);
        terms += self.modifiers.pretty(theme);
        terms += self.identifier.pretty(theme);
        terms.into()
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternWhenNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.concat(vec![theme.keyword("when"), " ".into(), self.guard.pretty(theme)])
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternTypeNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.concat(vec![theme.keyword("type"), " ".into(), self.typing.pretty(theme)])
    }
}
#[cfg(feature = "pretty-print")]
impl PrettyPrint for PatternElseNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        theme.keyword("else")
    }
}