diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-10-29 20:26:51 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-10-29 20:26:51 +0100 |
commit | 645f6a332a649d5bad9c60f0b07d7084901e5cb9 (patch) | |
tree | 1ec393ec1bcf87f39f6621688ba70351a9f406e1 | |
parent | e74f49e712a0479c839dac4354ffb3b3073cfe86 (diff) |
Break amount expression parsing into multiple parts
-rw-r--r-- | src/parser.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/parser.rs b/src/parser.rs index 0a2ecb8..9ca8f16 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -138,10 +138,17 @@ pub enum Iterspec { use nom::whitespace::sp; +named!(amount_expr_next<(Operator, Box<AmountExpr>)>, do_parse!( + op:operator_parser + >> opt!(sp) + >> amexp:amount_expr + >> ((op, Box::new(amexp))) +)); + named!(amount_expr<AmountExpr>, do_parse!( amount:amount_parser >> opt!(sp) >> - o: opt!(do_parse!(op:operator_parser >> opt!(sp) >> amexp:amount_expr >> ((op, Box::new(amexp))))) >> + o: opt!(amount_expr_next) >> (AmountExpr { amount: amount, next: o, }) )); @@ -285,6 +292,17 @@ mod tests { } #[test] + fn test_amountexpr_next() { + assert_eq!(amount_expr_next(&b"+ 12minutes"[..]), + IResult::Done(&b""[..], + ( + Operator::Plus, + Box::new(AmountExpr { amount: Amount(12, Unit::Minute), next: None }) + ) + )); + } + + #[test] fn test_amountexpr() { assert_eq!(amount_expr(&b"5minutes"[..]), IResult::Done(&b""[..], |