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