Rename OrgModeContext.
This commit is contained in:
parent
77f02a21b9
commit
29a53044ea
@ -14,7 +14,7 @@ use tracing::trace;
|
|||||||
|
|
||||||
type Link<'r, T> = Option<&'r Node<'r, T>>;
|
type Link<'r, T> = Option<&'r Node<'r, T>>;
|
||||||
type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
|
type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
|
||||||
pub type OrgModeContext<'r> = ContextTree<'r, ContextElement<'r>>;
|
pub type OrgModeContextNode<'r> = ContextTree<'r, ContextElement<'r>>;
|
||||||
|
|
||||||
struct Node<'r, T> {
|
struct Node<'r, T> {
|
||||||
elem: T,
|
elem: T,
|
||||||
@ -52,12 +52,12 @@ pub enum ChainBehavior<'r> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait OrgModeContextTree<'r> {
|
pub trait OrgModeContextTree<'r> {
|
||||||
fn with_additional_fail_matcher(&'r self, fail_matcher: &'r Matcher) -> OrgModeContext<'r>;
|
fn with_additional_fail_matcher(&'r self, fail_matcher: &'r Matcher) -> OrgModeContextNode<'r>;
|
||||||
|
|
||||||
fn match_fail<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
|
fn match_fail<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> OrgModeContextTree<'r> for OrgModeContext<'r> {
|
impl<'r> OrgModeContextTree<'r> for OrgModeContextNode<'r> {
|
||||||
fn with_additional_fail_matcher(
|
fn with_additional_fail_matcher(
|
||||||
&'r self,
|
&'r self,
|
||||||
fail_matcher: &'r Matcher,
|
fail_matcher: &'r Matcher,
|
||||||
|
@ -140,9 +140,3 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> {
|
|||||||
eof,
|
eof,
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
|
||||||
let initial_context = ContextTree::new();
|
|
||||||
let ret = many1(parser_with_context!(paragraph)(&initial_context))(input);
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@ use crate::parser::parser_with_context::parser_with_context;
|
|||||||
use crate::parser::text::paragraph_end;
|
use crate::parser::text::paragraph_end;
|
||||||
|
|
||||||
use super::nom_context::ContextTree;
|
use super::nom_context::ContextTree;
|
||||||
use super::nom_context::OrgModeContext;
|
use super::nom_context::OrgModeContextNode;
|
||||||
use super::nom_context::OrgModeContextTree;
|
use super::nom_context::OrgModeContextTree;
|
||||||
use super::text::bold_end;
|
use super::text::bold_end;
|
||||||
use super::text::bold_start;
|
use super::text::bold_start;
|
||||||
@ -43,7 +43,7 @@ pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
|||||||
|
|
||||||
pub fn paragraph<'s, 'r>(
|
pub fn paragraph<'s, 'r>(
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
context: &'r OrgModeContext<'r>,
|
context: &'r OrgModeContextNode<'r>,
|
||||||
) -> 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)?;
|
||||||
@ -55,7 +55,7 @@ pub fn paragraph<'s, 'r>(
|
|||||||
|
|
||||||
fn flat_text_element<'s, 'r>(
|
fn flat_text_element<'s, 'r>(
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
context: &'r OrgModeContext<'r>,
|
context: &'r OrgModeContextNode<'r>,
|
||||||
) -> 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 +78,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 OrgModeContext<'r>) -> Res<&'s str, Bold<'s>> {
|
fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContextNode<'r>) -> 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 +93,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 OrgModeContext<'r>) -> Res<&'s str, Link<'s>> {
|
fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContextNode<'r>) -> 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