use oak_core::{Source, Token, TokenType, UniversalElementRole, UniversalTokenRole};
pub type FSharpToken = Token<FSharpTokenType>;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FSharpTokenType {
Root,
Expression,
Whitespace,
Newline,
Identifier,
IntegerLiteral,
FloatLiteral,
StringLiteral,
CharLiteral,
BooleanLiteral,
UnitLiteral,
Let,
Rec,
And,
In,
If,
Then,
Else,
Elif,
Match,
With,
When,
Function,
Fun,
Type,
Val,
Mutable,
Of,
As,
Module,
Namespace,
Open,
Try,
Finally,
Exception,
Raise,
Failwith,
For,
To,
Downto,
Do,
Done,
While,
Yield,
Return,
Class,
Interface,
Inherit,
Abstract,
Override,
Default,
Member,
Static,
New,
Lazy,
Async,
Seq,
Use,
Begin,
End,
Struct,
Sig,
True,
False,
Null,
Or,
Public,
Private,
Internal,
Inline,
Extern,
Upcast,
Downcast,
Assert,
Global,
Base,
This,
Void,
Delegate,
Select,
Obj,
Unit,
Int,
Float,
String,
Bool,
Char,
Byte,
SByte,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
NativeInt,
UNativeInt,
Decimal,
BigInt,
Plus,
Minus,
Star,
Slash,
Percent,
StarStar,
Equal,
NotEqual,
LessThan,
LessEqual,
GreaterThan,
GreaterEqual,
AndAnd,
OrOr,
Not,
BitwiseAnd,
BitwiseOr,
BitwiseXor,
BitwiseNot,
LeftShift,
RightShift,
Arrow,
DoubleArrow,
Pipe,
PipeRight,
DoublePipe,
Cons,
At,
Compose,
ComposeBack,
Dollar,
PipeForward,
PipeBackward,
LogicalAnd,
LogicalOr,
Ampersand,
Caret,
Tilde,
Less,
Greater,
PipeGreater,
Exclamation,
ColonEqual,
LArrow,
PlusPlus,
MinusMinus,
LeftParen,
RightParen,
LeftBracket,
RightBracket,
LeftArrayBracket,
RightArrayBracket,
LeftBracketBar,
RightBracketBar,
LeftBracketAngle,
RightBracketAngle,
LeftBrace,
RightBrace,
LeftAngle,
RightAngle,
Comma,
Semicolon,
Colon,
DoubleColon,
Dot,
DotDot,
Question,
Underscore,
Apostrophe,
Backtick,
Hash,
LineComment,
BlockComment,
Error,
Eof,
}
impl FSharpTokenType {
pub fn is_keyword(&self) -> bool {
matches!(
self,
Self::Let
| Self::Rec
| Self::And
| Self::In
| Self::If
| Self::Then
| Self::Else
| Self::Elif
| Self::Match
| Self::With
| Self::When
| Self::Function
| Self::Fun
| Self::Type
| Self::Val
| Self::Mutable
| Self::Of
| Self::As
| Self::Module
| Self::Namespace
| Self::Open
| Self::Try
| Self::Finally
| Self::Exception
| Self::Raise
| Self::Failwith
| Self::For
| Self::To
| Self::Downto
| Self::Do
| Self::Done
| Self::While
| Self::Yield
| Self::Return
| Self::Class
| Self::Interface
| Self::Inherit
| Self::Abstract
| Self::Override
| Self::Default
| Self::Member
| Self::Static
| Self::New
| Self::Lazy
| Self::Async
| Self::Seq
| Self::Use
| Self::Begin
| Self::End
| Self::Struct
| Self::Sig
| Self::True
| Self::False
| Self::Null
| Self::Or
| Self::Public
| Self::Private
| Self::Internal
| Self::Inline
| Self::Extern
| Self::Upcast
| Self::Downcast
| Self::Assert
| Self::Delegate
| Self::Select
)
}
}
impl TokenType for FSharpTokenType {
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::Error => UniversalTokenRole::Error,
_ if self.is_keyword() => UniversalTokenRole::Keyword,
Self::Identifier => UniversalTokenRole::Name,
Self::IntegerLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::BooleanLiteral => UniversalTokenRole::Literal,
_ => UniversalTokenRole::None,
}
}
}