1use oak_core::{SyntaxKind, Token};
2use serde::{Deserialize, Serialize};
3
4pub type ElixirToken = Token<ElixirSyntaxKind>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum ElixirSyntaxKind {
9 Whitespace,
11 Newline,
13 Comment,
15 Identifier,
17 Atom,
19 Variable,
21 Number,
23 Float,
25 String,
27 Character,
29 Sigil,
31
32 After,
34 And,
36 Case,
38 Catch,
40 Cond,
42 Def,
44 Defp,
46 Defmodule,
48 Defstruct,
50 Defprotocol,
52 Defimpl,
54 Defmacro,
56 Defmacrop,
58 Do,
60 Else,
62 Elsif,
64 End,
66 False,
68 Fn,
70 If,
72 In,
74 Not,
76 Or,
78 Receive,
80 Rescue,
82 True,
84 Try,
86 Unless,
88 When,
90 With,
92
93 Plus,
95 Minus,
97 Star,
99 Slash,
101 Equal,
103 EqualEqual,
105 NotEqual,
107 EqualEqualEqual,
109 NotEqualEqual,
111 Less,
113 Greater,
115 LessEqual,
117 GreaterEqual,
119 PlusPlus,
121 MinusMinus,
123 StarStar,
125 Exclamation,
127 Question,
129 Ampersand,
131 At,
133 Caret,
135 Tilde,
137 LeftShift,
139 RightShift,
141 MatchOp,
143 PipeRight,
145
146 LeftParen, RightParen, LeftBrace, RightBrace, LeftBracket, RightBracket, Comma, Semicolon, Dot, Colon, Arrow, Pipe, PipePipe, Hash, Error,
164 Eof,
165
166 SourceFile,
168 Module,
169 Function,
170 ParameterList,
171 Parameter,
172 BlockExpression,
173 LetStatement,
174 ExpressionStatement,
175 IdentifierExpression,
176 LiteralExpression,
177 BooleanLiteral,
178 ParenthesizedExpression,
179 BinaryExpression,
180 UnaryExpression,
181 CallExpression,
182 FieldExpression,
183 IndexExpression,
184 IfExpression,
185 MatchExpression,
186 LoopExpression,
187 WhileExpression,
188 ForExpression,
189 BreakExpression,
190 ContinueExpression,
191 ReturnExpression,
192 StructExpression,
193 TupleExpression,
194 ArrayExpression,
195 RangeExpression,
196 ClosureExpression,
197 AsyncBlockExpression,
198 UnsafeBlockExpression,
199 TryExpression,
200 AwaitExpression,
201 MacroCall,
202 Path,
203 PathSegment,
204 GenericArgs,
205 TypePath,
206 TupleType,
207 ArrayType,
208 SliceType,
209 ReferenceType,
210 PointerType,
211 FunctionType,
212 TraitObjectType,
213 ImplTraitType,
214 InferredType,
215 NeverType,
216 Pattern,
217 IdentifierPattern,
218 WildcardPattern,
219 TuplePattern,
220 StructPattern,
221 TupleStructPattern,
222 SlicePattern,
223 ReferencePattern,
224 LiteralPattern,
225 RangePattern,
226 OrPattern,
227 RestPattern,
228 StructDeclaration,
229 EnumDeclaration,
230 UnionDeclaration,
231 TraitDeclaration,
232 ImplDeclaration,
233 ModuleDeclaration,
234 UseDeclaration,
235 ConstDeclaration,
236 StaticDeclaration,
237 TypeAliasDeclaration,
238 ExternBlock,
239 ExternFunction,
240 Attribute,
241 Visibility,
242 GenericParams,
243 GenericParam,
244 TypeParam,
245 ConstParam,
246 LifetimeParam,
247 WhereClause,
248 WherePredicate,
249 ReturnType,
250 FieldList,
251 Field,
252 Variant,
253 VariantList,
254 AssociatedItem,
255 TraitItem,
256 ImplItem,
257}
258
259impl SyntaxKind for ElixirSyntaxKind {
260 fn is_trivia(&self) -> bool {
261 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
262 }
263
264 fn is_comment(&self) -> bool {
265 matches!(self, Self::Comment)
266 }
267
268 fn is_whitespace(&self) -> bool {
269 matches!(self, Self::Whitespace | Self::Newline)
270 }
271
272 fn is_token_type(&self) -> bool {
273 use ElixirSyntaxKind::*;
274 !matches!(
275 self,
276 Error | Eof |
277 SourceFile | Module | Function | ParameterList | Parameter | BlockExpression |
279 LetStatement | ExpressionStatement | IdentifierExpression | LiteralExpression |
280 BooleanLiteral | ParenthesizedExpression | BinaryExpression | UnaryExpression |
281 CallExpression | FieldExpression | IndexExpression | IfExpression |
282 MatchExpression | LoopExpression | WhileExpression | ForExpression |
283 BreakExpression | ContinueExpression | ReturnExpression | StructExpression |
284 TupleExpression | ArrayExpression | RangeExpression | ClosureExpression |
285 AsyncBlockExpression | UnsafeBlockExpression | TryExpression | AwaitExpression |
286 MacroCall | Path | PathSegment | GenericArgs | TypePath | TupleType |
287 ArrayType | SliceType | ReferenceType | PointerType | FunctionType |
288 TraitObjectType | ImplTraitType | InferredType | NeverType | Pattern |
289 IdentifierPattern | WildcardPattern | TuplePattern | StructPattern |
290 TupleStructPattern | SlicePattern | ReferencePattern | LiteralPattern |
291 RangePattern | OrPattern | RestPattern | StructDeclaration | EnumDeclaration | UnionDeclaration |
292 TraitDeclaration | ImplDeclaration | ModuleDeclaration | UseDeclaration | ConstDeclaration |
293 StaticDeclaration | TypeAliasDeclaration | ExternBlock | ExternFunction |
294 Attribute | Visibility | GenericParams | GenericParam | TypeParam |
295 ConstParam | LifetimeParam | WhereClause | WherePredicate |
296 ReturnType | FieldList | Field | Variant | VariantList |
297 AssociatedItem | TraitItem | ImplItem
298 )
299 }
300
301 fn is_element_type(&self) -> bool {
302 use ElixirSyntaxKind::*;
303 matches!(
304 self,
305 Error | Eof |
306 SourceFile | Module | Function | ParameterList | Parameter | BlockExpression |
308 LetStatement | ExpressionStatement | IdentifierExpression | LiteralExpression |
309 BooleanLiteral | ParenthesizedExpression | BinaryExpression | UnaryExpression |
310 CallExpression | FieldExpression | IndexExpression | IfExpression |
311 MatchExpression | LoopExpression | WhileExpression | ForExpression |
312 BreakExpression | ContinueExpression | ReturnExpression | StructExpression |
313 TupleExpression | ArrayExpression | RangeExpression | ClosureExpression |
314 AsyncBlockExpression | UnsafeBlockExpression | TryExpression | AwaitExpression |
315 MacroCall | Path | PathSegment | GenericArgs | TypePath | TupleType |
316 ArrayType | SliceType | ReferenceType | PointerType | FunctionType |
317 TraitObjectType | ImplTraitType | InferredType | NeverType | Pattern |
318 IdentifierPattern | WildcardPattern | TuplePattern | StructPattern |
319 TupleStructPattern | SlicePattern | ReferencePattern | LiteralPattern |
320 RangePattern | OrPattern | RestPattern | StructDeclaration | EnumDeclaration | UnionDeclaration |
321 TraitDeclaration | ImplDeclaration | ModuleDeclaration | UseDeclaration | ConstDeclaration |
322 StaticDeclaration | TypeAliasDeclaration | ExternBlock | ExternFunction |
323 Attribute | Visibility | GenericParams | GenericParam | TypeParam |
324 ConstParam | LifetimeParam | WhereClause | WherePredicate |
325 ReturnType | FieldList | Field | Variant | VariantList |
326 AssociatedItem | TraitItem | ImplItem
327 )
328 }
329}
330
331impl ElixirSyntaxKind {
332 pub fn is_keyword(self) -> bool {
333 matches!(
334 self,
335 Self::After
336 | Self::And
337 | Self::Case
338 | Self::Catch
339 | Self::Cond
340 | Self::Def
341 | Self::Defp
342 | Self::Defmodule
343 | Self::Defstruct
344 | Self::Defprotocol
345 | Self::Defimpl
346 | Self::Defmacro
347 | Self::Defmacrop
348 | Self::Do
349 | Self::Else
350 | Self::Elsif
351 | Self::End
352 | Self::False
353 | Self::Fn
354 | Self::If
355 | Self::In
356 | Self::Not
357 | Self::Or
358 | Self::Receive
359 | Self::Rescue
360 | Self::True
361 | Self::Try
362 | Self::Unless
363 | Self::When
364 | Self::With
365 )
366 }
367}