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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
extern crate mentat_query;
use std;
use std::fmt;
use std::fmt::Display;
use failure::{
Backtrace,
Context,
Error,
Fail,
};
use mentat_core::{
ValueType,
ValueTypeSet,
};
use self::mentat_query::{
PlainSymbol,
};
pub type Result<T> = std::result::Result<T, Error>;
#[macro_export]
macro_rules! bail {
($e:expr) => (
return Err($e.into());
)
}
#[derive(Debug)]
pub struct InvalidBinding {
pub function: PlainSymbol,
pub inner: Context<BindingError>
}
impl InvalidBinding {
pub fn new(function: PlainSymbol, inner: BindingError) -> InvalidBinding {
InvalidBinding {
function: function,
inner: Context::new(inner)
}
}
}
impl Fail for InvalidBinding {
fn cause(&self) -> Option<&Fail> {
self.inner.cause()
}
fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
}
impl Display for InvalidBinding {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid binding for {}: {:?}", self.function, self.inner)
}
}
impl Display for BindingError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "BindingError: {:?}", self)
}
}
#[derive(Clone, Debug, Eq, PartialEq, Fail)]
pub enum BindingError {
NoBoundVariable,
UnexpectedBinding,
RepeatedBoundVariable,
ExpectedBindRel,
ExpectedBindRelOrBindColl,
InvalidNumberOfBindings { number: usize, expected: usize },
}
#[derive(Debug, Fail)]
pub enum AlgebrizerError {
#[fail(display = "{} var {} is duplicated", _0, _1)]
DuplicateVariableError(PlainSymbol, &'static str),
#[fail(display = "unexpected FnArg")]
UnsupportedArgument,
#[fail(display = "value of type {} provided for var {}, expected {}", _0, _1, _2)]
InputTypeDisagreement(PlainSymbol, ValueType, ValueType),
#[fail(display = "invalid number of arguments to {}: expected {}, got {}.", _0, _1, _2)]
InvalidNumberOfArguments(PlainSymbol, usize, usize),
#[fail(display = "invalid argument to {}: expected {} in position {}.", _0, _1, _2)]
InvalidArgument(PlainSymbol, &'static str, usize),
#[fail(display = "invalid argument to {}: expected one of {:?} in position {}.", _0, _1, _2)]
InvalidArgumentType(PlainSymbol, ValueTypeSet, usize),
#[fail(display = "invalid expression in ground constant")]
InvalidGroundConstant,
#[fail(display = "invalid limit {} of type {}: expected natural number.", _0, _1)]
InvalidLimit(String, ValueType),
#[fail(display = "mismatched bindings in ground")]
GroundBindingsMismatch,
#[fail(display = "no entid found for ident: {}", _0)]
UnrecognizedIdent(String),
#[fail(display = "no function named {}", _0)]
UnknownFunction(PlainSymbol),
#[fail(display = ":limit var {} not present in :in", _0)]
UnknownLimitVar(PlainSymbol),
#[fail(display = "unbound variable {} in order clause or function call", _0)]
UnboundVariable(PlainSymbol),
#[fail(display = "non-matching variables in 'or' clause")]
NonMatchingVariablesInOrClause,
#[fail(display = "non-matching variables in 'not' clause")]
NonMatchingVariablesInNotClause,
}