Detect the opening and build the context.

This commit is contained in:
Tom Alexander 2023-04-19 17:03:46 -04:00
parent 18f8e2562e
commit 2137b08e42
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1,9 +1,23 @@
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;
use super::Context;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::error::Res;
use crate::parser::exiting::ExitClass;
use crate::parser::greater_element::PropertyDrawer;
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ExitMatcherNode;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::immediate_in_section;
use crate::parser::util::start_of_line;
#[tracing::instrument(ret, level = "debug")]
pub fn property_drawer<'r, 's>(
@ -15,22 +29,24 @@ pub fn property_drawer<'r, 's>(
"Cannot nest objects of the same element",
))));
}
// start_of_line(context, input)?;
// let (remaining, _leading_whitespace) = space0(input)?;
// let (remaining, (_open_colon, drawer_name, _close_colon, _new_line)) = tuple((
// tag(":"),
// name,
// tag(":"),
// recognize(tuple((space0, line_ending))),
// ))(remaining)?;
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)?;
// let parser_context = context
// .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
// .with_additional_node(ContextElement::Context("drawer"))
// .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
// class: ExitClass::Alpha,
// exit_matcher: &drawer_end,
// }));
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,
}));
// let element_matcher = parser_with_context!(element)(&parser_context);
// let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
@ -61,3 +77,14 @@ pub fn property_drawer<'r, 's>(
// ))
todo!()
}
#[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)
}