aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser/pair_ext_parse.rs
diff options
context:
space:
mode:
authorPhilipp A2018-12-08 00:43:20 +0100
committerPhilipp A2018-12-08 00:43:20 +0100
commit96b5685ef6e74d2be4f43b96e3862abdfc0fcb0d (patch)
tree0850a35aad640b111dc6321f6b5eb9d5d81ddc93 /src/parser/pair_ext_parse.rs
parenteb416cc02b1ec8dbd3073dc6e2c0f80ae53dab9e (diff)
downloadrust-rst-96b5685ef6e74d2be4f43b96e3862abdfc0fcb0d.tar.bz2
some todos
Diffstat (limited to 'src/parser/pair_ext_parse.rs')
-rw-r--r--src/parser/pair_ext_parse.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/parser/pair_ext_parse.rs b/src/parser/pair_ext_parse.rs
index 2ce642a..c7d2d45 100644
--- a/src/parser/pair_ext_parse.rs
+++ b/src/parser/pair_ext_parse.rs
@@ -1,5 +1,6 @@
use std::str::FromStr;
+use pest::Span;
use pest::iterators::Pair;
use pest::error::{Error,ErrorVariant};
@@ -10,9 +11,11 @@ pub trait PairExt<R> where R: pest::RuleType {
impl<'l, R> PairExt<R> for Pair<'l, R> where R: pest::RuleType {
fn parse<T, E>(&self) -> Result<T, Error<R>> where T: FromStr<Err = E>, E: ToString {
- self.as_str().parse().map_err(|e: T::Err| {
- let var: ErrorVariant<R> = ErrorVariant::CustomError { message: e.to_string() };
- Error::new_from_span(var, self.as_span())
- })
+ self.as_str().parse().map_err(|e| to_parse_error(self.as_span(), &e))
}
}
+
+pub(crate) fn to_parse_error<E, R>(span: Span, e: &E) -> Error<R> where E: ToString, R: pest::RuleType {
+ let var: ErrorVariant<R> = ErrorVariant::CustomError { message: e.to_string() };
+ Error::new_from_span(var, span)
+}