Fix requiring no space between comment and property drawer for zeroth section.

This commit is contained in:
Tom Alexander 2023-04-19 19:22:23 -04:00
parent 603cc131a0
commit 4e65d2cda9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 13 additions and 14 deletions

View File

@ -127,28 +127,26 @@ fn zeroth_section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
let element_matcher = parser_with_context!(element)(&parser_context); let element_matcher = parser_with_context!(element)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (comment_element, property_drawer_element)) = tuple(( let (remaining, comment_and_property_drawer_element) = opt(tuple((
opt(parser_with_context!(comment)( opt(parser_with_context!(comment)(
&without_consuming_whitespace_context, &without_consuming_whitespace_context,
)), )),
opt(parser_with_context!(property_drawer)( parser_with_context!(property_drawer)(&without_consuming_whitespace_context),
&without_consuming_whitespace_context, )))(input)?;
)),
))(input)?;
let (remaining, (mut children, _exit_contents)) = verify( let (remaining, (mut children, _exit_contents)) = verify(
many_till(element_matcher, exit_matcher), many_till(element_matcher, exit_matcher),
|(children, _exit_contents)| { |(children, _exit_contents)| {
!children.is_empty() || property_drawer_element.is_some() || comment_element.is_some() !children.is_empty() || comment_and_property_drawer_element.is_some()
}, },
)(remaining)?; )(remaining)?;
property_drawer_element
.map(Element::PropertyDrawer) comment_and_property_drawer_element.map(|(comment, property_drawer)| {
.map(|ele| children.insert(0, ele)); children.insert(0, Element::PropertyDrawer(property_drawer));
comment_element comment
.map(Element::Comment) .map(Element::Comment)
.map(|ele| children.insert(0, ele)); .map(|ele| children.insert(0, ele));
// children.insert(0, item) });
let (remaining, _trailing_ws) = let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;

View File

@ -1,5 +1,6 @@
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::bytes::complete::tag_no_case;
use nom::bytes::complete::take_while; use nom::bytes::complete::take_while;
use nom::character::complete::line_ending; use nom::character::complete::line_ending;
use nom::character::complete::space0; use nom::character::complete::space0;
@ -92,7 +93,7 @@ fn drawer_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
start_of_line(context, input)?; start_of_line(context, input)?;
recognize(tuple(( recognize(tuple((
space0, space0,
tag(":end:"), tag_no_case(":end:"),
space0, space0,
alt((line_ending, eof)), alt((line_ending, eof)),
)))(input) )))(input)