Parse descriptions properly
This commit is contained in:
parent
90f74c82bc
commit
76eed7f30d
2 changed files with 7 additions and 13 deletions
12
src/parse.rs
12
src/parse.rs
|
|
@ -96,13 +96,7 @@ fn parse_options(p: Pair<Rule>) -> Result<Options> {
|
||||||
|
|
||||||
fn parse_indented_line(p: Pair<Rule>) -> Result<String> {
|
fn parse_indented_line(p: Pair<Rule>) -> Result<String> {
|
||||||
assert_eq!(p.as_rule(), Rule::indented_line);
|
assert_eq!(p.as_rule(), Rule::indented_line);
|
||||||
Ok(match p.into_inner().next() {
|
Ok(p.as_str().to_string())
|
||||||
Some(rest) => {
|
|
||||||
assert_eq!(rest.as_rule(), Rule::rest);
|
|
||||||
rest.as_str().to_string()
|
|
||||||
}
|
|
||||||
None => "".to_string(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_description(p: Pair<Rule>) -> Result<Option<String>> {
|
fn parse_description(p: Pair<Rule>) -> Result<Option<String>> {
|
||||||
|
|
@ -115,8 +109,8 @@ fn parse_description(p: Pair<Rule>) -> Result<Option<String>> {
|
||||||
|
|
||||||
// TODO Strip whitespace prefix
|
// TODO Strip whitespace prefix
|
||||||
|
|
||||||
let desc = lines.join("\n");
|
let desc = lines.join("\n").trim_end().to_string();
|
||||||
Ok(Some(desc).filter(|s| !s.is_empty()))
|
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> {
|
||||||
|
|
|
||||||
|
|
@ -72,10 +72,10 @@ except = !{ "EXCEPT" ~ datum ~ eol }
|
||||||
donedate = { "(" ~ datum ~ time ~ ")" }
|
donedate = { "(" ~ datum ~ time ~ ")" }
|
||||||
done = !{ "DONE" ~ datum? ~ donedate? ~ eol }
|
done = !{ "DONE" ~ datum? ~ donedate? ~ eol }
|
||||||
|
|
||||||
// I need to use `nl` for the empty line here. Otherwise, the parser gets into
|
// I need to use `NEWLINE` for the empty line here. Otherwise, the parser gets
|
||||||
// an endless loop at the `EOI` since `indented*` can appear at the end of the
|
// into an endless loop at the `EOI` since `indented*` can appear at the end of
|
||||||
// file and would just repeatedly match the empty string.
|
// the file and would just repeatedly match the empty string.
|
||||||
indented_line = { NEWLINE | WHITESPACE ~ rest ~ eol }
|
indented_line = @{ NEWLINE | WHITESPACE ~ rest ~ eol }
|
||||||
|
|
||||||
description = { indented_line* }
|
description = { indented_line* }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue