use std::fmt;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Position(pub usize, pub usize);
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Position(line, column) = self;
write!(f, "{line}:{column}")
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Token {
pub r#type: TokenType,
pub position: Position,
}
impl Token {
pub fn new(r#type: TokenType, position: Position) -> Self {
Self { r#type, position }
}
}
pub type TT = TokenType;
#[derive(Debug, Clone, PartialEq)]
pub enum TokenType {
Integer(i32),
Float(f32),
Boolean(bool),
String(String),
RawString(String),
Identifier(String),
Flag(String),
Export,
Let,
External,
Import,
Source,
Function,
Return,
If,
Elif,
Else,
For,
In,
While,
Continue,
Break,
Assignment,
Add,
Sub,
Multiply,
Divide,
Modulo,
Power,
AddAssignment,
SubAssignment,
MultiplyAssignment,
DivideAssignment,
ModuloAssignment,
PowerAssignment,
And,
Or,
Not,
Equal,
Less,
Greater,
LessEqual,
GreaterEqual,
NotEqual,
Pipe,
Daemon,
RegexMatch,
Question,
Colon,
Dollar,
At,
Dot,
Range, Comma,
Semicolon,
LParen,
RParen,
LBrace,
RBrace,
LBracket,
RBracket,
Invalid,
}
impl std::fmt::Display for Token {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Token { r#type, .. } = self;
write!(f, "{type}")
}
}
impl Default for TokenType {
fn default() -> Self {
Self::Invalid
}
}
impl std::fmt::Display for TokenType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}",)
}
}