Same lifetime issue.
This commit is contained in:
parent
ec4078c812
commit
7d25628f74
@ -29,9 +29,6 @@ use nom::sequence::tuple;
|
||||
use nom::IResult;
|
||||
use tracing::instrument;
|
||||
|
||||
use super::nom_context::ContextTree;
|
||||
use super::nom_context::OrgModeContextTree;
|
||||
use super::parser_with_context::parser_with_context;
|
||||
use super::text_element_parser::paragraph;
|
||||
|
||||
pub type Res<T, U> = IResult<T, U, VerboseError<T>>;
|
||||
|
@ -5,9 +5,9 @@ use std::rc::Rc;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use crate::parser::text::paragraph_end;
|
||||
|
||||
use super::nom_context::ContextTree;
|
||||
use super::nom_context::OrgModeContextNode;
|
||||
use super::nom_context::OrgModeContextTree;
|
||||
use super::new_context::ContextElement;
|
||||
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;
|
||||
@ -37,12 +37,13 @@ use nom::Parser;
|
||||
use tracing::instrument;
|
||||
use tracing::trace;
|
||||
|
||||
fn context_many_till<'r, I, O, E, F, M, T>(
|
||||
context: &'r OrgModeContextNode<'r>,
|
||||
fn context_many_till<'r, C, I, O, E, F, M, T>(
|
||||
context: &'r ContextTree<'r, C>,
|
||||
mut many_matcher: M,
|
||||
mut till_matcher: T,
|
||||
) -> impl FnMut(I) -> IResult<I, (Vec<O>, F), E>
|
||||
where
|
||||
C: ContextElement,
|
||||
I: Clone + InputLength,
|
||||
M: Parser<I, O, E>,
|
||||
T: Parser<I, F, E>,
|
||||
@ -81,16 +82,19 @@ where
|
||||
}
|
||||
|
||||
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
||||
let initial_context = ContextTree::new();
|
||||
let initial_context: ContextTree<'_, FailMatcherNode> = ContextTree::new();
|
||||
let paragraph_parser = parser_with_context!(paragraph);
|
||||
let ret = many1(paragraph_parser(&initial_context))(input);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn paragraph<'s, 'r>(
|
||||
context: &'r OrgModeContextNode<'r>,
|
||||
pub fn paragraph<'s, 'r, C>(
|
||||
context: &'r ContextTree<'r, C>,
|
||||
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
|
||||
not(eof)(i)?;
|
||||
let paragraph_context = context.with_additional_fail_matcher(¶graph_end);
|
||||
@ -100,11 +104,14 @@ pub fn paragraph<'s, 'r>(
|
||||
ret
|
||||
}
|
||||
|
||||
fn flat_text_element<'s, 'r>(
|
||||
context: &'r OrgModeContextNode<'r>,
|
||||
fn flat_text_element<'s, 'r, C>(
|
||||
context: &'r ContextTree<'r, C>,
|
||||
i: &'s str,
|
||||
) -> Res<&'s str, TextElement<'s>> {
|
||||
not(|i| context.match_fail(i))(i)?;
|
||||
) -> Res<&'s str, TextElement<'s>>
|
||||
where
|
||||
C: ContextElement,
|
||||
{
|
||||
not(|i| context.check_fail_matcher(i))(i)?;
|
||||
|
||||
let bold_matcher = parser_with_context!(flat_bold)(context);
|
||||
let link_matcher = parser_with_context!(flat_link)(context);
|
||||
@ -125,7 +132,10 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
|
||||
recognize(bold_end)(input)
|
||||
}
|
||||
|
||||
fn flat_bold<'s, 'r>(context: &'r OrgModeContextNode<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> {
|
||||
fn flat_bold<'s, 'r, C>(context: &'r ContextTree<'r, C>, i: &'s str) -> Res<&'s str, Bold<'s>>
|
||||
where
|
||||
C: ContextElement,
|
||||
{
|
||||
let new_context = context.with_additional_fail_matcher(&recognize_bold_end);
|
||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||
let (remaining, captured) = recognize(tuple((
|
||||
@ -140,7 +150,10 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> {
|
||||
recognize(link_end)(input)
|
||||
}
|
||||
|
||||
fn flat_link<'s, 'r>(context: &'r OrgModeContextNode<'r>, i: &'s str) -> Res<&'s str, Link<'s>> {
|
||||
fn flat_link<'s, 'r, C>(context: &'r ContextTree<'r, C>, i: &'s str) -> Res<&'s str, Link<'s>>
|
||||
where
|
||||
C: ContextElement,
|
||||
{
|
||||
let new_context = context.with_additional_fail_matcher(&recognize_link_end);
|
||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||
let (remaining, captured) = recognize(tuple((
|
||||
|
Loading…
x
Reference in New Issue
Block a user