Parameterize lesser_block_end.

Only works with static strings right now.
This commit is contained in:
Tom Alexander 2023-04-21 17:11:27 -04:00
parent 47844caa5c
commit f3393417bb
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -42,12 +42,13 @@ pub fn lesser_block<'r, 's>(
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
let (remaining, _nl) = line_ending(remaining)?; let (remaining, _nl) = line_ending(remaining)?;
let lesser_block_end_specialized = lesser_block_end("comment");
let parser_context = context let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
.with_additional_node(ContextElement::Context("lesser block")) .with_additional_node(ContextElement::Context("lesser block"))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta, class: ExitClass::Beta,
exit_matcher: &lesser_block_end, exit_matcher: &lesser_block_end_specialized,
})); }));
let parameters = match parameters { let parameters = match parameters {
Some((_ws, parameters)) => Some(parameters), Some((_ws, parameters)) => Some(parameters),
@ -65,7 +66,7 @@ pub fn lesser_block<'r, 's>(
(remaining, children) (remaining, children)
} }
}; };
let (remaining, _end) = lesser_block_end(&parser_context, remaining)?; let (remaining, _end) = lesser_block_end_specialized(&parser_context, remaining)?;
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)?;
@ -92,10 +93,9 @@ fn data<'s>(input: &'s str) -> Res<&'s str, &'s str> {
is_not("\r\n")(input) is_not("\r\n")(input)
} }
#[tracing::instrument(ret, level = "debug")] fn lesser_block_end<'x>(current_name: &'x str) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str> + 'x {
fn lesser_block_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { move |context: Context, input: &str| {
start_of_line(context, input)?; start_of_line(context, input)?;
let current_name = "comment"; // TODO
let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _leading_whitespace) = space0(input)?;
let (remaining, (_begin, _name, _ws)) = tuple(( let (remaining, (_begin, _name, _ws)) = tuple((
tag_no_case("#+end_"), tag_no_case("#+end_"),
@ -105,3 +105,4 @@ fn lesser_block_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s
let source = get_consumed(input, remaining); let source = get_consumed(input, remaining);
Ok((remaining, source)) Ok((remaining, source))
} }
}