From bdf3c98f3479b980e7ea1a465fb83b930142b3ea Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 3 Dec 2022 20:47:31 -0500 Subject: [PATCH] Starting to move the org-mode specific context tree stuff over. --- src/parser/new_context.rs | 34 +++++++++++++++++++++++++++++++ src/parser/text_element_parser.rs | 5 ++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/parser/new_context.rs b/src/parser/new_context.rs index 8b137891..5f62a674 100644 --- a/src/parser/new_context.rs +++ b/src/parser/new_context.rs @@ -1 +1,35 @@ +use nom::error::VerboseError; +use nom::IResult; +use super::list::List; + +type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; + +pub struct ContextTree<'r> { + tree: List>, +} + +impl<'r> ContextTree<'r> { + pub fn new() -> Self { + ContextTree { tree: List::new() } + } +} + +pub enum ContextElement<'r> { + FailMatcherNode(FailMatcherNode<'r>), + PreviousElementNode(PreviousElementNode<'r>), +} + +pub struct FailMatcherNode<'r> { + pub fail_matcher: ChainBehavior<'r>, +} + +pub struct PreviousElementNode<'r> { + pub dummy: &'r str, +} + +#[derive(Clone)] +pub enum ChainBehavior<'r> { + AndParent(Option<&'r Matcher>), + IgnoreParent(Option<&'r Matcher>), +} diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 58f6f88d..ebc94424 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -34,13 +34,12 @@ use nom::Parser; use tracing::instrument; use tracing::trace; -fn context_many_till<'r, C, I, O, E, F, M, T>( - context: &'r ContextTree<'r, C>, +fn context_many_till<'r, I, O, E, F, M, T>( + context: &'r ContextTree<'r>, mut many_matcher: M, mut till_matcher: T, ) -> impl FnMut(I) -> IResult, F), E> where - C: ContextElement, I: Clone + InputLength, M: Parser, T: Parser,