1use std::borrow::Cow;
2
3use thiserror::Error;
4
5#[derive(Debug, Error, PartialEq)]
6pub enum Error<'a>
7{
8 #[error("unknown variable '{0}'")]
9 UnknownVar(Cow<'a, str>),
10
11 #[error("unknown function '{0}'")]
12 UnknownFn(Cow<'a, str>),
13
14 #[error("parse error: {0}")]
15 ParseError(ParseError<'a>),
16
17 #[error("eval error: {0}")]
18 EvalError(EvalError),
19
20 #[error("internal invariant: {0}")]
21 InternalInvariant(String),
22}
23
24#[derive(Debug, Error, PartialEq)]
25pub enum ParseError<'a>
26{
27 #[error("unexpected character '{0}' at {1}")]
28 UnexpectedChar(Cow<'a, char>, usize),
29
30 #[error("invalid number '{0}' at {1}")]
31 InvalidNumber(Cow<'a, str>, usize),
32
33 #[error("unmatched parentheses at {0}")]
34 UnmatchedParentheses(usize),
35
36 #[error("unexpected expresison end")]
37 UnexpectedEnd,
38}
39
40#[derive(Debug, Error, PartialEq)]
41pub enum EvalError
42{
43 #[error("RPN stack underflow")]
44 RPNStackUnderflow,
45
46 #[error("malformed expression")]
47 MalformedExpression,
48}