2023-06-11 13:53:45 -07:00
|
|
|
mod operator;
|
|
|
|
mod function;
|
|
|
|
mod evaluate;
|
2023-06-11 14:24:43 -07:00
|
|
|
|
2023-06-11 13:53:45 -07:00
|
|
|
pub use self::evaluate::evaluate;
|
|
|
|
|
2023-06-13 20:15:20 -07:00
|
|
|
#[derive(Debug)]
|
2023-06-11 13:53:45 -07:00
|
|
|
pub enum EvalError {
|
|
|
|
BadMath,
|
|
|
|
TooBig,
|
|
|
|
ZeroDivision,
|
2023-06-14 20:18:28 -07:00
|
|
|
IncompatibleUnit,
|
|
|
|
BadDefineName
|
2023-07-31 16:05:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl ToString for EvalError {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
|
|
|
EvalError::BadMath => {
|
|
|
|
String::from("Failed to evaluate expression")
|
|
|
|
},
|
|
|
|
EvalError::TooBig => {
|
|
|
|
String::from("Number too big")
|
|
|
|
},
|
|
|
|
EvalError::ZeroDivision => {
|
|
|
|
String::from("Division by zero")
|
|
|
|
},
|
|
|
|
EvalError::IncompatibleUnit => {
|
|
|
|
String::from("Incompatible units")
|
|
|
|
},
|
|
|
|
EvalError::BadDefineName => {
|
|
|
|
String::from("Invalid variable name")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|