diff options
Diffstat (limited to 'cli/src/search.rs')
| -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( |
