Evaluate some simple statements

This commit is contained in:
Joscha 2021-12-04 22:37:01 +01:00
parent 778576a63c
commit 3a219ecac2
6 changed files with 184 additions and 12 deletions

View file

@ -355,7 +355,11 @@ pub enum Statement {
From(Option<NaiveDate>),
Until(Option<NaiveDate>),
Except(NaiveDate), // TODO Allow excluding ranges
Move(NaiveDate, NaiveDate),
Move {
span: Span,
from: NaiveDate,
to: NaiveDate,
},
}
#[derive(Debug, Clone, Copy)]
@ -440,6 +444,22 @@ pub enum Command {
Note(Note),
}
impl Command {
pub fn title(&self) -> &str {
match self {
Command::Task(task) => &task.title,
Command::Note(note) => &note.title,
}
}
pub fn desc(&self) -> &[String] {
match self {
Command::Task(task) => &task.desc,
Command::Note(note) => &note.desc,
}
}
}
#[derive(Debug)]
pub struct File {
pub contents: String,

View file

@ -219,7 +219,7 @@ impl fmt::Display for Statement {
Statement::Until(Some(date)) => writeln!(f, "UNTIL {}", date),
Statement::Until(None) => writeln!(f, "UNTIL *"),
Statement::Except(date) => writeln!(f, "EXCEPT {}", date),
Statement::Move(from, to) => writeln!(f, "MOVE {} TO {}", from, to),
Statement::Move { span, from, to } => writeln!(f, "MOVE {} TO {}", from, to),
}
}
}

View file

@ -605,11 +605,12 @@ fn parse_stmt_except(p: Pair<'_, Rule>) -> Result<Statement> {
fn parse_stmt_move(p: Pair<'_, Rule>) -> Result<Statement> {
assert_eq!(p.as_rule(), Rule::stmt_move);
let span = (&p.as_span()).into();
let mut p = p.into_inner();
let from = parse_datum(p.next().unwrap())?.value;
let to = parse_datum(p.next().unwrap())?.value;
assert_eq!(p.next(), None);
Ok(Statement::Move(from, to))
Ok(Statement::Move { span, from, to })
}
fn parse_statements(p: Pair<'_, Rule>) -> Result<Vec<Statement>> {