flexar 1.2.6

An extremely flexible lexer/parser (get it?) for writing your own programming language
Documentation
pub mod compile_error_format;
pub mod compile_error_macro;
pub mod compile_error_display;
pub use compile_error_format::*;
pub use crate::compilerr_fmt;
pub use crate::compile_error;

use std::error::Error;
use crate::cursor::Position;

/// Errors that occur during the compilation stage
#[derive(Clone, Debug)]
pub struct CompileError {
    pub id: &'static str,
    pub error_type: &'static str,
    pub msg: String,
    pub position: Position,
}

impl CompileError {
    #[inline]
    pub fn new(id: &'static str, error_type: &'static str, msg: String, position: Position) -> Self {
        CompileError { id, error_type, msg, position }
    }

    /// Prints the compile error to the screen and then exits the program
    pub fn throw<T>(&self) -> T {
        println!("{}", self);
        if cfg!(debug_assertions) {
            panic!("error thrown in debug mode");
        }
        std::process::exit(1);
    }
}

impl Error for CompileError {}

/// Compile Error Template (generated by macro)
pub struct CompileErrorTemplate<const N: usize> {
    pub error_type: &'static str,
    pub fmt: CompileErrFormatter<N>,
}

impl<const N: usize> CompileErrorTemplate<N> {
    /// Creates a new compile error template
    /// Should **only** be used a macro
    #[inline]
    pub const fn new(error_type: &'static str, fmt: CompileErrFormatter<N>) -> Self {
        Self {
            error_type,
            fmt,
        }
    }
}