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

@@ -5,6 +5,7 @@ use nom::character::complete::space0;
use nom::combinator::verify;
use nom::multi::many_till;
use super::org_source::OrgSource;
use super::Context;
use super::Object;
use crate::error::CustomError;
@@ -21,7 +22,10 @@ use crate::parser::RadioLink;
use crate::parser::RadioTarget;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn radio_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, RadioLink<'s>> {
pub fn radio_link<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, RadioLink<'s>> {
let radio_targets = context
.iter()
.filter_map(|context_element| match context_element.get_data() {
@@ -37,14 +41,14 @@ pub fn radio_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
return Ok((
remaining,
RadioLink {
source,
source: source.into(),
children: rematched_target,
},
));
}
}
Err(nom::Err::Error(CustomError::MyError(MyError(
"NoRadioLink",
"NoRadioLink".into(),
))))
}
@@ -52,8 +56,8 @@ pub fn radio_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
pub fn rematch_target<'x, 'r, 's>(
context: Context<'r, 's>,
target: &'x Vec<Object<'x>>,
input: &'s str,
) -> Res<&'s str, Vec<Object<'s>>> {
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
let mut remaining = input;
let mut new_matches = Vec::with_capacity(target.len());
for original_object in target {
@@ -71,7 +75,7 @@ pub fn rematch_target<'x, 'r, 's>(
}
_ => {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"OnlyMinimalSetObjectsAllowed",
"OnlyMinimalSetObjectsAllowed".into(),
))));
}
};
@@ -82,8 +86,8 @@ pub fn rematch_target<'x, 'r, 's>(
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn radio_target<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, RadioTarget<'s>> {
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, RadioTarget<'s>> {
let (remaining, _opening) = tag("<<<")(input)?;
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
@@ -102,11 +106,20 @@ pub fn radio_target<'r, 's>(
let (remaining, _closing) = tag(">>>")(remaining)?;
let (remaining, _trailing_whitespace) = space0(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, RadioTarget { source, children }))
Ok((
remaining,
RadioTarget {
source: source.into(),
children,
},
))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn radio_target_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
fn radio_target_end<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
alt((tag("<"), tag(">"), line_ending))(input)
}
@@ -114,8 +127,8 @@ pub trait RematchObject<'x> {
fn rematch_object<'r, 's>(
&'x self,
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>>;
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>>;
}
#[cfg(test)]