oak_lean/lexer/token_type.rs
1use oak_core::{Source, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5impl TokenType for LeanTokenType {
6 type Role = UniversalTokenRole;
7 const END_OF_STREAM: Self = Self::Error;
8
9 fn is_ignored(&self) -> bool {
10 false
11 }
12
13 fn role(&self) -> Self::Role {
14 match self {
15 _ => UniversalTokenRole::None,
16 }
17 }
18}
19
20pub type LeanToken = Token<LeanTokenType>;
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
23#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24/// Token types for the Lean language.
25pub enum LeanTokenType {
26 // Node kinds
27 /// Root node.
28 Root,
29 /// End of stream.
30 Eof,
31
32 // Keywords
33 /// `axiom` keyword.
34 Axiom,
35 /// `constant` keyword.
36 Constant,
37 /// `def` keyword.
38 Def,
39 /// `example` keyword.
40 Example,
41 /// `inductive` keyword.
42 Inductive,
43 /// `lemma` keyword.
44 Lemma,
45 /// `namespace` keyword.
46 Namespace,
47 /// `open` keyword.
48 Open,
49 /// `private` keyword.
50 Private,
51 /// `protected` keyword.
52 Protected,
53 /// `section` keyword.
54 Section,
55 /// `structure` keyword.
56 Structure,
57 /// `theorem` keyword.
58 Theorem,
59 /// `universe` keyword.
60 Universe,
61 /// `variable` keyword.
62 Variable,
63 /// `variables` keyword.
64 Variables,
65 /// `end` keyword.
66 End,
67 /// `import` keyword.
68 Import,
69 /// `export` keyword.
70 Export,
71 /// `prelude` keyword.
72 Prelude,
73 /// `noncomputable` keyword.
74 Noncomputable,
75 /// `partial` keyword.
76 Partial,
77 /// `unsafe` keyword.
78 Unsafe,
79 /// `mutual` keyword.
80 Mutual,
81 /// `where` keyword.
82 Where,
83 /// `have` keyword.
84 Have,
85 /// `show` keyword.
86 Show,
87 /// `suffices` keyword.
88 Suffices,
89 /// `let` keyword.
90 Let,
91 /// `in` keyword.
92 In,
93 /// `if` keyword.
94 If,
95 /// `then` keyword.
96 Then,
97 /// `else` keyword.
98 Else,
99 /// `match` keyword.
100 Match,
101 /// `with` keyword.
102 With,
103 /// `fun` keyword.
104 Fun,
105 /// `do` keyword.
106 Do,
107 /// `for` keyword.
108 For,
109 /// `while` keyword.
110 While,
111 /// `break` keyword.
112 Break,
113 /// `continue` keyword.
114 Continue,
115 /// `return` keyword.
116 Return,
117 /// `try` keyword.
118 Try,
119 /// `catch` keyword.
120 Catch,
121 /// `finally` keyword.
122 Finally,
123 /// `throw` keyword.
124 Throw,
125
126 // Identifiers and literals
127 /// Identifier.
128 Identifier,
129 /// Integer literal.
130 IntegerLiteral,
131 /// Floating point literal.
132 FloatLiteral,
133 /// String literal.
134 StringLiteral,
135 /// Character literal.
136 CharLiteral,
137
138 // Operators
139 /// Plus operator `+`.
140 Plus,
141 /// Minus operator `-`.
142 Minus,
143 /// Multiplication operator `*`.
144 Star,
145 /// Division operator `/`.
146 Slash,
147 /// Modulo operator `%`.
148 Percent,
149 /// Exponentiation operator `^`.
150 Caret,
151 /// Hash sign `#`.
152 Hash,
153 /// Bitwise AND operator `&`.
154 Ampersand,
155 /// Bitwise OR operator `|`.
156 Pipe,
157 /// Bitwise NOT operator `~`.
158 Tilde,
159 /// Logical NOT operator `!`.
160 Bang,
161 /// Question mark `?`.
162 Question,
163 /// At sign `@`.
164 At,
165 /// Dollar sign `$`.
166 Dollar,
167 /// Arrow `->`.
168 Arrow,
169 /// Fat arrow `=>`.
170 FatArrow,
171 /// Equality operator `=`.
172 Eq,
173 /// Inequality operator `!=`.
174 Ne,
175 /// Less than operator `<`.
176 Lt,
177 /// Less than or equal operator `<=`.
178 Le,
179 /// Greater than operator `>`.
180 Gt,
181 /// Greater than or equal operator `>=`.
182 Ge,
183 /// Logical AND operator `&&`.
184 And,
185 /// Logical OR operator `||`.
186 Or,
187 /// `not` operator.
188 Not,
189 /// Append operator `++`.
190 Append,
191 /// Cons operator `::`.
192 Cons,
193
194 // Delimiters
195 /// Left parenthesis `(`.
196 LeftParen,
197 /// Right parenthesis `)`.
198 RightParen,
199 /// Left brace `{`.
200 LeftBrace,
201 /// Right brace `}`.
202 RightBrace,
203 /// Left bracket `[`.
204 LeftBracket,
205 /// Right bracket `]`.
206 RightBracket,
207 /// Left angle bracket `⟨`.
208 LeftAngle,
209 /// Right angle bracket `⟩`.
210 RightAngle,
211 /// Semicolon `;`.
212 Semicolon,
213 /// Colon `:`.
214 Colon,
215 /// Comma `,`.
216 Comma,
217 /// Dot `.`.
218 Dot,
219 /// Double dot `..`.
220 DotDot,
221 /// Assignment operator `:=`.
222 ColonEq,
223 /// Double colon `::`.
224 ColonColon,
225
226 // Whitespace and comments
227 /// Whitespace.
228 Whitespace,
229 /// Newline.
230 Newline,
231 /// Comment.
232 Comment,
233
234 // Special markers
235 /// Error token.
236 Error,
237
238 // Syntax node types (Non-terminals)
239 /// Source file.
240 SourceFile,
241 /// Function declaration.
242 Function,
243 /// Parameter list.
244 ParameterList,
245 /// Parameter.
246 Parameter,
247 /// Block expression.
248 BlockExpression,
249 /// Let statement.
250 LetStatement,
251 /// Expression statement.
252 ExpressionStatement,
253 /// Identifier expression.
254 IdentifierExpression,
255 /// Literal expression.
256 LiteralExpression,
257 /// Boolean literal.
258 BooleanLiteral,
259 /// Parenthesized expression.
260 ParenthesizedExpression,
261 /// Binary expression.
262 BinaryExpression,
263 /// Unary expression.
264 UnaryExpression,
265 /// Call expression.
266 CallExpression,
267 /// Field access expression.
268 FieldExpression,
269 /// Index access expression.
270 IndexExpression,
271 /// If expression.
272 IfExpression,
273 /// Match expression.
274 MatchExpression,
275 /// Loop expression.
276 LoopExpression,
277 /// While loop expression.
278 WhileExpression,
279 /// For loop expression.
280 ForExpression,
281 /// Break expression.
282 BreakExpression,
283 /// Continue expression.
284 ContinueExpression,
285 /// Return expression.
286 ReturnExpression,
287 /// Struct literal expression.
288 StructExpression,
289 /// Tuple literal expression.
290 TupleExpression,
291 /// Array literal expression.
292 ArrayExpression,
293 /// Range expression.
294 RangeExpression,
295 /// Closure expression.
296 ClosureExpression,
297 /// Async block expression.
298 AsyncBlockExpression,
299 /// Unsafe block expression.
300 UnsafeBlockExpression,
301 /// Try expression.
302 TryExpression,
303 /// Await expression.
304 AwaitExpression,
305 /// Macro call.
306 MacroCall,
307 /// Path.
308 Path,
309 /// Path segment.
310 PathSegment,
311 /// Generic arguments.
312 GenericArgs,
313 /// Type path.
314 TypePath,
315 /// Tuple type.
316 TupleType,
317 /// Array type.
318 ArrayType,
319 /// Slice type.
320 SliceType,
321 /// Reference type.
322 ReferenceType,
323 /// Pointer type.
324 PointerType,
325 /// Function type.
326 FunctionType,
327 /// Trait object type.
328 TraitObjectType,
329 /// Impl trait type.
330 ImplTraitType,
331 /// Inferred type `_`.
332 InferredType,
333 /// Never type `!`.
334 NeverType,
335 /// Pattern.
336 Pattern,
337 /// Identifier pattern.
338 IdentifierPattern,
339 /// Wildcard pattern `_`.
340 WildcardPattern,
341 /// Tuple pattern.
342 TuplePattern,
343 /// Struct pattern.
344 StructPattern,
345 /// Tuple struct pattern.
346 TupleStructPattern,
347 /// Slice pattern.
348 SlicePattern,
349 /// Reference pattern.
350 ReferencePattern,
351 /// Literal pattern.
352 LiteralPattern,
353 /// Range pattern.
354 RangePattern,
355 /// Or pattern.
356 OrPattern,
357 /// Rest pattern `..`.
358 RestPattern,
359 /// Struct declaration.
360 StructDeclaration,
361 /// Enum declaration.
362 EnumDeclaration,
363 /// Union declaration.
364 UnionDeclaration,
365 /// Trait declaration.
366 TraitDeclaration,
367 /// Impl block declaration.
368 ImplDeclaration,
369 /// Module declaration.
370 ModuleDeclaration,
371 /// Use declaration.
372 UseDeclaration,
373 /// Const declaration.
374 ConstDeclaration,
375 /// Static declaration.
376 StaticDeclaration,
377 /// Type alias declaration.
378 TypeAliasDeclaration,
379 /// Extern block.
380 ExternBlock,
381 /// Extern function.
382 ExternFunction,
383 /// Attribute.
384 Attribute,
385 /// Visibility modifier.
386 Visibility,
387 /// Generic parameters.
388 GenericParams,
389 /// Generic parameter.
390 GenericParam,
391 /// Type parameter.
392 TypeParam,
393 /// Const parameter.
394 ConstParam,
395 /// Lifetime parameter.
396 LifetimeParam,
397 /// Where clause.
398 WhereClause,
399 /// Where predicate.
400 WherePredicate,
401 /// Return type specification.
402 ReturnType,
403 /// Field list.
404 FieldList,
405 /// Field declaration.
406 Field,
407 /// Enum variant.
408 Variant,
409 /// Variant list.
410 VariantList,
411 /// Associated item.
412 AssociatedItem,
413 /// Trait item.
414 TraitItem,
415 /// Impl item.
416 ImplItem,
417}