Re-arrange context parameter order.
This commit is contained in:
parent
29a53044ea
commit
4d58ed3bea
@ -1,6 +1,6 @@
|
|||||||
macro_rules! parser_with_context {
|
macro_rules! parser_with_context {
|
||||||
($target:ident) => {
|
($target:ident) => {
|
||||||
move |context| move |i| $target(i, context)
|
move |context| move |i| $target(context, i)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use parser_with_context;
|
pub(crate) use parser_with_context;
|
||||||
|
@ -35,6 +35,10 @@ use nom::IResult;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
|
fn context_many_till() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
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::new();
|
let initial_context = ContextTree::new();
|
||||||
let ret = many1(parser_with_context!(paragraph)(&initial_context))(input);
|
let ret = many1(parser_with_context!(paragraph)(&initial_context))(input);
|
||||||
@ -42,8 +46,8 @@ pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn paragraph<'s, 'r>(
|
pub fn paragraph<'s, 'r>(
|
||||||
i: &'s str,
|
|
||||||
context: &'r OrgModeContextNode<'r>,
|
context: &'r OrgModeContextNode<'r>,
|
||||||
|
i: &'s str,
|
||||||
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
|
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
|
||||||
// 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)?;
|
||||||
@ -54,8 +58,8 @@ pub fn paragraph<'s, 'r>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn flat_text_element<'s, 'r>(
|
fn flat_text_element<'s, 'r>(
|
||||||
i: &'s str,
|
|
||||||
context: &'r OrgModeContextNode<'r>,
|
context: &'r OrgModeContextNode<'r>,
|
||||||
|
i: &'s str,
|
||||||
) -> Res<&'s str, TextElement<'s>> {
|
) -> Res<&'s str, TextElement<'s>> {
|
||||||
not(|i| context.match_fail(i))(i)?;
|
not(|i| context.match_fail(i))(i)?;
|
||||||
|
|
||||||
@ -78,7 +82,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
|
|||||||
recognize(bold_end)(input)
|
recognize(bold_end)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContextNode<'r>) -> Res<&'s str, Bold<'s>> {
|
fn flat_bold<'s, 'r>(context: &'r OrgModeContextNode<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> {
|
||||||
let new_context = context.with_additional_fail_matcher(&recognize_bold_end);
|
let new_context = context.with_additional_fail_matcher(&recognize_bold_end);
|
||||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||||
let (remaining, captured) = recognize(tuple((
|
let (remaining, captured) = recognize(tuple((
|
||||||
@ -93,7 +97,7 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> {
|
|||||||
recognize(link_end)(input)
|
recognize(link_end)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContextNode<'r>) -> Res<&'s str, Link<'s>> {
|
fn flat_link<'s, 'r>(context: &'r OrgModeContextNode<'r>, i: &'s str) -> Res<&'s str, Link<'s>> {
|
||||||
let new_context = context.with_additional_fail_matcher(&recognize_link_end);
|
let new_context = context.with_additional_fail_matcher(&recognize_link_end);
|
||||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||||
let (remaining, captured) = recognize(tuple((
|
let (remaining, captured) = recognize(tuple((
|
||||||
|
Loading…
x
Reference in New Issue
Block a user