1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u8)]
7pub enum SwiftElementType {
8 Whitespace,
10 Newline,
12 Comment,
14 Identifier,
16 Error,
18 Eof,
20 NumberLiteral,
22 StringLiteral,
24 CharLiteral,
26 BooleanLiteral,
28
29 Class,
31 Struct,
33 Enum,
35 Protocol,
37 Extension,
39 Func,
41 Var,
43 Let,
45 Init,
47 Deinit,
49 Subscript,
51 Typealias,
53 Import,
55 If,
57 Else,
59 Switch,
61 Case,
63 Default,
65 For,
67 While,
69 Repeat,
71 Do,
73 Break,
75 Continue,
77 Fallthrough,
79 Return,
81 Throw,
83 Try,
85 Catch,
87 Finally,
89 Guard,
91 Defer,
93 Public,
95 Private,
97 Internal,
99 Fileprivate,
101 Open,
103 Static,
105 Final,
107 Override,
109 Mutating,
111 Nonmutating,
113 Lazy,
115 Weak,
117 Unowned,
119 Optional,
121 Required,
123 Convenience,
125 Dynamic,
127 Infix,
129 Prefix,
131 Postfix,
133 Any,
135 AnyObject,
137 Self_,
139 Type,
141 Protocol_,
143 True,
145 False,
147 Nil,
149 As,
151 Is,
153 In,
155 Where,
157 Associatedtype,
159 Operator,
161 Precedencegroup,
163 Indirect,
165 Rethrows,
167 Throws,
169 Inout,
171
172 Plus,
174 Minus,
176 Star,
178 Slash,
180 Percent,
182 Equal,
184 NotEqual,
186 Less,
188 Greater,
190 LessEqual,
192 GreaterEqual,
194 LogicalAnd,
196 LogicalOr,
198 LogicalNot,
200 BitAnd,
202 BitOr,
204 BitXor,
206 BitNot,
208 LeftShift,
210 RightShift,
212 Assign,
214 PlusAssign,
216 MinusAssign,
218 StarAssign,
220 SlashAssign,
222 PercentAssign,
224 AndAssign,
226 OrAssign,
228 XorAssign,
230 LeftShiftAssign,
232 RightShiftAssign,
234
235 Question,
237 QuestionQuestion,
239 Dot,
241 Arrow,
243 Range,
245 ClosedRange,
247 LeftParen,
249 RightParen,
251 LeftBracket,
253 RightBracket,
255 LeftBrace,
257 RightBrace,
259 Comma,
261 Semicolon,
263 Colon,
265 At,
267 Hash,
269 Dollar,
271 Underscore,
273 Backslash,
275
276 SourceFile,
278 FunctionDeclaration,
280 Parameter,
282 ParameterList,
284 VariableDeclaration,
286 ClassDeclaration,
288 StructDeclaration,
290 EnumDeclaration,
292 ProtocolDeclaration,
294 IfStatement,
296 WhileStatement,
298 ForStatement,
300 ReturnStatement,
302 BreakStatement,
304 ContinueStatement,
306 ExpressionStatement,
308 Block,
310 BinaryExpression,
312 UnaryExpression,
314 CallExpression,
316 MemberExpression,
318 IdentifierExpression,
320 LiteralExpression,
322}
323
324impl SwiftElementType {
325 pub fn is_trivia(&self) -> bool {
327 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
328 }
329}
330
331impl ElementType for SwiftElementType {
332 type Role = UniversalElementRole;
333
334 fn role(&self) -> Self::Role {
335 match self {
336 Self::SourceFile => UniversalElementRole::Root,
337 Self::Error => UniversalElementRole::Error,
338 _ => UniversalElementRole::None,
339 }
340 }
341}
342
343impl From<crate::lexer::token_type::SwiftTokenType> for SwiftElementType {
344 fn from(token: crate::lexer::token_type::SwiftTokenType) -> Self {
345 use crate::lexer::token_type::SwiftTokenType as T;
346 match token {
347 T::Whitespace => Self::Whitespace,
348 T::Newline => Self::Newline,
349 T::Comment => Self::Comment,
350 T::Identifier => Self::Identifier,
351 T::Error => Self::Error,
352 T::Eof => Self::Eof,
353 T::NumberLiteral => Self::NumberLiteral,
354 T::StringLiteral => Self::StringLiteral,
355 T::CharLiteral => Self::CharLiteral,
356 T::BooleanLiteral => Self::BooleanLiteral,
357 T::Class => Self::Class,
358 T::Struct => Self::Struct,
359 T::Enum => Self::Enum,
360 T::Protocol => Self::Protocol,
361 T::Extension => Self::Extension,
362 T::Func => Self::Func,
363 T::Var => Self::Var,
364 T::Let => Self::Let,
365 T::Init => Self::Init,
366 T::Deinit => Self::Deinit,
367 T::Subscript => Self::Subscript,
368 T::Typealias => Self::Typealias,
369 T::Import => Self::Import,
370 T::If => Self::If,
371 T::Else => Self::Else,
372 T::Switch => Self::Switch,
373 T::Case => Self::Case,
374 T::Default => Self::Default,
375 T::For => Self::For,
376 T::While => Self::While,
377 T::Repeat => Self::Repeat,
378 T::Do => Self::Do,
379 T::Break => Self::Break,
380 T::Continue => Self::Continue,
381 T::Fallthrough => Self::Fallthrough,
382 T::Return => Self::Return,
383 T::Throw => Self::Throw,
384 T::Try => Self::Try,
385 T::Catch => Self::Catch,
386 T::Finally => Self::Finally,
387 T::Guard => Self::Guard,
388 T::Defer => Self::Defer,
389 T::Public => Self::Public,
390 T::Private => Self::Private,
391 T::Internal => Self::Internal,
392 T::Fileprivate => Self::Fileprivate,
393 T::Open => Self::Open,
394 T::Static => Self::Static,
395 T::Final => Self::Final,
396 T::Override => Self::Override,
397 T::Mutating => Self::Mutating,
398 T::Nonmutating => Self::Nonmutating,
399 T::Lazy => Self::Lazy,
400 T::Weak => Self::Weak,
401 T::Unowned => Self::Unowned,
402 T::Optional => Self::Optional,
403 T::Required => Self::Required,
404 T::Convenience => Self::Convenience,
405 T::Dynamic => Self::Dynamic,
406 T::Infix => Self::Infix,
407 T::Prefix => Self::Prefix,
408 T::Postfix => Self::Postfix,
409 T::Any => Self::Any,
410 T::AnyObject => Self::AnyObject,
411 T::Self_ => Self::Self_,
412 T::Type => Self::Type,
413 T::Protocol_ => Self::Protocol_,
414 T::True => Self::True,
415 T::False => Self::False,
416 T::Nil => Self::Nil,
417 T::As => Self::As,
418 T::Is => Self::Is,
419 T::In => Self::In,
420 T::Where => Self::Where,
421 T::Associatedtype => Self::Associatedtype,
422 T::Operator => Self::Operator,
423 T::Precedencegroup => Self::Precedencegroup,
424 T::Indirect => Self::Indirect,
425 T::Rethrows => Self::Rethrows,
426 T::Throws => Self::Throws,
427 T::Inout => Self::Inout,
428 T::Plus => Self::Plus,
429 T::Minus => Self::Minus,
430 T::Star => Self::Star,
431 T::Slash => Self::Slash,
432 T::Percent => Self::Percent,
433 T::Equal => Self::Equal,
434 T::NotEqual => Self::NotEqual,
435 T::Less => Self::Less,
436 T::Greater => Self::Greater,
437 T::LessEqual => Self::LessEqual,
438 T::GreaterEqual => Self::GreaterEqual,
439 T::LogicalAnd => Self::LogicalAnd,
440 T::LogicalOr => Self::LogicalOr,
441 T::LogicalNot => Self::LogicalNot,
442 T::BitAnd => Self::BitAnd,
443 T::BitOr => Self::BitOr,
444 T::BitXor => Self::BitXor,
445 T::BitNot => Self::BitNot,
446 T::LeftShift => Self::LeftShift,
447 T::RightShift => Self::RightShift,
448 T::Assign => Self::Assign,
449 T::PlusAssign => Self::PlusAssign,
450 T::MinusAssign => Self::MinusAssign,
451 T::StarAssign => Self::StarAssign,
452 T::SlashAssign => Self::SlashAssign,
453 T::PercentAssign => Self::PercentAssign,
454 T::AndAssign => Self::AndAssign,
455 T::OrAssign => Self::OrAssign,
456 T::XorAssign => Self::XorAssign,
457 T::LeftShiftAssign => Self::LeftShiftAssign,
458 T::RightShiftAssign => Self::RightShiftAssign,
459 T::Question => Self::Question,
460 T::QuestionQuestion => Self::QuestionQuestion,
461 T::Dot => Self::Dot,
462 T::Arrow => Self::Arrow,
463 T::Range => Self::Range,
464 T::ClosedRange => Self::ClosedRange,
465 T::LeftParen => Self::LeftParen,
466 T::RightParen => Self::RightParen,
467 T::LeftBracket => Self::LeftBracket,
468 T::RightBracket => Self::RightBracket,
469 T::LeftBrace => Self::LeftBrace,
470 T::RightBrace => Self::RightBrace,
471 T::Comma => Self::Comma,
472 T::Semicolon => Self::Semicolon,
473 T::Colon => Self::Colon,
474 T::At => Self::At,
475 T::Hash => Self::Hash,
476 T::Dollar => Self::Dollar,
477 T::Underscore => Self::Underscore,
478 T::Backslash => Self::Backslash,
479 T::SourceFile => Self::SourceFile,
480 T::FunctionDeclaration => Self::FunctionDeclaration,
481 T::Parameter => Self::Parameter,
482 T::ParameterList => Self::ParameterList,
483 T::VariableDeclaration => Self::VariableDeclaration,
484 T::ClassDeclaration => Self::ClassDeclaration,
485 T::StructDeclaration => Self::StructDeclaration,
486 T::EnumDeclaration => Self::EnumDeclaration,
487 T::ProtocolDeclaration => Self::ProtocolDeclaration,
488 T::IfStatement => Self::IfStatement,
489 T::WhileStatement => Self::WhileStatement,
490 T::ForStatement => Self::ForStatement,
491 T::ReturnStatement => Self::ReturnStatement,
492 T::BreakStatement => Self::BreakStatement,
493 T::ContinueStatement => Self::ContinueStatement,
494 T::ExpressionStatement => Self::ExpressionStatement,
495 T::Block => Self::Block,
496 T::BinaryExpression => Self::BinaryExpression,
497 T::UnaryExpression => Self::UnaryExpression,
498 T::CallExpression => Self::CallExpression,
499 T::MemberExpression => Self::MemberExpression,
500 T::IdentifierExpression => Self::IdentifierExpression,
501 T::LiteralExpression => Self::LiteralExpression,
502 }
503 }
504}