Use the global settings todo keywords when parsing headlines.
This commit is contained in:
@@ -12,14 +12,18 @@ use nom::sequence::tuple;
|
||||
|
||||
use crate::error::Res;
|
||||
|
||||
// ref https://orgmode.org/manual/Per_002dfile-keywords.html
|
||||
// ref https://orgmode.org/manual/Workflow-states.html
|
||||
// Case is significant.
|
||||
|
||||
/// Parses the text in the value of a #+TODO keyword.
|
||||
///
|
||||
/// Example input: "foo bar baz | lorem ipsum"
|
||||
pub fn keyword_todo<'s>(input: &'s str) -> Res<&'s str, (Vec<&'s str>, Vec<&'s str>)> {
|
||||
let (remaining, mut before_pipe_words) = separated_list0(space1, keyword_word)(input)?;
|
||||
pub fn todo_keywords<'s>(input: &'s str) -> Res<&'s str, (Vec<&'s str>, Vec<&'s str>)> {
|
||||
let (remaining, mut before_pipe_words) = separated_list0(space1, todo_keyword_word)(input)?;
|
||||
let (remaining, after_pipe_words) = opt(tuple((
|
||||
tuple((space0, tag("|"), space0)),
|
||||
separated_list0(space1, keyword_word),
|
||||
separated_list0(space1, todo_keyword_word),
|
||||
)))(remaining)?;
|
||||
let (remaining, _eol) = alt((line_ending, eof))(remaining)?;
|
||||
if let Some((_pipe, after_pipe_words)) = after_pipe_words {
|
||||
@@ -39,7 +43,7 @@ pub fn keyword_todo<'s>(input: &'s str) -> Res<&'s str, (Vec<&'s str>, Vec<&'s s
|
||||
}
|
||||
}
|
||||
|
||||
fn keyword_word<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn todo_keyword_word<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
verify(take_till(|c| " \t\r\n|".contains(c)), |result: &str| {
|
||||
!result.is_empty()
|
||||
})(input)
|
||||
@@ -51,7 +55,7 @@ mod tests {
|
||||
#[test]
|
||||
fn before_and_after() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let input = "foo bar baz | lorem ipsum";
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = keyword_todo(input)?;
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = todo_keywords(input)?;
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(before_pipe_words, vec!["foo", "bar", "baz"]);
|
||||
assert_eq!(after_pipe_words, vec!["lorem", "ipsum"]);
|
||||
@@ -61,7 +65,7 @@ mod tests {
|
||||
#[test]
|
||||
fn no_pipe() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let input = "foo bar baz";
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = keyword_todo(input)?;
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = todo_keywords(input)?;
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(before_pipe_words, vec!["foo", "bar"]);
|
||||
assert_eq!(after_pipe_words, vec!["baz"]);
|
||||
@@ -71,7 +75,7 @@ mod tests {
|
||||
#[test]
|
||||
fn early_pipe() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let input = "| foo bar baz";
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = keyword_todo(input)?;
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = todo_keywords(input)?;
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(before_pipe_words, Vec::<&str>::new());
|
||||
assert_eq!(after_pipe_words, vec!["foo", "bar", "baz"]);
|
||||
@@ -81,7 +85,7 @@ mod tests {
|
||||
#[test]
|
||||
fn late_pipe() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let input = "foo bar baz |";
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = keyword_todo(input)?;
|
||||
let (remaining, (before_pipe_words, after_pipe_words)) = todo_keywords(input)?;
|
||||
assert_eq!(remaining, "");
|
||||
assert_eq!(before_pipe_words, vec!["foo", "bar", "baz"]);
|
||||
assert_eq!(after_pipe_words, Vec::<&str>::new());
|
||||
|
||||
Reference in New Issue
Block a user