2016-11-16 16:12:26 +00:00
|
|
|
|
|
|
|
use serde_json::Value;
|
|
|
|
use operator::Operator;
|
|
|
|
|
|
|
|
|
|
|
|
quick_error! {
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Expression parsing error
|
2016-11-16 16:12:26 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum Error {
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Unsupported operator yet.
|
2016-11-16 16:12:26 +00:00
|
|
|
UnsupportedOperator(operator: String) {
|
|
|
|
display("Unsupported operator: {:?}", operator)
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// This operator does not support execution.
|
2016-11-16 16:12:26 +00:00
|
|
|
CanNotExec(operator: Operator) {
|
|
|
|
display("This operator does not support execution: {:?}", operator)
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Your expression may start with non-value operator like ( + * )
|
2016-11-16 16:12:26 +00:00
|
|
|
StartWithNonValueOperator {
|
|
|
|
display("Your expression may start with non-value operator like ( + * ).")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Unpaired brackets, left brackets count does not equal right brackets count
|
2016-11-16 16:12:26 +00:00
|
|
|
UnpairedBrackets {
|
|
|
|
display("Unpaired brackets, left brackets count does not equal right brackets count.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Duplicate values node, you may have (2 3) but there is no operators between them
|
2016-11-16 16:12:26 +00:00
|
|
|
DuplicateValueNode {
|
|
|
|
display("Duplicate values node, you may have (2 3) but there is no operators between them.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Duplicate operators node, you may have (+ +) but there is no values between them
|
2016-11-16 16:12:26 +00:00
|
|
|
DuplicateOperatorNode {
|
|
|
|
display("Duplicate operators node, you may have (+ +) but there is no values between them.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// You have a comma(,) , but there is no function in front of it.
|
2016-11-16 16:12:26 +00:00
|
|
|
CommaNotWithFunction {
|
|
|
|
display("You have a comma(,) , but there is no function in front of it.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// You have empty brackets () , but there is no function in front of it.
|
2016-11-16 16:12:26 +00:00
|
|
|
BracketNotWithFunction {
|
|
|
|
display("You have empty brackets () , but there is no function in front of it.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Function not exists.
|
2016-11-16 16:12:26 +00:00
|
|
|
FunctionNotExists(ident: String) {
|
|
|
|
display("Function not exists: {}", ident)
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Expected a boolean but the given value isn't.
|
2016-11-21 01:14:40 +00:00
|
|
|
ExpectedBoolean(value: Value) {
|
|
|
|
display("Expected a boolean, found: {}", value)
|
2016-11-16 16:12:26 +00:00
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Expected ident.
|
2016-11-21 01:14:40 +00:00
|
|
|
ExpectedIdentifier {
|
|
|
|
display("Expected ident.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Expected array.
|
2016-11-21 01:14:40 +00:00
|
|
|
ExpectedArray {
|
|
|
|
display("Expected array.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Expected object.
|
2016-11-21 01:14:40 +00:00
|
|
|
ExpectedObject {
|
|
|
|
display("Expected object.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Expect number.
|
2016-11-21 01:14:40 +00:00
|
|
|
ExpectedNumber {
|
|
|
|
display("Expected number.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Failed to parse, no final expression.
|
2016-11-16 16:12:26 +00:00
|
|
|
NoFinalNode {
|
|
|
|
display("Failed to parse, no final expression.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// The number of arguments is greater than the maximum limit.
|
2016-11-16 16:12:26 +00:00
|
|
|
ArgumentsGreater(max: usize) {
|
|
|
|
display("The number of arguments is greater than the maximum limit: {}", max)
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// The number of arguments is less than the minimum limit.
|
2016-11-16 16:12:26 +00:00
|
|
|
ArgumentsLess(min: usize) {
|
|
|
|
display("The number of arguments is less than the minimum limit: {}", min)
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// This two value types are different or do not support mathematical calculations.
|
2016-11-16 16:12:26 +00:00
|
|
|
UnsupportedTypes(a: String, b: String) {
|
|
|
|
display("This two value types are different or do not support mathematical calculations: {}, {}", a, b)
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Invalid range expression like `1..2..3`
|
2016-11-16 16:28:54 +00:00
|
|
|
InvalidRange(ident: String) {
|
|
|
|
display("Invalid range expression: {}", ident)
|
2016-11-16 16:12:26 +00:00
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Can not add child node.
|
2016-11-21 01:14:40 +00:00
|
|
|
CanNotAddChild {
|
|
|
|
display("Can not add child node.")
|
|
|
|
}
|
2017-02-13 00:20:53 +00:00
|
|
|
/// Custom error.
|
2016-11-16 16:12:26 +00:00
|
|
|
Custom(detail: String) {
|
|
|
|
display("{}", detail)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|