Add support for parsing the planning element in sections.

This commit is contained in:
Tom Alexander 2023-04-21 21:39:26 -04:00
parent 2ec1d4f855
commit f5099356a1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -6,6 +6,7 @@ use crate::parser::object_parser::standard_set_object;
use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ContextTree; use crate::parser::parser_context::ContextTree;
use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_context::ExitMatcherNode;
use crate::parser::planning::planning;
use crate::parser::property_drawer::property_drawer; use crate::parser::property_drawer::property_drawer;
use crate::parser::util::blank_line; use crate::parser::util::blank_line;
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
@ -168,20 +169,27 @@ fn section<'r, 's>(context: Context<'r, 's>, mut input: &'s str) -> Res<&'s str,
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);
// TODO: Match whatever a planning is. // TODO: Match whatever a planning is.
let (mut remaining, property_drawer_element) = let (mut remaining, (planning_element, property_drawer_element)) = tuple((
opt(parser_with_context!(property_drawer)(&parser_context))(input)?; opt(parser_with_context!(planning)(&parser_context)),
if property_drawer_element.is_none() { opt(parser_with_context!(property_drawer)(&parser_context)),
))(input)?;
if planning_element.is_none() && property_drawer_element.is_none() {
let (remain, _ws) = many0(blank_line)(remaining)?; let (remain, _ws) = many0(blank_line)(remaining)?;
remaining = remain; remaining = remain;
input = remain; input = remain;
} }
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.is_empty() || property_drawer_element.is_some(), |(children, _exit_contents)| {
!children.is_empty() || property_drawer_element.is_some() || planning_element.is_some()
},
)(remaining)?; )(remaining)?;
property_drawer_element property_drawer_element
.map(Element::PropertyDrawer) .map(Element::PropertyDrawer)
.map(|ele| children.insert(0, ele)); .map(|ele| children.insert(0, ele));
planning_element
.map(Element::Planning)
.map(|ele| children.insert(0, ele));
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)?;