Port a lot of the function signatures over.

This commit is contained in:
Tom Alexander 2022-12-03 20:53:14 -05:00
parent bdf3c98f34
commit c0e51298b6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -5,6 +5,9 @@ use std::rc::Rc;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::text::paragraph_end;
use super::new_context::ChainBehavior;
use super::new_context::ContextTree;
use super::new_context::FailMatcherNode;
use super::text::bold_end;
use super::text::bold_start;
use super::text::line_break;
@ -35,7 +38,7 @@ use tracing::instrument;
use tracing::trace;
fn context_many_till<'r, I, O, E, F, M, T>(
context: &'r ContextTree<'r>,
context: ContextTree<'r>,
mut many_matcher: M,
mut till_matcher: T,
) -> impl FnMut(I) -> IResult<I, (Vec<O>, F), E>
@ -78,19 +81,16 @@ where
}
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
let initial_context: ContextTree<'_, FailMatcherNode> = ContextTree::new();
let initial_context: ContextTree<'_> = ContextTree::new();
let paragraph_parser = parser_with_context!(paragraph);
let ret = many1(paragraph_parser(&initial_context))(input);
ret
}
pub fn paragraph<'s, 'x: 'r, 'r, C>(
context: &'x ContextTree<'r, C>,
pub fn paragraph<'s, 'r>(
context: ContextTree<'r>,
i: &'s str,
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)>
where
C: ContextElement,
{
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
// Add a not(eof) check because many_till cannot match a zero-length string
not(eof)(i)?;
let paragraph_context = context.with_additional_node(FailMatcherNode {
@ -107,13 +107,10 @@ where
ret
}
fn flat_text_element<'s, 'x: 'r, 'r, C>(
context: &'x ContextTree<'r, C>,
fn flat_text_element<'s, 'r>(
context: ContextTree<'r>,
i: &'s str,
) -> Res<&'s str, TextElement<'s>>
where
C: ContextElement,
{
) -> Res<&'s str, TextElement<'s>> {
not(|i| context.check_fail_matcher(i))(i)?;
let bold_matcher = parser_with_context!(flat_bold)(context);
@ -135,13 +132,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
recognize(bold_end)(input)
}
fn flat_bold<'s, 'x: 'r, 'r, C>(
context: &'x ContextTree<'r, C>,
i: &'s str,
) -> Res<&'s str, Bold<'s>>
where
C: ContextElement,
{
fn flat_bold<'s, 'r>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> {
let new_context = context.with_additional_node(FailMatcherNode {
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
});
@ -159,13 +150,7 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> {
recognize(link_end)(input)
}
fn flat_link<'s, 'x: 'r, 'r, C>(
context: &'x ContextTree<'r, C>,
i: &'s str,
) -> Res<&'s str, Link<'s>>
where
C: ContextElement,
{
fn flat_link<'s, 'r, C>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Link<'s>> {
let new_context = context.with_additional_node(FailMatcherNode {
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)),
});