OverComplicatedCalculator/src/lexer/tokens.rs

43 lines
869 B
Rust

/// # Token Metadata
/// Data contained is:
/// * File that the token was parsed in
/// * Line that the token was parsed in
/// * Position of the *first character making up the token* in said line
#[derive(Debug)]
pub struct TokenMeta {
file: String,
line: u32,
pos: u32,
}
#[derive(Debug)]
pub enum OpType {
MUL,
DIV,
ADD,
SUB,
POW,
}
/// Bracket types, either OPEN or CLOSE.
#[derive(Debug)]
pub enum BrType {
OPEN,
CLOSE,
}
/// # Tokens
/// The tokens all contain [metadata](TokenMeta).
/// 1. `ID`: A number, parsed into 64 bit floating-point.
/// 1. `OBR`: An opening bracket (`(`).
/// 1. `CBR`: A closing bracket (`)`).
/// 1. `OP`: An operation. Containing an [Operation Type](OpType).
#[derive(Debug)]
pub enum Token {
ID (TokenMeta, f64),
OBR (TokenMeta),
CBR (TokenMeta),
OP (TokenMeta, OpType),
}