diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-08-03 14:22:34 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-08-03 14:22:34 +0200 |
| commit | dc2db9dc8c89c2cf966bbc74a8d1ddfaea01c410 (patch) | |
| tree | 1f13acde70e7b01e9d484399375f851dc77eaf02 | |
| parent | ee3bb3cce727f96ee2bc7cc8d9d320706eace5c2 (diff) | |
| download | money-dc2db9dc8c89c2cf966bbc74a8d1ddfaea01c410.tar.gz | |
parse constraint::category
| -rw-r--r-- | cli/src/search.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/cli/src/search.rs b/cli/src/search.rs index c25b458..5d2a53a 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -1,5 +1,5 @@ use chrono::{naive::NaiveDate, Duration}; -use nom::{branch::alt, bytes::complete::is_not, character::complete::{alphanumeric1, char}, combinator::{map, recognize}, complete::tag, sequence::{delimited, preceded, terminated, tuple}}; +use nom::{branch::alt, bytes::complete::{is_not, tag}, character::complete::{alphanumeric1, char}, combinator::{map, recognize}, sequence::{delimited, preceded}}; use rust_decimal::Decimal; use std::str::FromStr; @@ -8,6 +8,7 @@ use crate::transaction::{Category, Transaction}; //TODO tests #[derive(Clone)] +#[derive(Debug)] pub enum DateIsh { Absolute(NaiveDate), Relative(Duration), @@ -39,6 +40,7 @@ impl DateIsh { } #[derive(Clone)] +#[derive(Debug)] pub enum Comparison { Equal, Greater, @@ -64,6 +66,7 @@ fn parse_comparison(s: &str) -> Option<(Decimal, Comparison)> { } #[derive(Clone)] +#[derive(Debug)] pub enum Constraint { Category(Category), Before(DateIsh), @@ -101,7 +104,13 @@ impl Constraint { } fn parse(i: &str) -> nom::IResult<&str, Self> { - todo!() + map( + preceded( + tag("category:"), + string, + ), + |c| Constraint::Category(c.to_string()) + )(i) } } @@ -113,6 +122,7 @@ fn string(i: &str) -> nom::IResult<&str, &str> { } #[derive(Clone)] +#[derive(Debug)] pub enum Filter { Union(Constraint), Intersect(Constraint), @@ -120,7 +130,7 @@ pub enum Filter { } impl Filter { - fn parse(i: &str) -> nom::IResult<&str, Self> { + pub fn parse(i: &str) -> nom::IResult<&str, Self> { alt(( map( preceded( |
