Port a lot of the function signatures over.
This commit is contained in:
parent
bdf3c98f34
commit
c0e51298b6
@ -5,6 +5,9 @@ use std::rc::Rc;
|
|||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
use crate::parser::text::paragraph_end;
|
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_end;
|
||||||
use super::text::bold_start;
|
use super::text::bold_start;
|
||||||
use super::text::line_break;
|
use super::text::line_break;
|
||||||
@ -35,7 +38,7 @@ use tracing::instrument;
|
|||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
fn context_many_till<'r, I, O, E, F, M, T>(
|
fn context_many_till<'r, I, O, E, F, M, T>(
|
||||||
context: &'r ContextTree<'r>,
|
context: ContextTree<'r>,
|
||||||
mut many_matcher: M,
|
mut many_matcher: M,
|
||||||
mut till_matcher: T,
|
mut till_matcher: T,
|
||||||
) -> impl FnMut(I) -> IResult<I, (Vec<O>, F), E>
|
) -> 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)>> {
|
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 paragraph_parser = parser_with_context!(paragraph);
|
||||||
let ret = many1(paragraph_parser(&initial_context))(input);
|
let ret = many1(paragraph_parser(&initial_context))(input);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paragraph<'s, 'x: 'r, 'r, C>(
|
pub fn paragraph<'s, 'r>(
|
||||||
context: &'x ContextTree<'r, C>,
|
context: ContextTree<'r>,
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)>
|
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
|
||||||
where
|
|
||||||
C: ContextElement,
|
|
||||||
{
|
|
||||||
// Add a not(eof) check because many_till cannot match a zero-length string
|
// Add a not(eof) check because many_till cannot match a zero-length string
|
||||||
not(eof)(i)?;
|
not(eof)(i)?;
|
||||||
let paragraph_context = context.with_additional_node(FailMatcherNode {
|
let paragraph_context = context.with_additional_node(FailMatcherNode {
|
||||||
@ -107,13 +107,10 @@ where
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_text_element<'s, 'x: 'r, 'r, C>(
|
fn flat_text_element<'s, 'r>(
|
||||||
context: &'x ContextTree<'r, C>,
|
context: ContextTree<'r>,
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
) -> Res<&'s str, TextElement<'s>>
|
) -> Res<&'s str, TextElement<'s>> {
|
||||||
where
|
|
||||||
C: ContextElement,
|
|
||||||
{
|
|
||||||
not(|i| context.check_fail_matcher(i))(i)?;
|
not(|i| context.check_fail_matcher(i))(i)?;
|
||||||
|
|
||||||
let bold_matcher = parser_with_context!(flat_bold)(context);
|
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)
|
recognize(bold_end)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_bold<'s, 'x: 'r, 'r, C>(
|
fn flat_bold<'s, 'r>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> {
|
||||||
context: &'x ContextTree<'r, C>,
|
|
||||||
i: &'s str,
|
|
||||||
) -> Res<&'s str, Bold<'s>>
|
|
||||||
where
|
|
||||||
C: ContextElement,
|
|
||||||
{
|
|
||||||
let new_context = context.with_additional_node(FailMatcherNode {
|
let new_context = context.with_additional_node(FailMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
|
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)
|
recognize(link_end)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_link<'s, 'x: 'r, 'r, C>(
|
fn flat_link<'s, 'r, C>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Link<'s>> {
|
||||||
context: &'x ContextTree<'r, C>,
|
|
||||||
i: &'s str,
|
|
||||||
) -> Res<&'s str, Link<'s>>
|
|
||||||
where
|
|
||||||
C: ContextElement,
|
|
||||||
{
|
|
||||||
let new_context = context.with_additional_node(FailMatcherNode {
|
let new_context = context.with_additional_node(FailMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)),
|
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)),
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user