pull/2/head
Mark 2023-08-03 14:04:12 -07:00
parent 4ddafd84ef
commit ae2041e42f
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 8 additions and 8 deletions

View File

@ -28,7 +28,7 @@ fn to_radians(q: Quantity) -> Result<Quantity, ()> {
pub fn eval_function(g: &Expression) -> Result<Expression, (LineLocation, EvalError)> {
let Expression::Operator(loc, Operator::Function(f), args) = g else {panic!()};
let Expression::Operator(loc, Operator::Function(f), args) = g else {unreachable!()};
if args.len() != 1 {panic!()};
let a = &args[0];

View File

@ -11,8 +11,8 @@ pub enum EvalError {
ZeroDivision,
IncompatibleUnit,
IncompatibleUnits(String, String),
BadDefineName,
Undefined(String)
Undefined(String),
EvaluationError,
}
@ -32,13 +32,13 @@ impl ToString for EvalError {
String::from("Incompatible unit")
},
EvalError::IncompatibleUnits(a, b) => {
format!("Incompatible units ({} and {})", a, b)
},
EvalError::BadDefineName => {
String::from("Invalid variable name")
format!("Incompatible units ({a} and {b})")
},
EvalError::Undefined(s) => {
format!("{} is undefined", s)
format!("{s} is undefined")
},
EvalError::EvaluationError => {
String::from("Could not evaluate")
}
}
}