1use std::fmt;
2
3#[derive(PartialEq, Debug)]
4pub enum Error {
5 MissingOperands(String), NotEnoughFunctionParams(String), FunctionSyntaxError(String), UnknownFunction(String), UnknownVariable(String), CannotEvaluateToken(String), InvalidToken(String),
12 EmptyExpression,
13}
14
15impl fmt::Display for Error {
16 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17 match self {
18 Error::MissingOperands(operator) => write!(
19 f,
20 "Expected more operands for operator \"{}\"",
21 operator
22 ),
23 Error::NotEnoughFunctionParams(fn_name) => write!(
24 f,
25 "Expected more parameters for function \"{}\"",
26 fn_name
27 ),
28 Error::FunctionSyntaxError(fn_name) => write!(
29 f,
30 "Syntax error in function \"{}()\". Usually this occurs \
31 because of missing or extra commas.",
32 fn_name
33 ),
34 Error::UnknownFunction(fn_name) => write!(
35 f,
36 "Function\"{}()\" does not exist. If it is a custom function, \
37 make sure you are passing it through the Scope.",
38 fn_name
39 ),
40 Error::UnknownVariable(var_name) => write!(
41 f,
42 "Variable \"{}\" is not defined. Make sure you are passing it \
43 through the Scope.",
44 var_name
45 ),
46 Error::CannotEvaluateToken(token) => write!(
47 f,
48 "Token \"{}\" does not belong on the stack. Please open an \
49 issue with your expression at \
50 https://github.com/chmln/asciimath-rs/issues",
51 token
52 ),
53 Error::InvalidToken(token) => {
54 write!(f, "Invalid token: \"{}\"", token)
55 },
56 Error::EmptyExpression => write!(
57 f,
58 "The expression is empty and there is nothing to evaluate"
59 ),
60 }
61 }
62}
63
64impl std::error::Error for Error {}