oak_zig/lexer/token_type.rs
1//! Zig token types and roles.
2
3use oak_core::{Token, TokenType, UniversalTokenRole};
4
5/// A token in the Zig language.
6pub type ZigToken = Token<ZigTokenType>;
7
8impl TokenType for ZigTokenType {
9 type Role = UniversalTokenRole;
10 const END_OF_STREAM: Self = Self::Eof;
11
12 fn is_ignored(&self) -> bool {
13 matches!(self, Self::Whitespace | Self::Newline | Self::Comment | Self::DocComment)
14 }
15
16 fn role(&self) -> Self::Role {
17 match self {
18 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
19 Self::Comment | Self::DocComment => UniversalTokenRole::Comment,
20 Self::Error => UniversalTokenRole::Error,
21 Self::Eof => UniversalTokenRole::Eof,
22 _ => UniversalTokenRole::None,
23 }
24 }
25}
26
27/// Zig token types.
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
30pub enum ZigTokenType {
31 /// Root element.
32 Root,
33 /// Whitespace characters.
34 Whitespace,
35 /// Newline character.
36 Newline,
37 /// Comment.
38 Comment,
39 /// Documentation comment.
40 DocComment,
41 /// Error token.
42 Error,
43 /// End of file.
44 Eof,
45
46 /// Identifier.
47 Identifier,
48 /// String literal.
49 StringLiteral,
50 /// Character literal.
51 CharLiteral,
52 /// Integer literal.
53 IntegerLiteral,
54 /// Floating-point literal.
55 FloatLiteral,
56 /// Boolean literal.
57 BooleanLiteral,
58
59 /// `const` keyword.
60 Const,
61 /// `var` keyword.
62 Var,
63 /// `fn` keyword.
64 Fn,
65 /// `struct` keyword.
66 Struct,
67 /// `union` keyword.
68 Union,
69 /// `enum` keyword.
70 Enum,
71 /// `opaque` keyword.
72 Opaque,
73 /// `type` keyword.
74 Type,
75 /// `comptime` keyword.
76 Comptime,
77 /// `inline` keyword.
78 Inline,
79 /// `noinline` keyword.
80 NoInline,
81 /// `pub` keyword.
82 Pub,
83 /// `export` keyword.
84 Export,
85 /// `extern` keyword.
86 Extern,
87 /// `packed` keyword.
88 Packed,
89 /// `align` keyword.
90 Align,
91 /// `callconv` keyword.
92 CallConv,
93 /// `linksection` keyword.
94 LinkSection,
95
96 /// `if` keyword.
97 If,
98 /// `else` keyword.
99 Else,
100 /// `switch` keyword.
101 Switch,
102 /// `while` keyword.
103 While,
104 /// `for` keyword.
105 For,
106 /// `break` keyword.
107 Break,
108 /// `continue` keyword.
109 Continue,
110 /// `return` keyword.
111 Return,
112 /// `defer` keyword.
113 Defer,
114 /// `errdefer` keyword.
115 ErrDefer,
116 /// `unreachable` keyword.
117 Unreachable,
118 /// `noreturn` keyword.
119 NoReturn,
120
121 /// `error` keyword.
122 ErrorKeyword,
123
124 /// `test` keyword.
125 Test,
126 /// `async` keyword.
127 Async,
128 /// `await` keyword.
129 Await,
130 /// `suspend` keyword.
131 Suspend,
132 /// `resume` keyword.
133 Resume,
134 /// `cancel` keyword.
135 Cancel,
136
137 /// `undefined` keyword.
138 Undefined,
139 /// `null` keyword.
140 Null,
141 /// `volatile` keyword.
142 Volatile,
143 /// `allowzero` keyword.
144 AllowZero,
145 /// `noalias` keyword.
146 NoAlias,
147
148 /// `and` keyword.
149 And,
150 /// `or` keyword.
151 Or,
152 /// `anyframe` keyword.
153 AnyFrame,
154 /// `anytype` keyword.
155 AnyType,
156 /// `threadlocal` keyword.
157 ThreadLocal,
158
159 /// `bool` type.
160 Bool,
161 /// `i8` type.
162 I8,
163 /// `i16` type.
164 I16,
165 /// `i32` type.
166 I32,
167 /// `i64` type.
168 I64,
169 /// `i128` type.
170 I128,
171 /// `isize` type.
172 Isize,
173 /// `u8` type.
174 U8,
175 /// `u16` type.
176 U16,
177 /// `u32` type.
178 U32,
179 /// `u64` type.
180 U64,
181 /// `u128` type.
182 U128,
183 /// `usize` type.
184 Usize,
185 /// `f16` type.
186 F16,
187 /// `f32` type.
188 F32,
189 /// `f64` type.
190 F64,
191 /// `f80` type.
192 F80,
193 /// `f128` type.
194 F128,
195 /// `c_short` type.
196 CShort,
197 /// `c_ushort` type.
198 CUshort,
199 /// `c_int` type.
200 CInt,
201 /// `c_uint` type.
202 CUint,
203 /// `c_long` type.
204 CLong,
205 /// `c_ulong` type.
206 CUlong,
207 /// `c_longlong` type.
208 CLongLong,
209 /// `c_ulonglong` type.
210 CUlongLong,
211 /// `c_longdouble` type.
212 CLongDouble,
213 /// `c_void` type.
214 CVoid,
215 /// `void` type.
216 Void,
217 /// `comptime_int` type.
218 ComptimeInt,
219 /// `comptime_float` type.
220 ComptimeFloat,
221
222 /// `+` operator.
223 Plus,
224 /// `-` operator.
225 Minus,
226 /// `*` operator.
227 Star,
228 /// `/` operator.
229 Slash,
230 /// `%` operator.
231 Percent,
232 /// `**` operator.
233 StarStar,
234 /// `+%` operator.
235 PlusPercent,
236 /// `-%` operator.
237 MinusPercent,
238 /// `*%` operator.
239 StarPercent,
240 /// `++` operator.
241 PlusPlus,
242 /// `--` operator.
243 MinusMinus,
244
245 /// `&` operator.
246 Ampersand,
247 /// `|` operator.
248 Pipe,
249 /// `^` operator.
250 Caret,
251 /// `~` operator.
252 Tilde,
253 /// `<<` operator.
254 LessLess,
255 /// `>>` operator.
256 GreaterGreater,
257
258 /// `==` operator.
259 Equal,
260 /// `!=` operator.
261 NotEqual,
262 /// `<` operator.
263 Less,
264 /// `>` operator.
265 Greater,
266 /// `<=` operator.
267 LessEqual,
268 /// `>=` operator.
269 GreaterEqual,
270
271 /// `and` logical operator.
272 AndAnd,
273 /// `or` logical operator.
274 OrOr,
275
276 /// `=` operator.
277 Assign,
278 /// `+=` operator.
279 PlusAssign,
280 /// `-=` operator.
281 MinusAssign,
282 /// `*=` operator.
283 StarAssign,
284 /// `/=` operator.
285 SlashAssign,
286 /// `%=` operator.
287 PercentAssign,
288 /// `&=` operator.
289 AmpersandAssign,
290 /// `|=` operator.
291 PipeAssign,
292 /// `^=` operator.
293 CaretAssign,
294 /// `<<=` operator.
295 LessLessAssign,
296 /// `>>=` operator.
297 GreaterGreaterAssign,
298
299 /// `(` symbol.
300 LeftParen,
301 /// `)` symbol.
302 RightParen,
303 /// `{` symbol.
304 LeftBrace,
305 /// `}` symbol.
306 RightBrace,
307 /// `[` symbol.
308 LeftBracket,
309 /// `]` symbol.
310 RightBracket,
311 /// `;` symbol.
312 Semicolon,
313 /// `,` symbol.
314 Comma,
315 /// `.` symbol.
316 Dot,
317 /// `..` symbol.
318 DotDot,
319 /// `...` symbol.
320 DotDotDot,
321 /// `.?` operator.
322 DotQuestion,
323 /// `.*` operator.
324 DotStar,
325 /// `:` symbol.
326 Colon,
327 /// `?` symbol.
328 Question,
329 /// `!` symbol.
330 Exclamation,
331 /// `->` operator.
332 Arrow,
333 /// `=>` operator.
334 FatArrow,
335
336 /// `orelse` operator.
337 OrElse,
338 /// `catch` operator.
339 CatchKeyword,
340 /// `try` operator.
341 TryKeyword,
342 /// `await` operator.
343 AwaitKeyword,
344
345 /// `@` symbol.
346 At,
347 /// Built-in identifier.
348 BuiltinIdentifier,
349
350 /// Start of a string literal.
351 StringStart,
352 /// End of a string literal.
353 StringEnd,
354 /// Content of a string literal.
355 StringContent,
356 /// Start of string interpolation.
357 InterpolationStart,
358 /// End of string interpolation.
359 InterpolationEnd,
360
361 /// Start of a multiline string.
362 MultilineStringStart,
363 /// End of a multiline string.
364 MultilineStringEnd,
365 /// Content of a multiline string.
366 MultilineStringContent,
367
368 /// Compile-time directive.
369 CompileDirective,
370
371 /// Text content.
372 Text,
373
374 /// Variable declaration non-terminal.
375 VarDeclaration,
376 /// Function declaration non-terminal.
377 FnDeclaration,
378 /// Struct declaration non-terminal.
379 StructDeclaration,
380 /// Enum declaration non-terminal.
381 EnumDeclaration,
382 /// Union declaration non-terminal.
383 UnionDeclaration,
384 /// Block non-terminal.
385 Block,
386 /// If statement non-terminal.
387 IfStatement,
388 /// While statement non-terminal.
389 WhileStatement,
390 /// For statement non-terminal.
391 ForStatement,
392 /// Return statement non-terminal.
393 ReturnStatement,
394}