From 2112272347d703479ae39f8583495d67fbe1ccd7 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 4 Dec 2021 23:24:21 +0100 Subject: [PATCH] Reorganize spec evaluation --- src/eval/command.rs | 12 ++++++++++-- src/eval/command/birthday.rs | 10 ++++++++++ src/eval/{date_spec.rs => command/date.rs} | 17 ++++++----------- .../{formula_spec.rs => command/formula.rs} | 16 ++++++---------- 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 src/eval/command/birthday.rs rename src/eval/{date_spec.rs => command/date.rs} (77%) rename src/eval/{formula_spec.rs => command/formula.rs} (85%) diff --git a/src/eval/command.rs b/src/eval/command.rs index dd970ab..7bb816d 100644 --- a/src/eval/command.rs +++ b/src/eval/command.rs @@ -7,6 +7,10 @@ use crate::files::{Source, SourcedCommand}; use super::{DateRange, Entry, EntryKind, Error, Result}; +mod birthday; +mod date; +mod formula; + pub struct CommandState<'a> { command: SourcedCommand<'a>, range: DateRange, @@ -121,11 +125,15 @@ impl<'a> CommandState<'a> { } fn eval_date(&mut self, spec: &Spec) -> Result<()> { - todo!() + match spec { + Spec::Date(spec) => self.eval_date_spec(spec.into()), + Spec::Weekday(spec) => self.eval_formula_spec(spec.into()), + Spec::Formula(spec) => self.eval_formula_spec(spec.into()), + } } fn eval_bdate(&mut self, spec: &BirthdaySpec) -> Result<()> { - todo!() + self.eval_birthday_spec(spec) } fn eval_except(&mut self, date: NaiveDate) { diff --git a/src/eval/command/birthday.rs b/src/eval/command/birthday.rs new file mode 100644 index 0000000..d90d9f1 --- /dev/null +++ b/src/eval/command/birthday.rs @@ -0,0 +1,10 @@ +use crate::files::commands::BirthdaySpec; + +use super::super::command::CommandState; +use super::super::Result; + +impl<'a> CommandState<'a> { + pub fn eval_birthday_spec(&mut self, spec: &BirthdaySpec) -> Result<()> { + todo!() + } +} diff --git a/src/eval/date_spec.rs b/src/eval/command/date.rs similarity index 77% rename from src/eval/date_spec.rs rename to src/eval/command/date.rs index 377afb4..df6310f 100644 --- a/src/eval/date_spec.rs +++ b/src/eval/command/date.rs @@ -1,10 +1,10 @@ use chrono::NaiveDate; -use crate::files::commands::{self, DoneDate, Spanned, Time}; -use crate::files::Source; +use crate::files::commands::{self, Spanned, Time}; -use super::delta::{Delta, DeltaStep}; -use super::{Entry, Eval, Result}; +use super::super::command::CommandState; +use super::super::delta::{Delta, DeltaStep}; +use super::super::Result; pub struct DateSpec { pub start: NaiveDate, @@ -52,13 +52,8 @@ impl From<&commands::DateSpec> for DateSpec { } } -impl Eval { - pub fn eval_date_spec( - &mut self, - spec: DateSpec, - last_done: Option, - new_entry: impl Fn(Source, Option) -> Entry, - ) -> Result<()> { +impl<'a> CommandState<'a> { + pub fn eval_date_spec(&mut self, spec: DateSpec) -> Result<()> { todo!() } } diff --git a/src/eval/formula_spec.rs b/src/eval/command/formula.rs similarity index 85% rename from src/eval/formula_spec.rs rename to src/eval/command/formula.rs index 7321b2f..b8f26d0 100644 --- a/src/eval/formula_spec.rs +++ b/src/eval/command/formula.rs @@ -1,8 +1,8 @@ -use crate::files::commands::{self, DoneDate, Expr, Spanned, Time, Var}; -use crate::files::Source; +use crate::files::commands::{self, Expr, Spanned, Time, Var}; -use super::delta::{Delta, DeltaStep}; -use super::{Entry, Eval, Result}; +use super::super::command::CommandState; +use super::super::delta::{Delta, DeltaStep}; +use super::super::Result; pub struct FormulaSpec { // TODO Implement more efficient exprs and expr evaluation @@ -77,12 +77,8 @@ impl From<&commands::WeekdaySpec> for FormulaSpec { } } -impl Eval { - pub fn eval_formula_spec( - &mut self, - spec: FormulaSpec, - new_entry: impl Fn(Source, Option) -> Entry, - ) -> Result<()> { +impl<'a> CommandState<'a> { + pub fn eval_formula_spec(&mut self, spec: FormulaSpec) -> Result<()> { todo!() } }