Change description format
Descriptions must now be prefixed by a '#' symbol instead of indented.
This commit is contained in:
parent
76eed7f30d
commit
d7c843ed86
3 changed files with 24 additions and 27 deletions
|
|
@ -213,7 +213,7 @@ pub struct Task {
|
||||||
pub until: Option<NaiveDate>,
|
pub until: Option<NaiveDate>,
|
||||||
pub except: Vec<NaiveDate>,
|
pub except: Vec<NaiveDate>,
|
||||||
pub done: Vec<Done>,
|
pub done: Vec<Done>,
|
||||||
pub desc: Option<String>,
|
pub desc: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -223,7 +223,7 @@ pub struct Note {
|
||||||
pub from: Option<NaiveDate>,
|
pub from: Option<NaiveDate>,
|
||||||
pub until: Option<NaiveDate>,
|
pub until: Option<NaiveDate>,
|
||||||
pub except: Vec<NaiveDate>,
|
pub except: Vec<NaiveDate>,
|
||||||
pub desc: Option<String>,
|
pub desc: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -236,7 +236,7 @@ pub struct BirthdaySpec {
|
||||||
pub struct Birthday {
|
pub struct Birthday {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub when: BirthdaySpec,
|
pub when: BirthdaySpec,
|
||||||
pub desc: Option<String>,
|
pub desc: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
29
src/parse.rs
29
src/parse.rs
|
|
@ -24,7 +24,9 @@ fn fail<S: Into<String>, T>(span: Span, message: S) -> Result<T> {
|
||||||
|
|
||||||
fn parse_title(p: Pair<Rule>) -> Result<String> {
|
fn parse_title(p: Pair<Rule>) -> Result<String> {
|
||||||
assert_eq!(p.as_rule(), Rule::title);
|
assert_eq!(p.as_rule(), Rule::title);
|
||||||
Ok(p.into_inner().next().unwrap().as_str().to_string())
|
let p = p.into_inner().next().unwrap();
|
||||||
|
assert_eq!(p.as_rule(), Rule::rest_some);
|
||||||
|
Ok(p.as_str().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_datum(p: Pair<Rule>) -> Result<NaiveDate> {
|
fn parse_datum(p: Pair<Rule>) -> Result<NaiveDate> {
|
||||||
|
|
@ -94,23 +96,20 @@ fn parse_options(p: Pair<Rule>) -> Result<Options> {
|
||||||
Ok(opts)
|
Ok(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_indented_line(p: Pair<Rule>) -> Result<String> {
|
fn parse_desc_line(p: Pair<Rule>) -> Result<String> {
|
||||||
assert_eq!(p.as_rule(), Rule::indented_line);
|
assert_eq!(p.as_rule(), Rule::desc_line);
|
||||||
Ok(p.as_str().to_string())
|
Ok(match p.into_inner().next() {
|
||||||
|
None => "".to_string(),
|
||||||
|
Some(p) => {
|
||||||
|
assert_eq!(p.as_rule(), Rule::rest_any);
|
||||||
|
p.as_str().to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_description(p: Pair<Rule>) -> Result<Option<String>> {
|
fn parse_description(p: Pair<Rule>) -> Result<Vec<String>> {
|
||||||
assert_eq!(p.as_rule(), Rule::description);
|
assert_eq!(p.as_rule(), Rule::description);
|
||||||
|
p.into_inner().map(parse_desc_line).collect()
|
||||||
let lines = p
|
|
||||||
.into_inner()
|
|
||||||
.map(parse_indented_line)
|
|
||||||
.collect::<Result<Vec<String>>>()?;
|
|
||||||
|
|
||||||
// TODO Strip whitespace prefix
|
|
||||||
|
|
||||||
let desc = lines.join("\n").trim_end().to_string();
|
|
||||||
Ok(if desc.is_empty() { None } else { Some(desc) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_task(p: Pair<Rule>) -> Result<Task> {
|
fn parse_task(p: Pair<Rule>) -> Result<Task> {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
eol = _{ NEWLINE | EOI }
|
eol = _{ NEWLINE | EOI }
|
||||||
WHITESPACE = _{ !eol ~ WHITE_SPACE }
|
WHITESPACE = _{ !eol ~ WHITE_SPACE }
|
||||||
rest = { (!eol ~ ANY)+ }
|
rest_some = { (!eol ~ ANY)+ }
|
||||||
|
rest_any = { (!eol ~ ANY)* }
|
||||||
|
|
||||||
title = { WHITESPACE ~ rest ~ eol }
|
title = { WHITESPACE ~ rest_some ~ eol }
|
||||||
|
|
||||||
year = @{ ASCII_DIGIT{4} }
|
year = @{ ASCII_DIGIT{4} }
|
||||||
month = @{ ASCII_DIGIT{2} }
|
month = @{ ASCII_DIGIT{2} }
|
||||||
|
|
@ -72,12 +73,8 @@ except = !{ "EXCEPT" ~ datum ~ eol }
|
||||||
donedate = { "(" ~ datum ~ time ~ ")" }
|
donedate = { "(" ~ datum ~ time ~ ")" }
|
||||||
done = !{ "DONE" ~ datum? ~ donedate? ~ eol }
|
done = !{ "DONE" ~ datum? ~ donedate? ~ eol }
|
||||||
|
|
||||||
// I need to use `NEWLINE` for the empty line here. Otherwise, the parser gets
|
desc_line = { "#" ~ (" " ~ rest_any)? ~ eol }
|
||||||
// into an endless loop at the `EOI` since `indented*` can appear at the end of
|
description = { desc_line* }
|
||||||
// the file and would just repeatedly match the empty string.
|
|
||||||
indented_line = @{ NEWLINE | WHITESPACE ~ rest ~ eol }
|
|
||||||
|
|
||||||
description = { indented_line* }
|
|
||||||
|
|
||||||
task_options = { (date | from | until | except | done)* }
|
task_options = { (date | from | until | except | done)* }
|
||||||
|
|
||||||
|
|
@ -104,6 +101,7 @@ birthday = {
|
||||||
~ description
|
~ description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
empty_line = _{ WHITESPACE* ~ NEWLINE }
|
||||||
command = { task | note | birthday }
|
command = { task | note | birthday }
|
||||||
|
|
||||||
file = ${ SOI ~ NEWLINE* ~ command* ~ EOI }
|
file = ${ SOI ~ (empty_line* ~ command)* ~ empty_line* ~ WHITESPACE* ~ EOI }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue