use oak_core::{Token, TokenType, UniversalTokenRole};
pub type SwiftToken = Token<SwiftTokenType>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
pub enum SwiftTokenType {
Whitespace,
Newline,
Comment,
Identifier,
Error,
Eof,
NumberLiteral,
StringLiteral,
CharLiteral,
BooleanLiteral,
Class,
Struct,
Enum,
Protocol,
Extension,
Func,
Var,
Let,
Init,
Deinit,
Subscript,
Typealias,
Import,
If,
Else,
Switch,
Case,
Default,
For,
While,
Repeat,
Do,
Break,
Continue,
Fallthrough,
Return,
Throw,
Try,
Catch,
Finally,
Guard,
Defer,
Public,
Private,
Internal,
Fileprivate,
Open,
Static,
Final,
Override,
Mutating,
Nonmutating,
Lazy,
Weak,
Unowned,
Optional,
Required,
Convenience,
Dynamic,
Infix,
Prefix,
Postfix,
Any,
AnyObject,
Self_,
Type,
Protocol_,
True,
False,
Nil,
As,
Is,
In,
Where,
Associatedtype,
Operator,
Precedencegroup,
Indirect,
Rethrows,
Throws,
Inout,
Plus,
Minus,
Star,
Slash,
Percent,
Equal,
NotEqual,
Less,
Greater,
LessEqual,
GreaterEqual,
LogicalAnd,
LogicalOr,
LogicalNot,
BitAnd,
BitOr,
BitXor,
BitNot,
LeftShift,
RightShift,
Assign,
PlusAssign,
MinusAssign,
StarAssign,
SlashAssign,
PercentAssign,
AndAssign,
OrAssign,
XorAssign,
LeftShiftAssign,
RightShiftAssign,
Question,
QuestionQuestion,
Dot,
Arrow,
Range,
ClosedRange,
LeftParen,
RightParen,
LeftBracket,
RightBracket,
LeftBrace,
RightBrace,
Comma,
Semicolon,
Colon,
At,
Hash,
Dollar,
Underscore,
Backslash,
SourceFile,
FunctionDeclaration,
Parameter,
ParameterList,
VariableDeclaration,
ClassDeclaration,
StructDeclaration,
EnumDeclaration,
ProtocolDeclaration,
IfStatement,
WhileStatement,
ForStatement,
ReturnStatement,
BreakStatement,
ContinueStatement,
ExpressionStatement,
Block,
BinaryExpression,
UnaryExpression,
CallExpression,
MemberExpression,
IdentifierExpression,
LiteralExpression,
}
impl SwiftTokenType {
pub fn is_trivia(&self) -> bool {
matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
}
}
impl TokenType for SwiftTokenType {
type Role = UniversalTokenRole;
const END_OF_STREAM: Self = Self::Eof;
fn is_ignored(&self) -> bool {
matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
}
fn role(&self) -> Self::Role {
match self {
Self::Whitespace => UniversalTokenRole::Whitespace,
Self::Newline => UniversalTokenRole::Whitespace,
Self::Comment => UniversalTokenRole::Comment,
Self::Eof => UniversalTokenRole::Eof,
Self::Error => UniversalTokenRole::Error,
_ => UniversalTokenRole::None,
}
}
}