summaryrefslogtreecommitdiffstats
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/iterator.rs17
-rw-r--r--src/parser/mod.rs8
-rw-r--r--src/parser/timetype.rs16
3 files changed, 20 insertions, 21 deletions
diff --git a/src/parser/iterator.rs b/src/parser/iterator.rs
index a60892e..7d3007c 100644
--- a/src/parser/iterator.rs
+++ b/src/parser/iterator.rs
@@ -1,12 +1,11 @@
use nom::whitespace::sp;
-use failure::Fallible as Result;
-use failure::Error;
+use error::Result;
+use error::Error;
use parser::timetype::*;
use timetype::IntoTimeType;
use timetype;
use iter;
-use error;
named!(pub iter_spec<Iterspec>, alt_complete!(
tag!("secondly") => { |_| Iterspec::Secondly } |
@@ -91,30 +90,30 @@ impl Iterator {
Iterspec::Yearly => unit_to_amount(1, Unit::Year),
};
- let into_ndt = |e: timetype::TimeType| try!(e.calculate())
+ let into_ndt = |e: timetype::TimeType| e.calculate()?
.get_moment()
- .ok_or(error::ErrorKind::NotADateInsideIterator)
+ .ok_or(Error::NotADateInsideIterator)
.map_err(Error::from)
.map(Clone::clone);
match self.2 {
Some(UntilSpec::Exact(e)) => {
- let base = try!(into_ndt(self.0.into_timetype()?));
- let e = try!(into_ndt(e.into_timetype()?));
+ let base = into_ndt(self.0.into_timetype()?)?;
+ let e = into_ndt(e.into_timetype()?)?;
iter::Iter::build(base, recur)
.map(|it| UserIterator::UntilIterator(it.until(e)))
},
Some(UntilSpec::Times(i)) => {
- let base = try!(into_ndt(self.0.into_timetype()?));
+ let base = into_ndt(self.0.into_timetype()?)?;
iter::Iter::build(base, recur)
.map(|it| it.times(i))
.map(UserIterator::TimesIter)
},
None => {
- let base = try!(into_ndt(self.0.into_timetype()?));
+ let base = into_ndt(self.0.into_timetype()?)?;
iter::Iter::build(base, recur)
.map(UserIterator::Iterator)
},
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index c6483b4..88d0020 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -49,8 +49,8 @@ use nom::IResult;
mod timetype;
mod iterator;
-use failure::Fallible as Result;
-use error::ErrorKind as KEK;
+use error::Result;
+use error::Error;
use iter::Iter;
use timetype::IntoTimeType;
use parser::timetype::timetype;
@@ -71,8 +71,8 @@ pub fn parse(s: &str) -> Result<Parsed> {
IResult::Done(_, Ok(o)) => Ok(o),
IResult::Done(_, Err(e)) => Err(e),
IResult::Error(e) => Err(e).map_err(From::from),
- IResult::Incomplete(Needed::Unknown) => Err(KEK::UnknownParserError.into()),
- IResult::Incomplete(Needed::Size(_)) => Err(KEK::UnknownParserError.into()),
+ IResult::Incomplete(Needed::Unknown) => Err(Error::UnknownParserError),
+ IResult::Incomplete(Needed::Size(_)) => Err(Error::UnknownParserError),
}
}
diff --git a/src/parser/timetype.rs b/src/parser/timetype.rs
index 37610c3..40ae3f7 100644
--- a/src/parser/timetype.rs
+++ b/src/parser/timetype.rs
@@ -4,11 +4,11 @@ use std::str::FromStr;
use nom::digit;
use nom::whitespace::sp;
use chrono::NaiveDate;
-use failure::Fallible as Result;
use timetype::IntoTimeType;
use timetype;
-use error::ErrorKind as KEK;
+use error::Result;
+use error::Error;
named!(pub integer<i64>, alt!(
map_res!(
@@ -192,12 +192,12 @@ impl IntoTimeType for ExactDate {
ExactDate::Iso8601Date(date) => {
match date {
::iso8601::Date::YMD { year, month, day } => NaiveDate::from_ymd_opt(year, month, day)
- .ok_or(KEK::OutOfBounds(year, month, day, 0, 0, 0).into())
+ .ok_or(Error::OutOfBounds(year, month, day, 0, 0, 0))
.map(|ndt| ndt.and_hms(0, 0, 0))
.map(timetype::TimeType::moment),
::iso8601::Date::Week { year, ww, d } => NaiveDate::from_ymd_opt(year, 1, 1)
- .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into())
+ .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0))
.map(|ndt| ndt.and_hms(0, 0, 0))
.map(timetype::TimeType::moment)
.map(|m| {
@@ -207,7 +207,7 @@ impl IntoTimeType for ExactDate {
}),
::iso8601::Date::Ordinal { year, ddd } => NaiveDate::from_ymd_opt(year, 1, 1)
- .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into())
+ .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0))
.map(|ndt| ndt.and_hms(0, 0, 0))
.map(timetype::TimeType::moment)
.map(|m| m + timetype::TimeType::days(ddd as i64)),
@@ -219,11 +219,11 @@ impl IntoTimeType for ExactDate {
match date {
::iso8601::Date::YMD { year, month, day } => NaiveDate::from_ymd_opt(year, month, day)
.and_then(|ndt| ndt.and_hms_opt(hour, minute, second))
- .ok_or(KEK::OutOfBounds(year, month, day, hour, minute, second).into())
+ .ok_or(Error::OutOfBounds(year, month, day, hour, minute, second))
.map(timetype::TimeType::moment),
::iso8601::Date::Week { year, ww, d } => NaiveDate::from_ymd_opt(year, 1, 1)
- .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into())
+ .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0))
.map(|ndt| ndt.and_hms(0, 0, 0))
.map(timetype::TimeType::moment)
.map(|m| {
@@ -236,7 +236,7 @@ impl IntoTimeType for ExactDate {
}),
::iso8601::Date::Ordinal { year, ddd } => NaiveDate::from_ymd_opt(year, 1, 1)
- .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into())
+ .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0))
.map(|ndt| ndt.and_hms(0, 0, 0))
.map(timetype::TimeType::moment)
.map(|m| {