From 1487f7d96bfe5783bc1fd446b3affd10d5283b19 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 24 Nov 2022 14:42:05 -0500 Subject: [PATCH] Really start from scratch. --- src/parser/nom_context.rs | 54 +++++++++++++++++++------------ src/parser/text.rs | 7 ++-- src/parser/text_element_parser.rs | 14 ++------ 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 3ac7105..9254f27 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -7,29 +7,41 @@ use nom::error::VerboseError; use nom::IResult; use nom::Parser; -type ContextReference<'r, T> = Option<&'r ContextLayer<'r, T>>; -type MatcherRef = dyn for<'s> FnMut(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; +// type ContextReference<'r, T> = Option>; +// type MatcherRef = dyn for<'s> FnMut(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; -pub struct ContextLayer<'r, T> { - data: T, - parent: ContextReference<'r, T>, -} +// pub struct ContextLayer<'r, T> { +// data: T, +// parent: ContextReference<'r, T>, +// } -pub struct TestContext<'r, T> { - head: ContextReference<'r, T>, -} +// pub struct TestContext<'r, T> { +// head: ContextReference<'r, T>, +// } -pub struct ContextData<'r> { - fail_matcher: ChainBehavior<'r>, -} +// pub struct ContextData<'r> { +// fail_matcher: ChainBehavior<'r>, +// } -impl<'r> TestContext<'r, ContextData<'r>> { - pub fn new() -> Self { - TestContext { head: None } - } -} +// impl<'r> TestContext<'r, ContextData<'r>> { +// pub fn new() -> Self { +// TestContext { head: None } +// } -enum ChainBehavior<'r> { - AndParent(Option<&'r MatcherRef>), - IgnoreParent(Option<&'r MatcherRef>), -} +// pub fn with_additional_fail_matcher<'subr>( +// &self, +// additional_fail_matcher: &'subr MatcherRef, +// ) -> TestContext<'subr, ContextData<'subr>> { +// // TestContext { +// // head: Some( + +// // ) +// // } +// todo!() +// } +// } + +// enum ChainBehavior<'r> { +// AndParent(Option<&'r MatcherRef>), +// IgnoreParent(Option<&'r MatcherRef>), +// } diff --git a/src/parser/text.rs b/src/parser/text.rs index 9513d43..f9b7f8a 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -26,7 +26,6 @@ use nom::multi::many_till; use nom::sequence::tuple; use nom::IResult; -use super::nom_context::TestContext; use super::parser_with_context::parser_with_context; use super::text_element_parser::paragraph; @@ -137,11 +136,11 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> { } pub fn document(input: &str) -> Res<&str, Vec<(Vec, &str)>> { - let initial_context = TestContext::new(); - let paragraph_context = initial_context; + // let initial_context = TestContext::new(); + // let paragraph_context = initial_context; // let paragraph_context = // initial_context.with_additional_fail_matcher(Rc::new(RefCell::new(paragraph_end))); // let initial_context = NomContext::new(Rc::new(RefCell::new(paragraph_end))); - let ret = many1(parser_with_context!(paragraph)(¶graph_context))(input); + let ret = many1(parser_with_context!(paragraph)(10))(input); ret } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 9d6d490..f0759de 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -5,8 +5,6 @@ use std::rc::Rc; use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; -use super::nom_context::ContextData; -use super::nom_context::TestContext; use super::text::bold_end; use super::text::bold_start; use super::text::line_break; @@ -25,10 +23,7 @@ use nom::multi::many_till; use nom::sequence::tuple; use nom::IResult; -fn flat_text_element<'s, 'r>( - i: &'s str, - context: &'r TestContext, -) -> Res<&'s str, TextElement<'s>> { +fn flat_text_element<'s, 'r>(i: &'s str, context: u32) -> Res<&'s str, TextElement<'s>> { // context.not_matching_fail(i)?; alt(( @@ -41,10 +36,7 @@ fn flat_text_element<'s, 'r>( ))(i) } -fn flat_bold<'s, 'r>( - i: &'s str, - context: &'r TestContext, -) -> Res<&'s str, TextElement<'s>> { +fn flat_bold<'s, 'r>(i: &'s str, context: u32) -> Res<&'s str, TextElement<'s>> { // let fail_matcher = recognize(bold_end); // let new_context = context.with_additional_fail_matcher(Rc::new(RefCell::new(paragraph_end))); // let new_context = @@ -55,7 +47,7 @@ fn flat_bold<'s, 'r>( pub fn paragraph<'s, 'r>( i: &'s str, - context: &'r TestContext, + context: u32, ) -> Res<&'s str, (Vec>, &'s str)> { let text_element_parser = parser_with_context!(flat_text_element)(context); many_till(text_element_parser, paragraph_end)(i)