Parse priority cookie and COMMENT from headlines.
This commit is contained in:
@@ -33,6 +33,7 @@ use crate::parser::util::blank_line;
|
||||
use crate::types::DocumentElement;
|
||||
use crate::types::Heading;
|
||||
use crate::types::Object;
|
||||
use crate::types::PriorityCookie;
|
||||
use crate::types::TodoKeywordType;
|
||||
|
||||
pub const fn heading(
|
||||
@@ -51,8 +52,10 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
parent_stars: usize,
|
||||
) -> Res<OrgSource<'s>, Heading<'s>> {
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
let (remaining, (star_count, _ws, maybe_todo_keyword, title, heading_tags)) =
|
||||
headline(context, input, parent_stars)?;
|
||||
let (
|
||||
remaining,
|
||||
(star_count, maybe_todo_keyword, maybe_priority, maybe_comment, title, heading_tags),
|
||||
) = headline(context, input, parent_stars)?;
|
||||
let section_matcher = parser_with_context!(section)(context);
|
||||
let heading_matcher = parser_with_context!(heading(star_count))(context);
|
||||
let (remaining, maybe_section) =
|
||||
@@ -70,6 +73,7 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
} else {
|
||||
remaining
|
||||
};
|
||||
let is_archived = heading_tags.contains(&"ARCHIVE");
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
@@ -80,9 +84,12 @@ fn _heading<'b, 'g, 'r, 's>(
|
||||
todo_keyword: maybe_todo_keyword.map(|((todo_keyword_type, todo_keyword), _ws)| {
|
||||
(todo_keyword_type, Into::<&str>::into(todo_keyword))
|
||||
}),
|
||||
priority_cookie: maybe_priority.map(|(priority, _)| priority),
|
||||
title,
|
||||
tags: heading_tags,
|
||||
children,
|
||||
is_comment: maybe_comment.is_some(),
|
||||
is_archived,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -102,8 +109,9 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
OrgSource<'s>,
|
||||
(
|
||||
usize,
|
||||
OrgSource<'s>,
|
||||
Option<((TodoKeywordType, OrgSource<'s>), OrgSource<'s>)>,
|
||||
Option<(PriorityCookie, OrgSource<'s>)>,
|
||||
Option<(OrgSource<'s>, OrgSource<'s>)>,
|
||||
Vec<Object<'s>>,
|
||||
Vec<&'s str>,
|
||||
),
|
||||
@@ -116,7 +124,18 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
|
||||
let (
|
||||
remaining,
|
||||
(_sol, star_count, ws, maybe_todo_keyword, title, maybe_tags, _ws, _line_ending),
|
||||
(
|
||||
_,
|
||||
star_count,
|
||||
_,
|
||||
maybe_todo_keyword,
|
||||
maybe_priority,
|
||||
maybe_comment,
|
||||
title,
|
||||
maybe_tags,
|
||||
_,
|
||||
_,
|
||||
),
|
||||
) = tuple((
|
||||
start_of_line,
|
||||
verify(many1_count(tag("*")), |star_count| {
|
||||
@@ -127,6 +146,8 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
parser_with_context!(heading_keyword)(&parser_context),
|
||||
space1,
|
||||
))),
|
||||
opt(tuple((priority_cookie, space1))),
|
||||
opt(tuple((tag("COMMENT"), space1))),
|
||||
many1(parser_with_context!(standard_set_object)(&parser_context)),
|
||||
opt(tuple((space0, tags))),
|
||||
space0,
|
||||
@@ -136,8 +157,9 @@ fn headline<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
(
|
||||
star_count,
|
||||
ws,
|
||||
maybe_todo_keyword,
|
||||
maybe_priority,
|
||||
maybe_comment,
|
||||
title,
|
||||
maybe_tags
|
||||
.map(|(_ws, tags)| {
|
||||
@@ -220,3 +242,17 @@ fn heading_keyword<'b, 'g, 'r, 's>(
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
||||
fn priority_cookie<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PriorityCookie> {
|
||||
let (remaining, (_, priority_character, _)) = tuple((
|
||||
tag("[#"),
|
||||
verify(anychar, |c| c.is_alphanumeric()),
|
||||
tag("]"),
|
||||
))(input)?;
|
||||
let cookie = PriorityCookie::try_from(priority_character).map_err(|_| {
|
||||
nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Failed to cast priority cookie to number.".into(),
|
||||
)))
|
||||
})?;
|
||||
Ok((remaining, cookie))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user