2023-04-19 17:03:46 -04:00
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::bytes::complete::tag;
|
|
|
|
use nom::bytes::complete::tag_no_case;
|
|
|
|
use nom::character::complete::line_ending;
|
|
|
|
use nom::character::complete::space0;
|
|
|
|
use nom::combinator::eof;
|
|
|
|
use nom::combinator::recognize;
|
|
|
|
use nom::sequence::tuple;
|
|
|
|
|
2023-04-19 16:51:00 -04:00
|
|
|
use super::Context;
|
2023-04-19 16:54:17 -04:00
|
|
|
use crate::parser::error::CustomError;
|
|
|
|
use crate::parser::error::MyError;
|
2023-04-19 16:51:00 -04:00
|
|
|
use crate::parser::error::Res;
|
2023-04-19 17:03:46 -04:00
|
|
|
use crate::parser::exiting::ExitClass;
|
2023-04-19 16:51:00 -04:00
|
|
|
use crate::parser::greater_element::PropertyDrawer;
|
2023-04-19 17:03:46 -04:00
|
|
|
use crate::parser::parser_context::ContextElement;
|
|
|
|
use crate::parser::parser_context::ExitMatcherNode;
|
|
|
|
use crate::parser::parser_with_context::parser_with_context;
|
2023-04-19 16:54:17 -04:00
|
|
|
use crate::parser::util::immediate_in_section;
|
2023-04-19 17:03:46 -04:00
|
|
|
use crate::parser::util::start_of_line;
|
2023-04-19 16:51:00 -04:00
|
|
|
|
|
|
|
#[tracing::instrument(ret, level = "debug")]
|
|
|
|
pub fn property_drawer<'r, 's>(
|
|
|
|
context: Context<'r, 's>,
|
|
|
|
input: &'s str,
|
|
|
|
) -> Res<&'s str, PropertyDrawer<'s>> {
|
2023-04-19 16:54:17 -04:00
|
|
|
if immediate_in_section(context, "property-drawer") {
|
|
|
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
|
|
"Cannot nest objects of the same element",
|
|
|
|
))));
|
|
|
|
}
|
2023-04-19 17:03:46 -04:00
|
|
|
let (
|
|
|
|
remaining,
|
|
|
|
(_start_of_line, _leading_whitespace, open_tag, _trailing_whitespace, _line_ending),
|
|
|
|
) = tuple((
|
|
|
|
parser_with_context!(start_of_line)(context),
|
|
|
|
space0,
|
|
|
|
tag_no_case(":PROPERTIES:"),
|
|
|
|
space0,
|
|
|
|
line_ending,
|
|
|
|
))(input)?;
|
2023-04-19 16:54:17 -04:00
|
|
|
|
2023-04-19 17:03:46 -04:00
|
|
|
let parser_context = context
|
|
|
|
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
|
|
|
.with_additional_node(ContextElement::Context("property-drawer"))
|
|
|
|
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
|
|
|
class: ExitClass::Alpha,
|
|
|
|
exit_matcher: &property_drawer_end,
|
|
|
|
}));
|
2023-04-19 16:54:17 -04:00
|
|
|
|
|
|
|
// let element_matcher = parser_with_context!(element)(&parser_context);
|
|
|
|
// let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
|
|
|
// let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) {
|
|
|
|
// Ok((remaining, (whitespace, (_children, _exit_contents)))) => (
|
|
|
|
// remaining,
|
|
|
|
// vec![Element::Paragraph(Paragraph::of_text(whitespace))],
|
|
|
|
// ),
|
|
|
|
// Err(_) => {
|
|
|
|
// let (remaining, (children, _exit_contents)) =
|
|
|
|
// many_till(element_matcher, exit_matcher)(remaining)?;
|
|
|
|
// (remaining, children)
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// let (remaining, _end) = drawer_end(&parser_context, remaining)?;
|
|
|
|
|
|
|
|
// let (remaining, _trailing_ws) =
|
|
|
|
// maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
|
|
|
// let source = get_consumed(input, remaining);
|
|
|
|
|
|
|
|
// Ok((
|
|
|
|
// remaining,
|
|
|
|
// Drawer {
|
|
|
|
// source,
|
|
|
|
// name: drawer_name,
|
|
|
|
// children,
|
|
|
|
// },
|
|
|
|
// ))
|
2023-04-19 16:51:00 -04:00
|
|
|
todo!()
|
|
|
|
}
|
2023-04-19 17:03:46 -04:00
|
|
|
|
|
|
|
#[tracing::instrument(ret, level = "debug")]
|
|
|
|
fn property_drawer_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
recognize(tuple((
|
|
|
|
parser_with_context!(start_of_line)(context),
|
|
|
|
space0,
|
|
|
|
tag(":end:"),
|
|
|
|
space0,
|
|
|
|
alt((line_ending, eof)),
|
|
|
|
)))(input)
|
|
|
|
}
|