bcomp 0.1.0

A compiler for a subset of the BASIC language
//! A mandatory part of the lexer
//!
//! The tokens are just all the BASIC keywords
//! I just copied this from online sources

#[allow(dead_code)]
#[derive(Debug, Clone, PartialEq)]
pub enum Token {
    // Keywords
    Print,
    Let,
    If,
    Then,
    Else,
    For,
    To,
    Next,
    Goto,
    Gosub,
    Return,
    End,
    Rem, // Remark/comment

    // Literals
    Integer(i64),
    Float(f64),
    String(String),
    Char(char),
    Identifier(String),

    // Invalid Character
    Invalid(char),
    InvalidLit(String),

    // Operators
    Plus,
    Minus,
    Star,
    Slash,
    Equal,
    Less,
    Greater,
    LessEqual,
    GreaterEqual,
    NotEqual,
    LParen,
    RParen,

    // Symbols
    LeftParen,
    RightParen,
    Comma,
    Colon,
    Semicolon,
    Asterisk,

    // End of input
    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,
        }
    }
}