#[allow(dead_code)]
#[derive(Debug, Clone, PartialEq)]
pub enum Token {
Print,
Let,
If,
Then,
Else,
For,
To,
Next,
Goto,
Gosub,
Return,
End,
Rem,
Integer(i64),
Float(f64),
String(String),
Char(char),
Identifier(String),
Invalid(char),
InvalidLit(String),
Plus,
Minus,
Star,
Slash,
Equal,
Less,
Greater,
LessEqual,
GreaterEqual,
NotEqual,
LParen,
RParen,
LeftParen,
RightParen,
Comma,
Colon,
Semicolon,
Asterisk,
Eof,
}
#[allow(dead_code)]
impl Token {
#[expect(
clippy::cast_precision_loss,
reason = "numeric literals are currently represented as f64 in the AST"
)]
pub fn get_number(&self) -> f64 {
match self {
Token::Float(num) => *num,
Token::Integer(num) => (*num) as f64,
_ => panic!("You messed up."),
}
}
pub fn get_ident(&self) -> String {
match self {
Token::Identifier(ident) => ident.clone(),
_ => panic!("Not Identifier!"),
}
}
#[expect(
clippy::cast_possible_truncation,
reason = "numeric literals are currently represented as f64 in the AST"
)]
pub fn try_number(&self) -> Option<i64> {
match self {
Token::Float(num) => Some(*num as i64),
Token::Integer(num) => Some(*num),
_ => None,
}
}
}