Part 0: Extract query-parser errors.

This commit is contained in:
Nick Alexander 2018-05-31 12:13:28 -07:00
parent 3cc8b4fd24
commit f1fc9f1846
3 changed files with 61 additions and 59 deletions

View file

@ -0,0 +1,49 @@
// Copyright 2018 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.
#![allow(dead_code)]
use edn;
use mentat_parser_utils::{
ValueParseError,
};
error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
}
foreign_links {
EdnParseError(edn::parse::ParseError);
}
errors {
DuplicateVariableError {
description("duplicate variable")
display("duplicates in variable list")
}
FindParseError(e: ValueParseError) {
description(":find parse error")
display(":find parse error")
}
UnknownLimitVar(var: edn::PlainSymbol) {
description("limit var not present in :in")
display("limit var {} not present in :in", var)
}
InvalidLimit(val: edn::Value) {
description("limit value not valid")
display("expected natural number, got {}", val)
}
}
}

View file

@ -24,12 +24,16 @@ extern crate edn;
#[macro_use]
extern crate mentat_parser_utils;
mod errors;
mod parse;
pub use parse::{
pub use errors::{
Error,
ErrorKind,
Result,
ResultExt,
};
pub use parse::{
parse_find_string,
};

View file

@ -36,6 +36,13 @@ use self::combine::combinator::{any, choice, or, try};
use self::mentat_core::ValueType;
use errors::{
Error,
ErrorKind,
Result,
ResultExt,
};
use self::mentat_parser_utils::{
KeywordMapParser,
ResultParser,
@ -87,64 +94,6 @@ use self::mentat_query::{
WhereFn,
};
error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
}
foreign_links {
EdnParseError(edn::parse::ParseError);
}
errors {
DuplicateVariableError {
description("duplicate variable")
display("duplicates in variable list")
}
NotAVariableError(value: edn::ValueAndSpan) {
description("not a variable")
display("not a variable: '{}'", value)
}
FindParseError(e: ValueParseError) {
description(":find parse error")
display(":find parse error")
}
WhereParseError(e: ValueParseError) {
description(":where parse error")
display(":where parse error")
}
// Not yet used.
WithParseError {
description(":with parse error")
display(":with parse error")
}
InvalidInputError(value: edn::Value) {
description("invalid input")
display("invalid input: '{}'", value)
}
MissingFieldError(value: edn::Keyword) {
description("missing field")
display("missing field: '{}'", value)
}
UnknownLimitVar(var: edn::PlainSymbol) {
description("limit var not present in :in")
display("limit var {} not present in :in", var)
}
InvalidLimit(val: edn::Value) {
description("limit value not valid")
display("expected natural number, got {}", val)
}
}
}
pub struct Query<'a>(std::marker::PhantomData<&'a ()>);
def_parser!(Query, variable, Variable, {