use oak_core::{Token, TokenType, UniversalTokenRole};
impl TokenType for ObjectiveCTokenType {
type Role = UniversalTokenRole;
const END_OF_STREAM: Self = Self::Eof;
fn is_ignored(&self) -> bool {
match self {
Self::Whitespace | Self::Newline | Self::CommentToken => true,
_ => false,
}
}
fn role(&self) -> Self::Role {
match self {
Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
Self::CommentToken => UniversalTokenRole::Comment,
Self::IntegerLiteral | Self::FloatLiteral | Self::String | Self::Character => UniversalTokenRole::Literal,
Self::Identifier => UniversalTokenRole::Name,
Self::InterfaceKeyword
| Self::ImplementationKeyword
| Self::EndKeyword
| Self::PropertyKeyword
| Self::SynthesizeKeyword
| Self::DynamicKeyword
| Self::ProtocolKeyword
| Self::CategoryKeyword
| Self::ImportKeyword
| Self::IncludeKeyword
| Self::IfKeyword
| Self::ElseKeyword
| Self::ForKeyword
| Self::WhileKeyword
| Self::DoKeyword
| Self::SwitchKeyword
| Self::CaseKeyword
| Self::DefaultKeyword
| Self::BreakKeyword
| Self::ContinueKeyword
| Self::ReturnKeyword
| Self::VoidKeyword
| Self::IntKeyword
| Self::FloatKeyword
| Self::DoubleKeyword
| Self::CharKeyword
| Self::BoolKeyword
| Self::IdKeyword
| Self::SelfKeyword
| Self::SuperKeyword
| Self::NilKeyword
| Self::YesKeyword
| Self::NoKeyword => UniversalTokenRole::Keyword,
Self::Plus | Self::Minus | Self::Star | Self::Slash | Self::Percent | Self::Equal | Self::EqualEqual | Self::NotEqual | Self::Less | Self::Greater | Self::LessEqual | Self::GreaterEqual | Self::And | Self::Or | Self::Not | Self::Question => {
UniversalTokenRole::Operator
}
Self::LeftParen | Self::RightParen | Self::LeftBrace | Self::RightBrace | Self::LeftBracket | Self::RightBracket | Self::Semicolon | Self::Comma | Self::Dot | Self::Colon | Self::At => UniversalTokenRole::Punctuation,
Self::Eof => UniversalTokenRole::Eof,
Self::Error => UniversalTokenRole::Error,
_ => UniversalTokenRole::None,
}
}
}
pub type ObjectiveCToken = Token<ObjectiveCTokenType>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ObjectiveCTokenType {
Root,
InterfaceDeclaration,
ImplementationDeclaration,
MethodDeclaration,
PropertyDeclaration,
ProtocolDeclaration,
CategoryDeclaration,
ClassExtension,
InterfaceKeyword,
ImplementationKeyword,
EndKeyword,
PropertyKeyword,
SynthesizeKeyword,
DynamicKeyword,
ProtocolKeyword,
CategoryKeyword,
ImportKeyword,
IncludeKeyword,
IfKeyword,
ElseKeyword,
ForKeyword,
WhileKeyword,
DoKeyword,
SwitchKeyword,
CaseKeyword,
DefaultKeyword,
BreakKeyword,
ContinueKeyword,
ReturnKeyword,
VoidKeyword,
IntKeyword,
FloatKeyword,
DoubleKeyword,
CharKeyword,
BoolKeyword,
IdKeyword,
SelfKeyword,
SuperKeyword,
NilKeyword,
YesKeyword,
NoKeyword,
LeftParen,
RightParen,
LeftBrace,
RightBrace,
LeftBracket,
RightBracket,
Semicolon,
Comma,
Dot,
Colon,
Plus,
Minus,
Star,
Slash,
Percent,
Equal,
EqualEqual,
NotEqual,
Less,
Greater,
LessEqual,
GreaterEqual,
And,
Or,
Not,
Question,
At,
Identifier,
IntegerLiteral,
FloatLiteral,
String,
Character,
Whitespace,
Newline,
CommentToken,
Error,
Eof,
}