diff --git a/query-parser/src/errors.rs b/query-parser/src/errors.rs new file mode 100644 index 00000000..990112ba --- /dev/null +++ b/query-parser/src/errors.rs @@ -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) + } + } +} diff --git a/query-parser/src/lib.rs b/query-parser/src/lib.rs index 1c035276..c6939efc 100644 --- a/query-parser/src/lib.rs +++ b/query-parser/src/lib.rs @@ -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, }; diff --git a/query-parser/src/parse.rs b/query-parser/src/parse.rs index 49659632..545ed38b 100644 --- a/query-parser/src/parse.rs +++ b/query-parser/src/parse.rs @@ -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, {