-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.rs
97 lines (95 loc) · 3.9 KB
/
display.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use super::ErrorType::{self, *};
use std::fmt;
impl fmt::Display for ErrorType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TypeError { expected, given } => write!(
f,
"MATH ERROR: a function expected type {}, but a type {} was given.",
expected, given
),
UnknownToken { token } => write!(
f,
"SYNTAX ERROR: an invalid token was provided: `{}`.",
token
),
InvalidTokenPosition { token } => {
write!(f, "SYNTAX ERROR: invalid position for token `{}`.", token)
}
FailedCast { value, from, to } => write!(
f,
"MATH ERROR: could not cast value `{}` from type {} to type {}.",
value, from, to
),
MismatchedArrayLengths {
first,
second,
operation_name,
} => write!(
f,
"MATH ERROR: invalid vectors sizes {} and {} for operation `{}`.",
first, second, operation_name
),
DivideByZero { numerator } => {
write!(f, "MATH ERROR: trying to divide {} by zero.", numerator)
}
NotAnOperator { token } => {
write!(f, "SYNTAX ERROR: `{}` is not a valid operator!", token)
}
InvalidClosingBracket => write!(f, "SYNTAX ERROR: invalid closing bracket."),
MissingClosingBracket => write!(f, "SYNTAX ERROR: missing closing bracket."),
MissingOperatorArgument { token } => {
write!(f, "SYNTAX ERROR: missing argument for operator `{}`", token)
}
FailedParse { value } => write!(f, "SYNTAX ERROR: could not parse value `{}`.", value),
EmptyBrackets => write!(f, "SYNTAX ERROR: invalid empty brackets."),
WrongFunctionArgumentsAmount {
func_name,
expected,
given,
} => write!(
f,
"SYNTAX ERROR: function `{}` expected {} arguments, but got {}.",
func_name, expected, given
),
MissingFunctionParameters { func_name } => write!(
f,
"SYNTAX ERROR: no arguments provided for function `{}`.",
func_name
),
InvalidDeclaration => write!(f, "SYNTAX ERROR: invalid declaration."),
UnknownFunction { func_name } => {
write!(f, "SYNTAX ERROR: unknown function `{}`.", func_name)
}
UnknownVar { var_name } => write!(f, "SYNTAX ERROR: unknown variable `{}`.", var_name),
ReservedVarName { var_name } => write!(
f,
"INTERNAL ERROR: `{}` is a keyword and cannot be used as a variable name.",
var_name
),
ReservedFunctionName { func_name } => write!(
f,
"INTERNAL ERROR: `{}` is a keyword cannot be used as a function name.",
func_name
),
EmptyUnion => write!(f, "SYNTAX ERROR: trying to aggregate an empty value."),
InvalidMutableContext { request } => write!(
f,
"INTERNAL ERROR: request `{}` is not valid for a static context",
request
),
RecursionDepthLimitReached { limit } => {
write!(f, "INTERNAL ERROR: maximum depth reached: {}.", limit)
}
ErrorDuring {
operation_name,
error,
} => write!(
f,
"An error occurred during operation `{}`: \n {}",
operation_name, *error
),
InternalError { message } => write!(f, "INTERNAL ERROR: {}.", message),
}
}
}