teacat_lib 0.5.1

Tools for working with TeaCat files
Documentation
use std::{error::Error, fmt::Display};

use crate::exec::ModuleName;

type PestErr = pest::error::Error<crate::parser::grammar::Rule>;

#[derive(Debug, Clone)]
pub enum TeaCatErr {
	Parsing(PestErr),
	NotInScope(String),
	ModuleNotFound(ModuleName),
}

impl Display for TeaCatErr {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		macro_rules! write {
			($($arg:tt)*) => { f.write_str(&format!($($arg)*)) };
		}
		match self {
			Self::Parsing(pest_err) => pest_err.fmt(f),
			Self::NotInScope(str) => write!("Variable @{str} not in scope!"),
			Self::ModuleNotFound(name) => write!("Module {name} not found!"),
		}
	}
}

impl Error for TeaCatErr {}

impl From<PestErr> for TeaCatErr {
	fn from(err: PestErr) -> Self {
		TeaCatErr::Parsing(err)
	}
}