Convert all functions to using the wrapped input type.
This commit is contained in:
@@ -11,6 +11,7 @@ use nom::combinator::recognize;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::util::get_consumed;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
@@ -25,8 +26,8 @@ use crate::parser::LatexEnvironment;
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn latex_environment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, LatexEnvironment<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, LatexEnvironment<'s>> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_opening, name, _open_close_brace, _ws, _line_ending)) = tuple((
|
||||
@@ -37,7 +38,7 @@ pub fn latex_environment<'r, 's>(
|
||||
line_ending,
|
||||
))(remaining)?;
|
||||
|
||||
let latex_environment_end_specialized = latex_environment_end(name);
|
||||
let latex_environment_end_specialized = latex_environment_end(name.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
@@ -48,11 +49,16 @@ pub fn latex_environment<'r, 's>(
|
||||
let (remaining, _end) = latex_environment_end_specialized(&parser_context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, LatexEnvironment { source }))
|
||||
Ok((
|
||||
remaining,
|
||||
LatexEnvironment {
|
||||
source: source.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn name<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn name<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
take_while1(|c: char| c.is_alphanumeric() || c == '*')(input)
|
||||
}
|
||||
|
||||
@@ -60,11 +66,15 @@ fn name<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(end_matcher))
|
||||
)]
|
||||
pub fn contents<'r, 's, F: Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str>>(
|
||||
pub fn contents<
|
||||
'r,
|
||||
's,
|
||||
F: Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>,
|
||||
>(
|
||||
end_matcher: F,
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, source) = recognize(many_till(
|
||||
anychar,
|
||||
peek(alt((
|
||||
@@ -78,9 +88,9 @@ pub fn contents<'r, 's, F: Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str>
|
||||
|
||||
fn latex_environment_end(
|
||||
current_name: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str> {
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let current_name_lower = current_name.to_lowercase();
|
||||
move |context: Context, input: &str| {
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_latex_environment_end(context, input, current_name_lower.as_str())
|
||||
}
|
||||
}
|
||||
@@ -88,9 +98,9 @@ fn latex_environment_end(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _latex_environment_end<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
current_name_lower: &'x str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, _name, _close_brace, _ws, _line_ending)) = tuple((
|
||||
|
||||
Reference in New Issue
Block a user