Reorganize spec evaluation

This commit is contained in:
Joscha 2021-12-04 23:24:21 +01:00
parent 3a219ecac2
commit 2112272347
4 changed files with 32 additions and 23 deletions

View file

@ -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) {

View file

@ -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!()
}
}

View file

@ -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<NaiveDate>,
new_entry: impl Fn(Source, Option<DoneDate>) -> Entry,
) -> Result<()> {
impl<'a> CommandState<'a> {
pub fn eval_date_spec(&mut self, spec: DateSpec) -> Result<()> {
todo!()
}
}

View file

@ -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<DoneDate>) -> Entry,
) -> Result<()> {
impl<'a> CommandState<'a> {
pub fn eval_formula_spec(&mut self, spec: FormulaSpec) -> Result<()> {
todo!()
}
}