From a792acf4b0892f2df5be855d4bf719397a1a0590 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 24 Nov 2022 15:14:53 -0500 Subject: [PATCH] Constructing a context. --- src/parser/nom_context.rs | 6 +++--- src/parser/text.rs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 41a3fbd9..c772a53e 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -36,11 +36,11 @@ impl<'r, T> ContextTree<'r, T> { } } -struct ContextElement<'r> { - fail_matcher: ChainBehavior<'r>, +pub struct ContextElement<'r> { + pub fail_matcher: ChainBehavior<'r>, } -enum ChainBehavior<'r> { +pub enum ChainBehavior<'r> { AndParent(Option<&'r Matcher>), IgnoreParent(Option<&'r Matcher>), } diff --git a/src/parser/text.rs b/src/parser/text.rs index f9b7f8a7..fac8c8e5 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -26,6 +26,9 @@ use nom::multi::many_till; use nom::sequence::tuple; use nom::IResult; +use super::nom_context::ChainBehavior; +use super::nom_context::ContextElement; +use super::nom_context::ContextTree; use super::parser_with_context::parser_with_context; use super::text_element_parser::paragraph; @@ -136,6 +139,10 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> { } pub fn document(input: &str) -> Res<&str, Vec<(Vec, &str)>> { + let initial_context = ContextTree::new(); + let paragraph_context = initial_context.with_additional_node(ContextElement { + fail_matcher: ChainBehavior::AndParent(Some(¶graph_end)), + }); // let initial_context = TestContext::new(); // let paragraph_context = initial_context; // let paragraph_context =