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
use serde_json::Value;
use operator::Operator;
quick_error! {
#[derive(Debug, PartialEq)]
pub enum Error {
UnsupportedOperator(operator: String) {
display("Unsupported operator: {:?}", operator)
}
CanNotExec(operator: Operator) {
display("This operator does not support execution: {:?}", operator)
}
StartWithNonValueOperator {
display("Your expression may start with non-value operator like ( + * ).")
}
UnpairedBrackets {
display("Unpaired brackets, left brackets count does not equal right brackets count.")
}
DuplicateValueNode {
display("Duplicate values node, you may have (2 3) but there is no operators between them.")
}
DuplicateOperatorNode {
display("Duplicate operators node, you may have (+ +) but there is no values between them.")
}
CommaNotWithFunction {
display("You have a comma(,) , but there is no function in front of it.")
}
BracketNotWithFunction {
display("You have empty brackets () , but there is no function in front of it.")
}
FunctionNotExists(ident: String) {
display("Function not exists: {}", ident)
}
ExpectedBoolean(value: Value) {
display("Expected a boolean, found: {}", value)
}
ExpectedIdentifier {
display("Expected ident.")
}
ExpectedArray {
display("Expected array.")
}
ExpectedObject {
display("Expected object.")
}
ExpectedNumber {
display("Expected number.")
}
NoFinalNode {
display("Failed to parse, no final expression.")
}
ArgumentsGreater(max: usize) {
display("The number of arguments is greater than the maximum limit: {}", max)
}
ArgumentsLess(min: usize) {
display("The number of arguments is less than the minimum limit: {}", min)
}
UnsupportedTypes(a: String, b: String) {
display("This two value types are different or do not support mathematical calculations: {}, {}", a, b)
}
InvalidRange(ident: String) {
display("Invalid range expression: {}", ident)
}
CanNotAddChild {
display("Can not add child node.")
}
Custom(detail: String) {
display("{}", detail)
}
}
}