use oak_core::{Source, Token, TokenType, UniversalElementRole, UniversalTokenRole};
pub type TypstToken = Token<TypstTokenType>;
impl TokenType for TypstTokenType {
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 | Self::Newline => UniversalTokenRole::Whitespace,
Self::LineComment | Self::BlockComment => UniversalTokenRole::Comment,
Self::Let | Self::If | Self::Else | Self::For | Self::While | Self::Break | Self::Continue | Self::Return | Self::Import | Self::Include | Self::Set | Self::Show => UniversalTokenRole::Keyword,
Self::True | Self::False | Self::StringLiteral | Self::NumericLiteral => UniversalTokenRole::Literal,
Self::Identifier => UniversalTokenRole::Name,
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 => {
UniversalTokenRole::Operator
}
Self::LeftParen
| Self::RightParen
| Self::LeftBrace
| Self::RightBrace
| Self::LeftBracket
| Self::RightBracket
| Self::Semicolon
| Self::Comma
| Self::Dot
| Self::Colon
| Self::Hash
| Self::At
| Self::Dollar
| Self::Underscore
| Self::Backtick => UniversalTokenRole::Punctuation,
Self::Eof => UniversalTokenRole::Eof,
Self::Error => UniversalTokenRole::Error,
_ => UniversalTokenRole::None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TypstTokenType {
Root,
Document,
Block,
Heading,
Paragraph,
List,
ListItem,
EnumItem,
Table,
TableRow,
TableCell,
Figure,
Image,
Link,
Text,
Strong,
Emphasis,
Code,
Math,
InlineMath,
DisplayMath,
Raw,
Quote,
Script,
Expression,
FunctionCall,
Variable,
Assignment,
Conditional,
Loop,
Import,
Include,
Set,
Show,
Style,
Color,
Font,
Size,
Let,
If,
Else,
For,
While,
Break,
Continue,
Return,
True,
False,
Plus,
Minus,
Star,
Slash,
Percent,
Equal,
EqualEqual,
NotEqual,
Less,
Greater,
LessEqual,
GreaterEqual,
And,
Or,
Not,
LeftParen,
RightParen,
LeftBrace,
RightBrace,
LeftBracket,
RightBracket,
Semicolon,
Comma,
Dot,
Colon,
Hash,
At,
Dollar,
Underscore,
Backtick,
StringLiteral,
NumericLiteral,
Identifier,
LineComment,
BlockComment,
Whitespace,
Newline,
Eof,
Error,
}