use crate::source::Span;
#[derive(Clone, Debug, PartialEq)]
pub enum TokenKind {
LeftParen,
RightParen,
LeftBrace,
RightBrace,
LeftBracket,
RightBracket,
Comma,
Colon,
ColonColon,
Dot,
DotDot,
Semicolon,
Plus,
Minus,
Star,
Slash,
Percent,
Dollar,
Bang,
Question,
BangEqual,
Equal,
EqualEqual,
FatArrow,
Greater,
GreaterEqual,
Ampersand,
Less,
LessEqual,
AndAnd,
OrOr,
Arrow,
Identifier(String),
Integer(i64),
Float(f64),
String(String),
Let,
Mut,
Fn,
Macro,
If,
Else,
While,
Loop,
Match,
Struct,
Enum,
Impl,
Trait,
Type,
For,
In,
As,
Return,
Break,
Continue,
Mod,
Use,
Pub,
True,
False,
Nil,
Eof,
}
impl TokenKind {
pub fn name(&self) -> &'static str {
match self {
Self::LeftParen => "`(`",
Self::RightParen => "`)`",
Self::LeftBrace => "`{`",
Self::RightBrace => "`}`",
Self::LeftBracket => "`[`",
Self::RightBracket => "`]`",
Self::Comma => "`,`",
Self::Colon => "`:`",
Self::ColonColon => "`::`",
Self::Dot => "`.`",
Self::DotDot => "`..`",
Self::Semicolon => "`;`",
Self::Plus => "`+`",
Self::Minus => "`-`",
Self::Star => "`*`",
Self::Slash => "`/`",
Self::Percent => "`%`",
Self::Dollar => "`$`",
Self::Bang => "`!`",
Self::Question => "`?`",
Self::BangEqual => "`!=`",
Self::Equal => "`=`",
Self::EqualEqual => "`==`",
Self::FatArrow => "`=>`",
Self::Greater => "`>`",
Self::GreaterEqual => "`>=`",
Self::Ampersand => "`&`",
Self::Less => "`<`",
Self::LessEqual => "`<=`",
Self::AndAnd => "`&&`",
Self::OrOr => "`||`",
Self::Arrow => "`->`",
Self::Identifier(_) => "identifier",
Self::Integer(_) => "integer",
Self::Float(_) => "float",
Self::String(_) => "string",
Self::Let => "`let`",
Self::Mut => "`mut`",
Self::Fn => "`fn`",
Self::Macro => "`macro`",
Self::If => "`if`",
Self::Else => "`else`",
Self::While => "`while`",
Self::Loop => "`loop`",
Self::Match => "`match`",
Self::Struct => "`struct`",
Self::Enum => "`enum`",
Self::Impl => "`impl`",
Self::Trait => "`trait`",
Self::Type => "`type`",
Self::For => "`for`",
Self::In => "`in`",
Self::As => "`as`",
Self::Return => "`return`",
Self::Break => "`break`",
Self::Continue => "`continue`",
Self::Mod => "`mod`",
Self::Use => "`use`",
Self::Pub => "`pub`",
Self::True => "`true`",
Self::False => "`false`",
Self::Nil => "`nil`",
Self::Eof => "end of file",
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Token {
pub kind: TokenKind,
pub span: Span,
}
impl Token {
pub const fn new(kind: TokenKind, span: Span) -> Self {
Self { kind, span }
}
}