1use oak_core::UniversalTokenRole;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum AplTokenType {
7 Whitespace,
9 Newline,
11 Comment,
13
14 StringLiteral,
16 NumberLiteral,
18 Identifier,
20
21 LeftArrow,
24 RightArrow,
26 Diamond,
28 Quad,
30 QuoteQuad,
32 Rho,
34 Iota,
36 Epsilon,
38 UpArrow,
40 DownArrow,
42 Del,
44 Delta,
46 Alpha,
48 Omega,
50 Zilde,
52
53 Plus,
56 Minus,
58 Times,
60 Divide,
62 Star,
64 Log,
66 Circle,
68 Or,
70 And,
72 Not,
74 Nor,
76 Nand,
78 Equal,
80 NotEqual,
82 LessThan,
84 LessEqual,
86 GreaterEqual,
88 GreaterThan,
90 UpStile,
92 DownStile,
94 Bar,
96 Tilde,
98 Question,
100 Factorial,
102
103 Slash,
106 Backslash,
108 SlashBar,
110 BackslashBar,
112 Dot,
114 Jot,
116 Diaeresis,
118 Power,
120 Rank,
122 Tally,
124
125 LeftParen,
128 RightParen,
130 LeftBracket,
132 RightBracket,
134 LeftBrace,
136 RightBrace,
138 Semicolon,
140
141 Eof,
143 Error,
145}
146
147impl AplTokenType {
148 pub fn is_identifier(&self) -> bool {
150 matches!(self, Self::Identifier | Self::Alpha | Self::Omega)
151 }
152
153 pub fn is_literal(&self) -> bool {
155 matches!(self, Self::StringLiteral | Self::NumberLiteral | Self::Zilde)
156 }
157}
158
159pub type TokenType = AplTokenType;
161
162impl oak_core::TokenType for AplTokenType {
163 type Role = UniversalTokenRole;
164 const END_OF_STREAM: Self = Self::Eof;
165
166 fn is_comment(&self) -> bool {
167 matches!(self, Self::Comment)
168 }
169
170 fn is_whitespace(&self) -> bool {
171 matches!(self, Self::Whitespace | Self::Newline)
172 }
173
174 fn is_error(&self) -> bool {
175 matches!(self, Self::Error)
176 }
177
178 fn role(&self) -> Self::Role {
179 use UniversalTokenRole::*;
180 match self {
181 Self::Identifier | Self::Alpha | Self::Omega => Name,
182 Self::StringLiteral | Self::NumberLiteral | Self::Zilde => Literal,
183 Self::Comment => Comment,
184 Self::Whitespace | Self::Newline => Whitespace,
185 Self::Error => Error,
186 Self::Eof => Eof,
187
188 Self::LeftArrow
190 | Self::RightArrow
191 | Self::Plus
192 | Self::Minus
193 | Self::Times
194 | Self::Divide
195 | Self::Star
196 | Self::Log
197 | Self::Circle
198 | Self::Or
199 | Self::And
200 | Self::Not
201 | Self::Nor
202 | Self::Nand
203 | Self::Equal
204 | Self::NotEqual
205 | Self::LessThan
206 | Self::LessEqual
207 | Self::GreaterEqual
208 | Self::GreaterThan
209 | Self::UpStile
210 | Self::DownStile
211 | Self::Bar
212 | Self::Tilde
213 | Self::Question
214 | Self::Factorial
215 | Self::Slash
216 | Self::Backslash
217 | Self::SlashBar
218 | Self::BackslashBar
219 | Self::Dot
220 | Self::Jot
221 | Self::Diaeresis
222 | Self::Power
223 | Self::Rank
224 | Self::Tally
225 | Self::Rho
226 | Self::Iota
227 | Self::Epsilon
228 | Self::UpArrow
229 | Self::DownArrow => Operator,
230
231 Self::Diamond | Self::Quad | Self::QuoteQuad | Self::Del | Self::Delta | Self::LeftParen | Self::RightParen | Self::LeftBracket | Self::RightBracket | Self::LeftBrace | Self::RightBrace | Self::Semicolon => Punctuation,
232 }
233 }
234}