Convert all functions to using the wrapped input type.
Some checks failed
rust-test Build rust-test has failed
rust-build Build rust-build has failed

This commit is contained in:
Tom Alexander
2023-08-23 00:30:26 -04:00
parent b7a5dd48ea
commit dab598e5e7
45 changed files with 1217 additions and 572 deletions

View File

@@ -11,6 +11,7 @@ use nom::multi::many_till;
#[cfg(feature = "tracing")]
use tracing::span;
use super::org_source::OrgSource;
use super::Context;
use crate::error::CustomError;
use crate::error::Res;
@@ -26,19 +27,27 @@ use crate::parser::InlineSourceBlock;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn inline_source_block<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, InlineSourceBlock<'s>> {
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, InlineSourceBlock<'s>> {
let (remaining, _) = tag_no_case("src_")(input)?;
let (remaining, _) = lang(context, remaining)?;
let (remaining, _header1) = opt(parser_with_context!(header)(context))(remaining)?;
let (remaining, _body) = body(context, remaining)?;
let (remaining, _) = space0(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, InlineSourceBlock { source }))
Ok((
remaining,
InlineSourceBlock {
source: source.into(),
},
))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn lang<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn lang<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
@@ -52,12 +61,18 @@ fn lang<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s st
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn lang_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn lang_end<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
recognize(one_of("[{"))(input)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn header<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn header<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let (remaining, _) = tag("[")(input)?;
let parser_context = context
@@ -81,12 +96,15 @@ fn header<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn header_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn header_end<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let context_depth = get_bracket_depth(context)
.expect("This function should only be called from inside an inline source block header.");
let text_since_context_entry = get_consumed(context_depth.position, input);
let mut current_depth = context_depth.depth;
for c in text_since_context_entry.chars() {
for c in Into::<&str>::into(text_since_context_entry).chars() {
match c {
'[' => {
current_depth += 1;
@@ -101,7 +119,7 @@ fn header_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
}
}
if current_depth == 0 {
let close_bracket = tag::<&str, &str, CustomError<&str>>("]")(input);
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
if close_bracket.is_ok() {
return close_bracket;
}
@@ -111,7 +129,10 @@ fn header_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn body<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn body<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let (remaining, _) = tag("{")(input)?;
let parser_context = context
@@ -145,12 +166,15 @@ fn body<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s st
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn body_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn body_end<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let context_depth = get_bracket_depth(context)
.expect("This function should only be called from inside an inline source block body.");
let text_since_context_entry = get_consumed(context_depth.position, input);
let mut current_depth = context_depth.depth;
for c in text_since_context_entry.chars() {
for c in Into::<&str>::into(text_since_context_entry).chars() {
match c {
'{' => {
current_depth += 1;
@@ -176,7 +200,7 @@ fn body_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'
let _enter = span.enter();
if current_depth == 0 {
let close_bracket = tag::<&str, &str, CustomError<&str>>("}")(input);
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("}")(input);
if close_bracket.is_ok() {
return close_bracket;
}