use core::fmt;
use std::error::Error as StdError;
use femstache_parser::nodes::Ident;
pub use femstache_parser::{ParseError, ParseResult};
use crate::loader::LoaderError;
#[derive(Debug)]
pub enum EvalError {
InvalidType,
VariableNotFound(Ident),
Loader(LoaderError),
}
impl StdError for EvalError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
EvalError::Loader(inner) => Some(inner),
_ => None,
}
}
}
impl fmt::Display for EvalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EvalError::InvalidType => write!(f, "invalid type"),
EvalError::VariableNotFound(ident) => write!(f, "variable {} not found", ident.data),
EvalError::Loader(inner) => write!(f, "loader error: {inner}"),
}
}
}
impl From<LoaderError> for EvalError {
fn from(err: LoaderError) -> Self {
Self::Loader(err)
}
}
pub type EvalResult<T> = core::result::Result<T, EvalError>;