Parameterize lesser_block_end.
Only works with static strings right now.
This commit is contained in:
parent
47844caa5c
commit
f3393417bb
@ -42,12 +42,13 @@ pub fn lesser_block<'r, 's>(
|
||||
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
let lesser_block_end_specialized = lesser_block_end("comment");
|
||||
let parser_context = context
|
||||
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
||||
.with_additional_node(ContextElement::Context("lesser block"))
|
||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
exit_matcher: &lesser_block_end,
|
||||
exit_matcher: &lesser_block_end_specialized,
|
||||
}));
|
||||
let parameters = match parameters {
|
||||
Some((_ws, parameters)) => Some(parameters),
|
||||
@ -65,7 +66,7 @@ pub fn lesser_block<'r, 's>(
|
||||
(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) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
@ -92,16 +93,16 @@ fn data<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
is_not("\r\n")(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn lesser_block_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
start_of_line(context, input)?;
|
||||
let current_name = "comment"; // TODO
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, _name, _ws)) = tuple((
|
||||
tag_no_case("#+end_"),
|
||||
tag_no_case(current_name),
|
||||
alt((eof, line_ending)),
|
||||
))(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, source))
|
||||
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 {
|
||||
move |context: Context, input: &str| {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, _name, _ws)) = tuple((
|
||||
tag_no_case("#+end_"),
|
||||
tag_no_case(current_name),
|
||||
alt((eof, line_ending)),
|
||||
))(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, source))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user