mod error;
mod lexer;
mod parser;

use core::fmt;
use crate::assembler::{AssembleError, Symbol};
use common::{asm::AsmOpcode, prelude::Register};
use lexer::Lexer;
use parser::Parser;

pub fn asm(input: &str) -> Result<Vec<u8>, AssembleError> {
    let mut lexer = Lexer::new(input.to_string(), 0);

    let tokens = lexer.run()?;

    let ast = Parser::new(tokens).parse().unwrap();

    println!("{:#?}", ast);
    Ok(vec![])
}

#[derive(Debug, Clone)]
pub enum Token {
    Symbol(Symbol),
    Register(Register),
    Immediate(u32),
    StringLit(String),
    CharLit(char),
    Opcode(AsmOpcode),
}

impl fmt::Display for Token {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Symbol(symbol) => write!(f, "{symbol}"),
            Self::Register(register) => write!(f, "{register}",),
            Self::Immediate(immediate) => write!(f, "{immediate}",),
            Self::StringLit(string_lit) => write!(f, "{string_lit}",),
            Self::CharLit(char_lit) => write!(f, "{char_lit}",),
            Self::Opcode(opcode) => write!(f, "{opcode}",),
        }
    }
}
