use oak_core::{Token, TokenType, UniversalTokenRole};
pub type TypeScriptToken = Token<TypeScriptTokenType>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
pub enum TypeScriptTokenType {
NamedImports,
Decorator,
ArrowFunction,
PredefinedType,
Abstract,
Any,
As,
Asserts,
Async,
Await,
Boolean,
Break,
Case,
Catch,
Class,
Const,
Constructor,
Continue,
Debugger,
Declare,
Default,
Delete,
Do,
Else,
Enum,
Export,
Extends,
False,
Finally,
For,
From,
Function,
Get,
Global,
If,
Implements,
Import,
In,
Infer,
Instanceof,
Interface,
Is,
Keyof,
Let,
Namespace,
Never,
New,
Null,
Number,
Object,
Of,
Override,
Package,
Private,
Protected,
Public,
Readonly,
Require,
Return,
Set,
Static,
String,
Super,
Switch,
Symbol,
This,
Throw,
True,
Try,
Type,
Typeof,
Undefined,
Unique,
Unknown,
Var,
Void,
While,
With,
Yield,
Plus,
Minus,
Star,
Slash,
Percent,
StarStar,
Question,
DotDotDot,
Less,
Greater,
LessEqual,
GreaterEqual,
EqualEqual,
NotEqual,
EqualEqualEqual,
NotEqualEqual,
AmpersandAmpersand,
PipePipe,
Exclamation,
Ampersand,
Pipe,
Caret,
Tilde,
LeftShift,
RightShift,
UnsignedRightShift,
Equal,
PlusEqual,
MinusEqual,
StarEqual,
SlashEqual,
PercentEqual,
StarStarEqual,
LeftShiftEqual,
RightShiftEqual,
UnsignedRightShiftEqual,
AmpersandEqual,
PipeEqual,
CaretEqual,
AmpersandAmpersandEqual,
PipePipeEqual,
QuestionQuestionEqual,
PlusPlus,
MinusMinus,
QuestionQuestion,
QuestionDot,
Arrow,
LeftParen,
RightParen,
LeftBrace,
RightBrace,
LeftBracket,
RightBracket,
Semicolon,
Comma,
Dot,
Colon,
At,
StringLiteral,
NumericLiteral,
BigIntLiteral,
BooleanLiteral,
TemplateString,
RegexLiteral,
IdentifierName,
LineComment,
BlockComment,
Whitespace,
Newline,
Eof,
Root,
SourceFile,
Module,
VariableDeclaration,
FunctionDeclaration,
ClassDeclaration,
InterfaceDeclaration,
TypeAliasDeclaration,
EnumDeclaration,
NamespaceDeclaration,
ClassBody,
ImportDeclaration,
ExportDeclaration,
ImportClause,
ImportSpecifier,
Parameter,
CallArgument,
PropertyDeclaration,
MethodDeclaration,
ConstructorDeclaration,
PropertyAssignment,
ShorthandPropertyAssignment,
SpreadElement,
Error,
JsxElement,
JsxSelfClosingElement,
JsxOpeningElement,
JsxClosingElement,
JsxFragment,
JsxOpeningFragment,
JsxClosingFragment,
JsxAttribute,
JsxAttributes,
JsxExpressionContainer,
JsxSpreadAttribute,
JsxText,
BinaryExpression,
UnaryExpression,
ConditionalExpression,
CallExpression,
NewExpression,
MemberExpression,
ArrayExpression,
ObjectExpression,
FunctionExpression,
TemplateExpression,
TaggedTemplateExpression,
AsExpression,
TypeAssertionExpression,
NonNullExpression,
UpdateExpression,
ExpressionStatement,
BlockStatement,
IfStatement,
WhileStatement,
ForStatement,
ForInStatement,
ForOfStatement,
DoWhileStatement,
SwitchStatement,
CaseClause,
DefaultClause,
TryStatement,
CatchClause,
FinallyClause,
ThrowStatement,
ReturnStatement,
BreakStatement,
ContinueStatement,
DebuggerStatement,
WithStatement,
BindingPattern,
ArrayBindingPattern,
ObjectBindingPattern,
BindingElement,
TypeReference,
TypeLiteral,
FunctionType,
ConstructorType,
ArrayType,
TupleType,
UnionType,
IntersectionType,
ConditionalType,
MappedType,
IndexedAccessType,
PropertySignature,
MethodSignature,
LiteralType,
TypeQuery,
TypePredicate,
TypeAnnotation,
TypeParameter,
HeritageClause,
EnumMember,
}
impl TypeScriptTokenType {
pub fn from_keyword(text: &str) -> Option<Self> {
match text {
"abstract" => Some(Self::Abstract),
"any" => Some(Self::Any),
"as" => Some(Self::As),
"asserts" => Some(Self::Asserts),
"async" => Some(Self::Async),
"await" => Some(Self::Await),
"boolean" => Some(Self::Boolean),
"break" => Some(Self::Break),
"case" => Some(Self::Case),
"catch" => Some(Self::Catch),
"class" => Some(Self::Class),
"const" => Some(Self::Const),
"constructor" => Some(Self::Constructor),
"continue" => Some(Self::Continue),
"debugger" => Some(Self::Debugger),
"declare" => Some(Self::Declare),
"default" => Some(Self::Default),
"delete" => Some(Self::Delete),
"do" => Some(Self::Do),
"else" => Some(Self::Else),
"enum" => Some(Self::Enum),
"export" => Some(Self::Export),
"extends" => Some(Self::Extends),
"false" => Some(Self::False),
"finally" => Some(Self::Finally),
"for" => Some(Self::For),
"from" => Some(Self::From),
"function" => Some(Self::Function),
"get" => Some(Self::Get),
"global" => Some(Self::Global),
"if" => Some(Self::If),
"implements" => Some(Self::Implements),
"import" => Some(Self::Import),
"in" => Some(Self::In),
"infer" => Some(Self::Infer),
"instanceof" => Some(Self::Instanceof),
"interface" => Some(Self::Interface),
"is" => Some(Self::Is),
"keyof" => Some(Self::Keyof),
"let" => Some(Self::Let),
"namespace" => Some(Self::Namespace),
"never" => Some(Self::Never),
"new" => Some(Self::New),
"null" => Some(Self::Null),
"number" => Some(Self::Number),
"object" => Some(Self::Object),
"of" => Some(Self::Of),
"override" => Some(Self::Override),
"package" => Some(Self::Package),
"private" => Some(Self::Private),
"protected" => Some(Self::Protected),
"public" => Some(Self::Public),
"readonly" => Some(Self::Readonly),
"require" => Some(Self::Require),
"return" => Some(Self::Return),
"set" => Some(Self::Set),
"static" => Some(Self::Static),
"string" => Some(Self::String),
"super" => Some(Self::Super),
"switch" => Some(Self::Switch),
"symbol" => Some(Self::Symbol),
"this" => Some(Self::This),
"throw" => Some(Self::Throw),
"true" => Some(Self::True),
"try" => Some(Self::Try),
"type" => Some(Self::Type),
"typeof" => Some(Self::Typeof),
"undefined" => Some(Self::Undefined),
"unique" => Some(Self::Unique),
"unknown" => Some(Self::Unknown),
"var" => Some(Self::Var),
"void" => Some(Self::Void),
"while" => Some(Self::While),
"with" => Some(Self::With),
"yield" => Some(Self::Yield),
_ => None,
}
}
}
impl TokenType for TypeScriptTokenType {
type Role = UniversalTokenRole;
const END_OF_STREAM: Self = Self::Eof;
fn is_ignored(&self) -> bool {
matches!(self, Self::Whitespace | Self::Newline | Self::LineComment | Self::BlockComment)
}
fn role(&self) -> Self::Role {
match self {
Self::Whitespace => UniversalTokenRole::Whitespace,
Self::Newline => UniversalTokenRole::Whitespace,
Self::LineComment => UniversalTokenRole::Comment,
Self::BlockComment => UniversalTokenRole::Comment,
Self::Eof => UniversalTokenRole::Eof,
Self::Error => UniversalTokenRole::Error,
_ => UniversalTokenRole::None,
}
}
}