daisy/src/evaluate/mod.rs

46 lines
889 B
Rust
Raw Normal View History

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,
2023-08-01 09:43:47 -07:00
IncompatibleUnits(String, String),
2023-07-31 16:43:30 -07:00
BadDefineName,
Undefined(String)
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 => {
2023-08-01 09:43:47 -07:00
String::from("Incompatible unit")
},
EvalError::IncompatibleUnits(a, b) => {
format!("Incompatible units ({} and {})", a, b)
2023-07-31 16:05:48 -07:00
},
EvalError::BadDefineName => {
String::from("Invalid variable name")
2023-07-31 16:43:30 -07:00
},
EvalError::Undefined(s) => {
format!("{} is undefined", s)
2023-07-31 16:05:48 -07:00
}
}
}
}