2017-03-16 19:16:56 +00:00
|
|
|
// Copyright 2016 Mozilla
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
|
|
// this file except in compliance with the License. You may obtain a copy of the
|
|
|
|
// License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed
|
|
|
|
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
|
// specific language governing permissions and limitations under the License.
|
|
|
|
|
|
|
|
extern crate mentat_query;
|
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
use std; // To refer to std::result::Result.
|
|
|
|
use std::fmt;
|
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
|
|
use failure::{
|
|
|
|
Backtrace,
|
|
|
|
Context,
|
|
|
|
Error,
|
|
|
|
Fail,
|
|
|
|
};
|
|
|
|
|
2017-04-26 22:50:17 +00:00
|
|
|
use mentat_core::{
|
|
|
|
ValueType,
|
2018-03-12 22:18:50 +00:00
|
|
|
ValueTypeSet,
|
2017-04-26 22:50:17 +00:00
|
|
|
};
|
2017-04-17 20:14:30 +00:00
|
|
|
|
2017-03-16 19:16:56 +00:00
|
|
|
use self::mentat_query::{
|
|
|
|
PlainSymbol,
|
|
|
|
};
|
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
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)]
|
2017-04-26 22:50:17 +00:00
|
|
|
pub enum BindingError {
|
|
|
|
NoBoundVariable,
|
2017-06-12 21:19:35 +00:00
|
|
|
UnexpectedBinding,
|
2017-04-26 22:50:17 +00:00
|
|
|
RepeatedBoundVariable, // TODO: include repeated variable(s).
|
2017-06-12 21:24:56 +00:00
|
|
|
|
|
|
|
/// Expected `[[?x ?y]]` but got some other type of binding. Mentat is deliberately more strict
|
|
|
|
/// than Datomic: we won't try to make sense of non-obvious (and potentially erroneous) bindings.
|
|
|
|
ExpectedBindRel,
|
|
|
|
|
2018-04-16 21:08:00 +00:00
|
|
|
/// Expected `[[?x ?y]]` or `[?x ...]` but got some other type of binding. Mentat is
|
|
|
|
/// deliberately more strict than Datomic: we won't try to make sense of non-obvious (and
|
|
|
|
/// potentially erroneous) bindings.
|
|
|
|
ExpectedBindRelOrBindColl,
|
|
|
|
|
2017-06-12 21:24:56 +00:00
|
|
|
/// Expected `[?x1 … ?xN]` or `[[?x1 … ?xN]]` but got some other number of bindings. Mentat is
|
|
|
|
/// deliberately more strict than Datomic: we prefer placeholders to omission.
|
|
|
|
InvalidNumberOfBindings { number: usize, expected: usize },
|
2017-04-26 22:50:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[derive(Debug, Fail)]
|
|
|
|
pub enum AlgebrizerError {
|
|
|
|
#[fail(display = "{} var {} is duplicated", _0, _1)]
|
|
|
|
DuplicateVariableError(PlainSymbol, &'static str),
|
2017-03-16 19:16:56 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "unexpected FnArg")]
|
|
|
|
UnsupportedArgument,
|
2017-06-14 23:17:25 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "value of type {} provided for var {}, expected {}", _0, _1, _2)]
|
|
|
|
InputTypeDisagreement(PlainSymbol, ValueType, ValueType),
|
2017-04-17 20:14:30 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "invalid number of arguments to {}: expected {}, got {}.", _0, _1, _2)]
|
|
|
|
InvalidNumberOfArguments(PlainSymbol, usize, usize),
|
2018-03-12 22:18:50 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "invalid argument to {}: expected {} in position {}.", _0, _1, _2)]
|
|
|
|
InvalidArgument(PlainSymbol, &'static str, usize),
|
2018-01-20 03:21:04 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "invalid argument to {}: expected one of {:?} in position {}.", _0, _1, _2)]
|
|
|
|
InvalidArgumentType(PlainSymbol, ValueTypeSet, usize),
|
2017-04-26 22:50:17 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
// TODO: flesh this out.
|
|
|
|
#[fail(display = "invalid expression in ground constant")]
|
|
|
|
InvalidGroundConstant,
|
2017-04-26 22:50:17 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "invalid limit {} of type {}: expected natural number.", _0, _1)]
|
|
|
|
InvalidLimit(String, ValueType),
|
2017-04-26 22:31:09 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "mismatched bindings in ground")]
|
|
|
|
GroundBindingsMismatch,
|
2018-03-12 22:18:50 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "no entid found for ident: {}", _0)]
|
|
|
|
UnrecognizedIdent(String),
|
2017-03-24 20:09:32 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "no function named {}", _0)]
|
|
|
|
UnknownFunction(PlainSymbol),
|
2017-04-19 23:16:19 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = ":limit var {} not present in :in", _0)]
|
|
|
|
UnknownLimitVar(PlainSymbol),
|
2017-04-28 09:44:11 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "unbound variable {} in order clause or function call", _0)]
|
|
|
|
UnboundVariable(PlainSymbol),
|
2018-05-31 21:10:49 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
// TODO: flesh out.
|
|
|
|
#[fail(display = "non-matching variables in 'or' clause")]
|
|
|
|
NonMatchingVariablesInOrClause,
|
2018-05-31 21:10:49 +00:00
|
|
|
|
2018-06-01 02:31:21 +00:00
|
|
|
#[fail(display = "non-matching variables in 'not' clause")]
|
|
|
|
NonMatchingVariablesInNotClause,
|
2017-03-16 19:16:56 +00:00
|
|
|
}
|