Convert all functions to using the wrapped input type.
This commit is contained in:
@@ -15,6 +15,7 @@ use nom::sequence::terminated;
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::span;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::radio_link::RematchObject;
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
@@ -39,7 +40,10 @@ use crate::parser::Underline;
|
||||
use crate::parser::Verbatim;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn text_markup<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Object<'s>> {
|
||||
pub fn text_markup<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Object<'s>> {
|
||||
alt((
|
||||
map(parser_with_context!(bold)(context), Object::Bold),
|
||||
map(parser_with_context!(italic)(context), Object::Italic),
|
||||
@@ -54,73 +58,126 @@ pub fn text_markup<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn bold<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Bold<'s>> {
|
||||
pub fn bold<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Bold<'s>> {
|
||||
let text_markup_object_specialized = text_markup_object("*");
|
||||
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Bold { source, children }))
|
||||
Ok((
|
||||
remaining,
|
||||
Bold {
|
||||
source: source.into(),
|
||||
children,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn italic<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Italic<'s>> {
|
||||
pub fn italic<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Italic<'s>> {
|
||||
let text_markup_object_specialized = text_markup_object("/");
|
||||
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Italic { source, children }))
|
||||
Ok((
|
||||
remaining,
|
||||
Italic {
|
||||
source: source.into(),
|
||||
children,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn underline<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Underline<'s>> {
|
||||
pub fn underline<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Underline<'s>> {
|
||||
let text_markup_object_specialized = text_markup_object("_");
|
||||
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Underline { source, children }))
|
||||
Ok((
|
||||
remaining,
|
||||
Underline {
|
||||
source: source.into(),
|
||||
children,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn strike_through<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, StrikeThrough<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, StrikeThrough<'s>> {
|
||||
let text_markup_object_specialized = text_markup_object("+");
|
||||
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, StrikeThrough { source, children }))
|
||||
Ok((
|
||||
remaining,
|
||||
StrikeThrough {
|
||||
source: source.into(),
|
||||
children,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn verbatim<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Verbatim<'s>> {
|
||||
pub fn verbatim<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Verbatim<'s>> {
|
||||
let text_markup_string_specialized = text_markup_string("=");
|
||||
let (remaining, contents) = text_markup_string_specialized(context, input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Verbatim { source, contents }))
|
||||
Ok((
|
||||
remaining,
|
||||
Verbatim {
|
||||
source: source.into(),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn code<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Code<'s>> {
|
||||
pub fn code<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Code<'s>> {
|
||||
let text_markup_string_specialized = text_markup_string("~");
|
||||
let (remaining, contents) = text_markup_string_specialized(context, input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Code { source, contents }))
|
||||
Ok((
|
||||
remaining,
|
||||
Code {
|
||||
source: source.into(),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn text_markup_object(
|
||||
marker_symbol: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, Vec<Object<'s>>> {
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
|
||||
let marker_symbol = marker_symbol.to_owned();
|
||||
move |context: Context, input: &str| _text_markup_object(context, input, marker_symbol.as_str())
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_text_markup_object(context, input, marker_symbol.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _text_markup_object<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
marker_symbol: &'x str,
|
||||
) -> Res<&'s str, Vec<Object<'s>>> {
|
||||
) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
|
||||
let (remaining, _) = pre(context, input)?;
|
||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
|
||||
let text_markup_end_specialized = text_markup_end(open);
|
||||
let text_markup_end_specialized = text_markup_end(open.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
@@ -142,7 +199,7 @@ fn _text_markup_object<'r, 's, 'x>(
|
||||
let _enter = span.enter();
|
||||
if exit_matcher_parser(context, remaining).is_ok() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Parent exit matcher is triggering.",
|
||||
"Parent exit matcher is triggering.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
@@ -154,21 +211,23 @@ fn _text_markup_object<'r, 's, 'x>(
|
||||
|
||||
fn text_markup_string(
|
||||
marker_symbol: &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 marker_symbol = marker_symbol.to_owned();
|
||||
move |context: Context, input: &str| _text_markup_string(context, input, marker_symbol.as_str())
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_text_markup_string(context, input, marker_symbol.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _text_markup_string<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
marker_symbol: &'x str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, _) = pre(context, input)?;
|
||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
|
||||
let text_markup_end_specialized = text_markup_end(open);
|
||||
let text_markup_end_specialized = text_markup_end(open.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
@@ -190,7 +249,7 @@ fn _text_markup_string<'r, 's, 'x>(
|
||||
let _enter = span.enter();
|
||||
if exit_matcher_parser(context, remaining).is_ok() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Parent exit matcher is triggering.",
|
||||
"Parent exit matcher is triggering.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
@@ -201,7 +260,7 @@ fn _text_markup_string<'r, 's, 'x>(
|
||||
}
|
||||
|
||||
#[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())
|
||||
@@ -213,7 +272,7 @@ pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()>
|
||||
Some(_) => {
|
||||
// Not at start of line, cannot be a heading
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre character for text markup.",
|
||||
"Not a valid pre character for text markup.".into(),
|
||||
))));
|
||||
}
|
||||
};
|
||||
@@ -221,24 +280,26 @@ pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()>
|
||||
}
|
||||
|
||||
#[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>, ()> {
|
||||
let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\">")), line_ending))(input)?;
|
||||
Ok((remaining, ()))
|
||||
}
|
||||
|
||||
fn text_markup_end(
|
||||
marker_symbol: &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 marker_symbol = marker_symbol.to_owned();
|
||||
move |context: Context, input: &str| _text_markup_end(context, input, marker_symbol.as_str())
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_text_markup_end(context, input, marker_symbol.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _text_markup_end<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
marker_symbol: &'x str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
not(parser_with_context!(preceded_by_whitespace)(context))(input)?;
|
||||
let (remaining, _marker) = terminated(
|
||||
tag(marker_symbol),
|
||||
@@ -253,26 +314,32 @@ impl<'x> RematchObject<'x> for Bold<'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>> {
|
||||
let (remaining, children) =
|
||||
_rematch_text_markup_object(_context, input, "*", &self.children)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Object::Bold(Bold { source, children })))
|
||||
Ok((
|
||||
remaining,
|
||||
Object::Bold(Bold {
|
||||
source: source.into(),
|
||||
children,
|
||||
}),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _rematch_text_markup_object<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
marker_symbol: &'static str,
|
||||
original_match_children: &'x Vec<Object<'x>>,
|
||||
) -> Res<&'s str, Vec<Object<'s>>> {
|
||||
) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
|
||||
let (remaining, _) = pre(context, input)?;
|
||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
|
||||
let text_markup_end_specialized = text_markup_end(open);
|
||||
let text_markup_end_specialized = text_markup_end(open.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Beta,
|
||||
@@ -290,7 +357,7 @@ fn _rematch_text_markup_object<'r, 's, 'x>(
|
||||
let _enter = span.enter();
|
||||
if exit_matcher_parser(context, remaining).is_ok() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Parent exit matcher is triggering.",
|
||||
"Parent exit matcher is triggering.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user