Convert all functions to using the wrapped input type.
This commit is contained in:
@@ -13,6 +13,7 @@ use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
@@ -26,8 +27,8 @@ use crate::parser::LatexFragment;
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn latex_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, LatexFragment<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, LatexFragment<'s>> {
|
||||
let (remaining, _) = alt((
|
||||
parser_with_context!(raw_latex_fragment)(context),
|
||||
parser_with_context!(escaped_parenthesis_fragment)(context),
|
||||
@@ -38,11 +39,19 @@ pub fn latex_fragment<'r, 's>(
|
||||
))(input)?;
|
||||
let (remaining, _) = space0(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, LatexFragment { source }))
|
||||
Ok((
|
||||
remaining,
|
||||
LatexFragment {
|
||||
source: source.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn raw_latex_fragment<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn raw_latex_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, _) = tag("\\")(input)?;
|
||||
let (remaining, _) = name(context, remaining)?;
|
||||
let (remaining, _) = many0(parser_with_context!(brackets)(context))(remaining)?;
|
||||
@@ -52,12 +61,18 @@ fn raw_latex_fragment<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn name<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn name<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
alpha1(input)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn brackets<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn brackets<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, body) = alt((
|
||||
recognize(tuple((
|
||||
tag("["),
|
||||
@@ -88,8 +103,8 @@ fn brackets<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn escaped_parenthesis_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, _) = tag("\\(")(input)?;
|
||||
let (remaining, _) = recognize(many_till(
|
||||
anychar,
|
||||
@@ -107,8 +122,8 @@ fn escaped_parenthesis_fragment<'r, 's>(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn escaped_bracket_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, _) = tag("\\[")(input)?;
|
||||
let (remaining, _) = recognize(many_till(
|
||||
anychar,
|
||||
@@ -126,8 +141,8 @@ fn escaped_bracket_fragment<'r, 's>(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn double_dollar_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
// TODO: The documentation on the dollar sign versions is incomplete. Test to figure out what the real requirements are. For example, can this span more than 3 lines and can this contain a single $ since its terminated by $$?
|
||||
let (remaining, _) = tag("$$")(input)?;
|
||||
let (remaining, _) = recognize(many_till(
|
||||
@@ -144,7 +159,10 @@ fn double_dollar_fragment<'r, 's>(
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn dollar_char_fragment<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn dollar_char_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (_, _) = pre(context, input)?;
|
||||
let (remaining, _) = tag("$")(input)?;
|
||||
let (remaining, _) = verify(none_of(".,?;\""), |c| !c.is_whitespace())(remaining)?;
|
||||
@@ -156,21 +174,21 @@ fn dollar_char_fragment<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
pub fn pre<'r, 's>(context: Context<'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
let document_root = context.get_document_root().unwrap();
|
||||
let preceding_character = get_one_before(document_root, input)
|
||||
.map(|slice| slice.chars().next())
|
||||
.flatten();
|
||||
if let Some('$') = preceding_character {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre character for dollar char fragment.",
|
||||
"Not a valid pre character for dollar char fragment.".into(),
|
||||
))));
|
||||
}
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn post<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
pub fn post<'r, 's>(context: Context<'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
// TODO: What about eof? Test to find out.
|
||||
|
||||
// TODO: Figure out which punctuation characters should be included.
|
||||
@@ -181,8 +199,8 @@ pub fn post<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn bordered_dollar_fragment<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (_, _) = pre(context, input)?;
|
||||
let (remaining, _) = tag("$")(input)?;
|
||||
// TODO: I'm assuming I should be peeking at the borders but the documentation is not clear. Test to figure out.
|
||||
@@ -197,7 +215,7 @@ fn bordered_dollar_fragment<'r, 's>(
|
||||
tag("$"),
|
||||
))),
|
||||
)),
|
||||
|body: &str| body.lines().take(4).count() <= 3,
|
||||
|body: &OrgSource<'_>| Into::<&str>::into(body).lines().take(4).count() <= 3,
|
||||
)(remaining)?;
|
||||
|
||||
let (_, _) = peek(parser_with_context!(close_border)(context))(remaining)?;
|
||||
@@ -209,12 +227,18 @@ fn bordered_dollar_fragment<'r, 's>(
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn open_border<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
pub fn open_border<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
recognize(verify(none_of(".,;$"), |c| !c.is_whitespace()))(input)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn close_border<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
pub fn close_border<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ()> {
|
||||
let document_root = context.get_document_root().unwrap();
|
||||
let preceding_character = get_one_before(document_root, input)
|
||||
.map(|slice| slice.chars().next())
|
||||
@@ -223,7 +247,7 @@ pub fn close_border<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s
|
||||
Some(c) if !c.is_whitespace() && !".,;$".contains(c) => Ok((input, ())),
|
||||
_ => {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre character for dollar char fragment.",
|
||||
"Not a valid pre character for dollar char fragment.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user