mirror of
https://github.com/rm-dr/daisy
synced 2025-10-11 02:01:23 -07:00
Added formattedtext and better error class
This commit is contained in:
@ -2,50 +2,4 @@ mod operator;
|
||||
mod function;
|
||||
mod evaluate;
|
||||
|
||||
pub use self::evaluate::evaluate;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EvalError {
|
||||
BadMath,
|
||||
TooBig,
|
||||
ZeroDivision,
|
||||
IncompatibleUnit,
|
||||
IncompatibleUnits(String, String),
|
||||
Undefined(String),
|
||||
EvaluationError,
|
||||
BadArguments(String, usize, usize)
|
||||
}
|
||||
|
||||
|
||||
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 unit")
|
||||
},
|
||||
EvalError::IncompatibleUnits(a, b) => {
|
||||
format!("Incompatible units ({a} and {b})")
|
||||
},
|
||||
EvalError::Undefined(s) => {
|
||||
format!("{s} is undefined")
|
||||
},
|
||||
EvalError::EvaluationError => {
|
||||
String::from("Could not evaluate")
|
||||
},
|
||||
EvalError::BadArguments(s, want, got) => {
|
||||
format!("{s} takes {want} argument{}, got {got}",
|
||||
if *want == 1 {""} else {"s"},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use self::evaluate::evaluate;
|
Reference in New Issue
Block a user