diff options
Diffstat (limited to 'src/lisp/error.rs')
-rw-r--r-- | src/lisp/error.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/lisp/error.rs b/src/lisp/error.rs index 4f90d14..b90e211 100644 --- a/src/lisp/error.rs +++ b/src/lisp/error.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | use crate::lisp::lex::{Span, SpanDisplay}; | 1 | use crate::lisp::{ |
2 | expr::Arity, | ||
3 | lex::{Span, SpanDisplay}, | ||
4 | }; | ||
2 | 5 | ||
3 | use std::fmt; | 6 | use std::fmt; |
4 | 7 | ||
@@ -81,23 +84,34 @@ impl From<ParseError> for LispError { | |||
81 | 84 | ||
82 | #[derive(Debug, PartialEq, Clone)] | 85 | #[derive(Debug, PartialEq, Clone)] |
83 | pub enum EvalError { | 86 | pub enum EvalError { |
84 | ArgumentCount(Option<u32>), // expected | 87 | ArgumentCount(Arity), |
85 | BadForm, | 88 | BadForm, |
86 | UnboundVariable(String), | 89 | UnboundVariable(String), |
87 | DivByZero, | 90 | DivByZero, |
88 | TypeMismatch, | 91 | TypeMismatch, |
92 | NoFileName, | ||
89 | } | 93 | } |
90 | 94 | ||
91 | impl fmt::Display for EvalError { | 95 | impl fmt::Display for EvalError { |
92 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 96 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
93 | match self { | 97 | match self { |
94 | Self::ArgumentCount(i) => { | 98 | Self::ArgumentCount(i) => { |
95 | write!(f, "invalid number of arguments, expected atleast {:?}", i) | 99 | write!(f, "invalid number of arguments, expected ")?; |
100 | match i { | ||
101 | Arity::Exact(a) => write!(f, "exactly {} argument(s)", a), | ||
102 | Arity::Atleast(a) => write!(f, "atleast {} argument(s)", a), | ||
103 | Arity::Atmost(a) => write!(f, "atmost {} argument(s)", a), | ||
104 | Arity::Range(low, high) => { | ||
105 | write!(f, "between {} and {} argument(s)", low, high) | ||
106 | } | ||
107 | Arity::None => write!(f, "any number of arguments"), | ||
108 | } | ||
96 | } | 109 | } |
97 | Self::BadForm => write!(f, "bad expression form"), | 110 | Self::BadForm => write!(f, "bad expression form"), |
98 | Self::UnboundVariable(s) => write!(f, "unbound variable {}", s), | 111 | Self::UnboundVariable(s) => write!(f, "unbound variable {}", s), |
99 | Self::TypeMismatch => write!(f, "mismatched types"), | 112 | Self::TypeMismatch => write!(f, "mismatched types"), |
100 | Self::DivByZero => write!(f, "attempt to divide by zero"), | 113 | Self::DivByZero => write!(f, "attempt to divide by zero"), |
114 | Self::NoFileName => write!(f, "no file name specified"), | ||
101 | } | 115 | } |
102 | } | 116 | } |
103 | } | 117 | } |