Fixing more errors.

This commit is contained in:
Tom Alexander
2023-09-03 11:05:34 -04:00
parent b54c6d366c
commit cd69e08516
5 changed files with 106 additions and 70 deletions

View File

@@ -13,10 +13,16 @@ use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::util::get_consumed;
use crate::context::parser_with_context;
use crate::context::ContextElement;
use crate::context::ContextMatcher;
use crate::context::ExitClass;
use crate::context::ExitMatcherNode;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::start_of_line;
use crate::parser::LatexEnvironment;
use crate::types::LatexEnvironment;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn latex_environment<'r, 's>(
@@ -34,11 +40,11 @@ pub fn latex_environment<'r, 's>(
))(remaining)?;
let latex_environment_end_specialized = latex_environment_end(name.into());
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
exit_matcher: &latex_environment_end_specialized,
}));
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
exit_matcher: &latex_environment_end_specialized,
});
let parser_context = context.with_additional_node(&parser_context);
let (remaining, _contents) = contents(&latex_environment_end_specialized, context, remaining)?;
let (remaining, _end) = latex_environment_end_specialized(&parser_context, remaining)?;
@@ -62,12 +68,13 @@ fn name<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
tracing::instrument(ret, level = "debug", skip(end_matcher))
)]
pub fn contents<
'b,
'r,
's,
F: Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>,
F: Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>,
>(
end_matcher: F,
context: RefContext<'_, 'r, 's>,
context: RefContext<'b, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let (remaining, source) = recognize(many_till(
@@ -81,11 +88,9 @@ pub fn contents<
Ok((remaining, source))
}
fn latex_environment_end(
current_name: &str,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
fn latex_environment_end(current_name: &str) -> impl ContextMatcher {
let current_name_lower = current_name.to_lowercase();
move |context: Context, input: OrgSource<'_>| {
move |context, input: OrgSource<'_>| {
_latex_environment_end(context, input, current_name_lower.as_str())
}
}