Rename OrgModeContext.

This commit is contained in:
Tom Alexander 2022-11-26 19:22:14 -05:00
parent 77f02a21b9
commit 29a53044ea
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 8 additions and 14 deletions

View File

@ -14,7 +14,7 @@ use tracing::trace;
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>>;
pub type OrgModeContext<'r> = ContextTree<'r, ContextElement<'r>>;
pub type OrgModeContextNode<'r> = ContextTree<'r, ContextElement<'r>>;
struct Node<'r, T> {
elem: T,
@ -52,12 +52,12 @@ pub enum ChainBehavior<'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>>;
}
impl<'r> OrgModeContextTree<'r> for OrgModeContext<'r> {
impl<'r> OrgModeContextTree<'r> for OrgModeContextNode<'r> {
fn with_additional_fail_matcher(
&'r self,
fail_matcher: &'r Matcher,

View File

@ -140,9 +140,3 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> {
eof,
))(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
}

View File

@ -6,7 +6,7 @@ use crate::parser::parser_with_context::parser_with_context;
use crate::parser::text::paragraph_end;
use super::nom_context::ContextTree;
use super::nom_context::OrgModeContext;
use super::nom_context::OrgModeContextNode;
use super::nom_context::OrgModeContextTree;
use super::text::bold_end;
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>(
i: &'s str,
context: &'r OrgModeContext<'r>,
context: &'r OrgModeContextNode<'r>,
) -> 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)?;
@ -55,7 +55,7 @@ pub fn paragraph<'s, 'r>(
fn flat_text_element<'s, 'r>(
i: &'s str,
context: &'r OrgModeContext<'r>,
context: &'r OrgModeContextNode<'r>,
) -> Res<&'s str, TextElement<'s>> {
not(|i| context.match_fail(i))(i)?;
@ -78,7 +78,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
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 text_element_parser = parser_with_context!(flat_text_element)(&new_context);
let (remaining, captured) = recognize(tuple((
@ -93,7 +93,7 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> {
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 text_element_parser = parser_with_context!(flat_text_element)(&new_context);
let (remaining, captured) = recognize(tuple((