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