diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-08-02 23:22:50 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-08-02 23:22:50 +0200 |
| commit | 49e14e27165ef5dd1884e6d31cd5ff39314118be (patch) | |
| tree | 2036e8893b677734a7a2e13ad0ef2671ebbfe00a /cli/src/search.rs | |
| parent | 69d810bb850c9bacdd7dc528ed98dda0bf001e47 (diff) | |
| download | money-49e14e27165ef5dd1884e6d31cd5ff39314118be.tar.gz | |
initial nom filter parsing
Diffstat (limited to 'cli/src/search.rs')
| -rw-r--r-- | cli/src/search.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cli/src/search.rs b/cli/src/search.rs index d140caf..b11ee78 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -1,4 +1,5 @@ use chrono::{naive::NaiveDate, Duration}; +use nom::{branch::alt, character::complete::char, combinator::map, sequence::tuple}; use rust_decimal::Decimal; use std::str::FromStr; @@ -98,6 +99,10 @@ impl Constraint { } } } + + fn parse(i: &str) -> nom::IResult<&str, Self> { + todo!() + } } #[derive(Clone)] @@ -107,6 +112,28 @@ pub enum Filter { Subtract(Constraint), } +impl Filter { + fn parse(i: &str) -> nom::IResult<&str, Self> { + alt(( + map( + tuple(( + char('+'), + Constraint::parse, + )), + |(_, constraint)| Filter::Union(constraint) + ), + map( + tuple(( + char('-'), + Constraint::parse, + )), + |(_, constraint)| Filter::Subtract(constraint) + ), + map(Constraint::parse, Filter::Intersect), + ))(i) + } +} + #[derive(Clone)] pub struct Search<'t> { filtered: Vec<usize>, |
