use oak_core::{Token, TokenType, UniversalTokenRole};
pub type GroovyToken = Token<GroovyTokenType>;
impl GroovyTokenType {
pub fn is_keyword(&self) -> bool {
matches!(
self,
Self::AbstractKeyword
| Self::AsKeyword
| Self::AssertKeyword
| Self::BreakKeyword
| Self::CaseKeyword
| Self::CatchKeyword
| Self::ClassKeyword
| Self::ConstKeyword
| Self::ContinueKeyword
| Self::DefKeyword
| Self::DefaultKeyword
| Self::DoKeyword
| Self::ElseKeyword
| Self::EnumKeyword
| Self::ExtendsKeyword
| Self::FinalKeyword
| Self::FinallyKeyword
| Self::ForKeyword
| Self::GotoKeyword
| Self::IfKeyword
| Self::ImplementsKeyword
| Self::ImportKeyword
| Self::InKeyword
| Self::InstanceofKeyword
| Self::InterfaceKeyword
| Self::NativeKeyword
| Self::NewKeyword
| Self::PackageKeyword
| Self::PrivateKeyword
| Self::ProtectedKeyword
| Self::PublicKeyword
| Self::ReturnKeyword
| Self::StaticKeyword
| Self::StrictfpKeyword
| Self::SuperKeyword
| Self::SwitchKeyword
| Self::SynchronizedKeyword
| Self::ThisKeyword
| Self::ThrowKeyword
| Self::ThrowsKeyword
| Self::TraitKeyword
| Self::TransientKeyword
| Self::TryKeyword
| Self::VoidKeyword
| Self::VolatileKeyword
| Self::WhileKeyword
)
}
}
impl TokenType for GroovyTokenType {
type Role = UniversalTokenRole;
const END_OF_STREAM: Self = Self::Eof;
fn is_ignored(&self) -> bool {
matches!(self, Self::Whitespace | Self::Comment)
}
fn role(&self) -> Self::Role {
use UniversalTokenRole::*;
if self.is_keyword() {
return Keyword;
}
match self {
Self::IntLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::BooleanLiteral | Self::NullLiteral => Literal,
Self::Identifier => Name,
Self::Plus
| Self::Minus
| Self::Star
| Self::Slash
| Self::Percent
| Self::Power
| Self::Assign
| Self::PlusAssign
| Self::MinusAssign
| Self::StarAssign
| Self::SlashAssign
| Self::PercentAssign
| Self::PowerAssign
| Self::Equal
| Self::NotEqual
| Self::Less
| Self::Greater
| Self::LessEqual
| Self::GreaterEqual
| Self::Spaceship
| Self::LogicalAnd
| Self::LogicalOr
| Self::LogicalNot
| Self::BitAnd
| Self::BitOr
| Self::BitXor
| Self::BitNot
| Self::LeftShift
| Self::RightShift
| Self::UnsignedRightShift
| Self::Increment
| Self::Decrement
| Self::Question
| Self::Elvis
| Self::SafeNavigation => Operator,
Self::LeftParen | Self::RightParen | Self::LeftBracket | Self::RightBracket | Self::LeftBrace | Self::RightBrace | Self::Comma | Self::Period | Self::Semicolon | Self::Colon | Self::At => Punctuation,
Self::Whitespace | Self::Newline => Whitespace,
Self::Comment => Comment,
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
pub enum GroovyTokenType {
Root,
SourceFile,
IntLiteral,
FloatLiteral,
StringLiteral,
CharLiteral,
BooleanLiteral,
NullLiteral,
Identifier,
AbstractKeyword,
AsKeyword,
AssertKeyword,
BreakKeyword,
CaseKeyword,
CatchKeyword,
ClassKeyword,
ConstKeyword,
ContinueKeyword,
DefKeyword,
DefaultKeyword,
DoKeyword,
ElseKeyword,
EnumKeyword,
ExtendsKeyword,
FinalKeyword,
FinallyKeyword,
ForKeyword,
GotoKeyword,
IfKeyword,
ImplementsKeyword,
ImportKeyword,
InKeyword,
InstanceofKeyword,
InterfaceKeyword,
NativeKeyword,
NewKeyword,
PackageKeyword,
PrivateKeyword,
ProtectedKeyword,
PublicKeyword,
ReturnKeyword,
StaticKeyword,
StrictfpKeyword,
SuperKeyword,
SwitchKeyword,
SynchronizedKeyword,
ThisKeyword,
ThrowKeyword,
ThrowsKeyword,
TraitKeyword,
TransientKeyword,
TryKeyword,
VoidKeyword,
VolatileKeyword,
WhileKeyword,
Plus,
Minus,
Star,
Slash,
Percent,
Power,
Assign,
PlusAssign,
MinusAssign,
StarAssign,
SlashAssign,
PercentAssign,
PowerAssign,
Equal,
NotEqual,
Less,
Greater,
LessEqual,
GreaterEqual,
Spaceship,
LogicalAnd,
LogicalOr, LogicalNot,
BitAnd, BitOr, BitXor, BitNot, LeftShift, RightShift, UnsignedRightShift,
Increment, Decrement,
Question, Colon, Elvis, SafeNavigation,
LeftParen, RightParen, LeftBracket, RightBracket, LeftBrace, RightBrace, Comma, Period, Semicolon, At,
Whitespace,
Comment,
Newline,
Eof,
Error,
}