Compare heading todo keywords.
This only handles the default case where the only valid TODO keywords are TODO and DONE.
This commit is contained in:
@@ -53,6 +53,8 @@ pub struct Document<'s> {
|
||||
pub struct Heading<'s> {
|
||||
pub source: &'s str,
|
||||
pub stars: usize,
|
||||
pub todo_keyword: Option<&'s str>,
|
||||
// TODO: add todo-type enum
|
||||
pub title: Vec<Object<'s>>,
|
||||
pub tags: Vec<&'s str>,
|
||||
pub children: Vec<DocumentElement<'s>>,
|
||||
@@ -271,7 +273,8 @@ fn heading<'r, 's>(
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Heading<'s>> {
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
let (remaining, (star_count, _ws, title, heading_tags)) = headline(context, input)?;
|
||||
let (remaining, (star_count, _ws, maybe_todo_keyword, title, heading_tags)) =
|
||||
headline(context, input)?;
|
||||
let section_matcher = parser_with_context!(section)(context);
|
||||
let heading_matcher = parser_with_context!(heading)(context);
|
||||
let (remaining, children) = many0(alt((
|
||||
@@ -287,6 +290,8 @@ fn heading<'r, 's>(
|
||||
Heading {
|
||||
source: source.into(),
|
||||
stars: star_count,
|
||||
todo_keyword: maybe_todo_keyword
|
||||
.map(|(todo_keyword, _ws)| Into::<&str>::into(todo_keyword)),
|
||||
title,
|
||||
tags: heading_tags,
|
||||
children,
|
||||
@@ -298,7 +303,16 @@ fn heading<'r, 's>(
|
||||
fn headline<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, (usize, OrgSource<'s>, Vec<Object<'s>>, Vec<&'s str>)> {
|
||||
) -> Res<
|
||||
OrgSource<'s>,
|
||||
(
|
||||
usize,
|
||||
OrgSource<'s>,
|
||||
Option<(OrgSource<'s>, OrgSource<'s>)>,
|
||||
Vec<Object<'s>>,
|
||||
Vec<&'s str>,
|
||||
),
|
||||
> {
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Document,
|
||||
@@ -306,10 +320,14 @@ fn headline<'r, 's>(
|
||||
}));
|
||||
let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context);
|
||||
|
||||
let (remaining, (_sol, star_count, ws, title, maybe_tags, _ws, _line_ending)) = tuple((
|
||||
let (
|
||||
remaining,
|
||||
(_sol, star_count, ws, maybe_todo_keyword, title, maybe_tags, _ws, _line_ending),
|
||||
) = tuple((
|
||||
start_of_line,
|
||||
many1_count(tag("*")),
|
||||
space1,
|
||||
opt(tuple((heading_keyword, space1))),
|
||||
many1(standard_set_object_matcher),
|
||||
opt(tuple((space0, tags))),
|
||||
space0,
|
||||
@@ -320,6 +338,7 @@ fn headline<'r, 's>(
|
||||
(
|
||||
star_count,
|
||||
ws,
|
||||
maybe_todo_keyword,
|
||||
title,
|
||||
maybe_tags
|
||||
.map(|(_ws, tags)| {
|
||||
@@ -357,6 +376,12 @@ fn single_tag<'r, 's>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
|
||||
})))(input)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn heading_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
// TODO: This should take into account the value of "#+TODO:" ref https://orgmode.org/manual/Per_002dfile-keywords.html and possibly the configurable variable org-todo-keywords ref https://orgmode.org/manual/Workflow-states.html. Case is significant.
|
||||
alt((tag("TODO"), tag("DONE")))(input)
|
||||
}
|
||||
|
||||
impl<'s> Document<'s> {
|
||||
pub fn iter_tokens<'r>(&'r self) -> impl Iterator<Item = Token<'r, 's>> {
|
||||
AllTokensIterator::new(Token::Document(self))
|
||||
|
||||
Reference in New Issue
Block a user