use std::fmt;
pub const MAX_PARSE_DEPTH: usize = 32;
pub const MAX_EVAL_DEPTH: usize = 64;
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
ParseError(String),
EvalError(String),
TypeError(String),
UnboundVariable(String),
ArityError {
expected: usize,
got: usize,
expression: Option<String>, },
}
impl Error {
pub fn arity_error(expected: usize, got: usize) -> Self {
Error::ArityError {
expected,
got,
expression: None,
}
}
pub fn arity_error_with_expr(expected: usize, got: usize, expression: String) -> Self {
Error::ArityError {
expected,
got,
expression: Some(expression),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::ParseError(msg) => write!(f, "Parse error: {msg}"),
Error::EvalError(msg) => write!(f, "Evaluation error: {msg}"),
Error::TypeError(msg) => write!(f, "Type error: {msg}"),
Error::UnboundVariable(var) => write!(f, "Unbound variable: {var}"),
Error::ArityError {
expected,
got,
expression,
} => match expression {
Some(expr) => write!(
f,
"Arity error in expression {expr}: expected {expected} arguments, got {got}"
),
None => write!(f, "Arity error: expected {expected} arguments, got {got}"),
},
}
}
}
mod ast;
mod builtinops;
pub mod evaluator;
pub use ast::Value;
#[cfg(feature = "jsonlogic")]
pub mod jsonlogic;
#[cfg(feature = "scheme")]
pub mod scheme;