Skip to content
Permalink
Browse files

No need to pass input type

  • Loading branch information
badboy committed Jul 19, 2015
1 parent fc9a196 commit 72cc6a0d257dd0fbac38ce120a8e32e35868b8bf
Showing with 36 additions and 36 deletions.
  1. +14 −14 src/easy.rs
  2. +22 −22 src/lib.rs
@@ -6,35 +6,35 @@ use super::{Date,Time,DateTime};

use macros::{take_2_digits,take_4_digits};

named!(sign <&[u8], i32>, alt!(
named!(sign <i32>, alt!(
tag!("-") => { |_| -1 } |
tag!("+") => { |_| 1 }
)
);

named!(positive_year <&[u8], i32>, map!(call!(take_4_digits), buf_to_i32));
named!(pub year <&[u8], i32>, chain!(
named!(positive_year <i32>, map!(call!(take_4_digits), buf_to_i32));
named!(pub year <i32>, chain!(
pref: opt!(sign) ~
y: positive_year
,
|| {
pref.unwrap_or(1) * y
}));

named!(pub month <&[u8], u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub day <&[u8], u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub month <u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub day <u32>, map!(call!(take_2_digits), buf_to_u32));

named!(pub date <&[u8], Date>, chain!(
named!(pub date <Date>, chain!(
y: year ~ tag!("-") ~ m: month ~ tag!("-") ~ d: day
, || { Date{ year: y, month: m, day: d }
}
));

named!(pub hour <&[u8], u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub minute <&[u8], u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub second <&[u8], u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub hour <u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub minute <u32>, map!(call!(take_2_digits), buf_to_u32));
named!(pub second <u32>, map!(call!(take_2_digits), buf_to_u32));

named!(pub time <&[u8], Time>, chain!(
named!(pub time <Time>, chain!(
h: hour ~
tag!(":") ~
m: minute ~
@@ -48,7 +48,7 @@ named!(pub time <&[u8], Time>, chain!(
}
));

named!(timezone_hour <&[u8], i32>, chain!(
named!(timezone_hour <i32>, chain!(
s: sign ~
h: hour ~
m: empty_or!(
@@ -59,10 +59,10 @@ named!(timezone_hour <&[u8], i32>, chain!(
|| { (s * (h as i32) * 3600) + (m.unwrap_or(0) * 60) as i32 }
));

named!(timezone_utc <&[u8], i32>, map!(tag!("Z"), |_| 0));
named!(timezone <&[u8], i32>, alt!(timezone_utc | timezone_hour));
named!(timezone_utc <i32>, map!(tag!("Z"), |_| 0));
named!(timezone <i32>, alt!(timezone_utc | timezone_hour));

named!(pub datetime <&[u8], DateTime>, chain!(
named!(pub datetime <DateTime>, chain!(
d: date ~
tag!("T") ~
t: time ~
@@ -72,7 +72,7 @@ impl DateTime {

named!(year_prefix, alt!(tag!("+") | tag!("-")));

named!(pub year <&[u8], i32>, chain!(
named!(pub year <i32>, chain!(
pref: opt!(year_prefix) ~
year: call!(take_4_digits)
,
@@ -83,19 +83,19 @@ named!(pub year <&[u8], i32>, chain!(
}
}));

named!(lower_month <&[u8], u32>, chain!(tag!("0") ~ s:char_between!('1', '9') , || buf_to_u32(s)));
named!(upper_month <&[u8], u32>, chain!(tag!("1") ~ s:char_between!('0', '2') , || 10+buf_to_u32(s)));
named!(lower_month <u32>, chain!(tag!("0") ~ s:char_between!('1', '9') , || buf_to_u32(s)));
named!(upper_month <u32>, chain!(tag!("1") ~ s:char_between!('0', '2') , || 10+buf_to_u32(s)));

named!(pub month <&[u8], u32>, alt!(lower_month | upper_month));
named!(pub month <u32>, alt!(lower_month | upper_month));

named!(day_zero <&[u8], u32>, chain!(tag!("0") ~ s:char_between!('1', '9') , || buf_to_u32(s)));
named!(day_one <&[u8], u32>, chain!(tag!("1") ~ s:char_between!('0', '9') , || 10+buf_to_u32(s)));
named!(day_two <&[u8], u32>, chain!(tag!("2") ~ s:char_between!('0', '9') , || 20+buf_to_u32(s)));
named!(day_three <&[u8], u32>, chain!(tag!("3") ~ s:char_between!('0', '1') , || 30+buf_to_u32(s)));
named!(day_zero <u32>, chain!(tag!("0") ~ s:char_between!('1', '9') , || buf_to_u32(s)));
named!(day_one <u32>, chain!(tag!("1") ~ s:char_between!('0', '9') , || 10+buf_to_u32(s)));
named!(day_two <u32>, chain!(tag!("2") ~ s:char_between!('0', '9') , || 20+buf_to_u32(s)));
named!(day_three <u32>, chain!(tag!("3") ~ s:char_between!('0', '1') , || 30+buf_to_u32(s)));

named!(pub day <&[u8], u32>, alt!(day_zero | day_one | day_two | day_three));
named!(pub day <u32>, alt!(day_zero | day_one | day_two | day_three));

named!(pub date <&[u8], Date>, chain!(
named!(pub date <Date>, chain!(
y: year ~
tag!("-") ~
m: month ~
@@ -106,19 +106,19 @@ named!(pub date <&[u8], Date>, chain!(
));


named!(lower_hour <&[u8], u32>, chain!(f:char_between!('0','1') ~ s:char_between!('0','9') ,
named!(lower_hour <u32>, chain!(f:char_between!('0','1') ~ s:char_between!('0','9') ,
|| { buf_to_u32(f)*10 + buf_to_u32(s) } ));
named!(upper_hour <&[u8], u32>, chain!(tag!("2") ~ s:char_between!('0','4') , || 20+buf_to_u32(s)));
named!(pub hour <&[u8], u32>, alt!(lower_hour | upper_hour));
named!(upper_hour <u32>, chain!(tag!("2") ~ s:char_between!('0','4') , || 20+buf_to_u32(s)));
named!(pub hour <u32>, alt!(lower_hour | upper_hour));

named!(below_sixty <&[u8], u32>, chain!(f:char_between!('0','5') ~ s:char_between!('0','9') ,
named!(below_sixty <u32>, chain!(f:char_between!('0','5') ~ s:char_between!('0','9') ,
|| { buf_to_u32(f)*10 + buf_to_u32(s) } ));
named!(upto_sixty <&[u8], u32>, alt!(below_sixty | map!(tag!("60"), |_| 60)));
named!(upto_sixty <u32>, alt!(below_sixty | map!(tag!("60"), |_| 60)));

named!(pub minute <&[u8], u32>, call!(below_sixty));
named!(pub second <&[u8], u32>, call!(upto_sixty));
named!(pub minute <u32>, call!(below_sixty));
named!(pub second <u32>, call!(upto_sixty));

named!(pub time <&[u8], Time>, chain!(
named!(pub time <Time>, chain!(
h: hour ~
tag!(":") ~
m: minute ~
@@ -136,7 +136,7 @@ named!(pub time <&[u8], Time>, chain!(
}
));

named!(timezone <&[u8], u32>, chain!(
named!(timezone <u32>, chain!(
tag!("+") ~
h: hour ~
empty_or!(
@@ -147,9 +147,9 @@ named!(timezone <&[u8], u32>, chain!(
|| { h }));

named!(tz_z, tag!("Z"));
named!(timezone_utc <&[u8], u32>, map!(tz_z, |_| 0));
named!(timezone_utc <u32>, map!(tz_z, |_| 0));

named!(pub time_with_timezone <&[u8], Time>, chain!(
named!(pub time_with_timezone <Time>, chain!(
t: time ~
s: empty_or!(alt!(timezone_utc | timezone))
,
@@ -163,7 +163,7 @@ named!(pub time_with_timezone <&[u8], Time>, chain!(
}
));

named!(pub datetime <&[u8], DateTime>, chain!(
named!(pub datetime <DateTime>, chain!(
d: date ~
tag!("T") ~
t: time_with_timezone

0 comments on commit 72cc6a0

Please sign in to comment.
You can’t perform that action at this time.