Swap in the new TestContext everywhere.
This commit is contained in:
		
							parent
							
								
									ec2d09b72a
								
							
						
					
					
						commit
						8695d32f40
					
				| @ -18,7 +18,7 @@ struct ContextLayer<T> { | ||||
|     parent: ContextReference<T>, | ||||
| } | ||||
| 
 | ||||
| struct ContextData { | ||||
| pub struct ContextData { | ||||
|     fail_matcher: ChainBehavior, | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -27,6 +27,7 @@ use nom::sequence::tuple; | ||||
| use nom::IResult; | ||||
| 
 | ||||
| use super::nom_context::NomContext; | ||||
| use super::nom_context::TestContext; | ||||
| use super::parser_with_context::parser_with_context; | ||||
| use super::text_element_parser::paragraph; | ||||
| 
 | ||||
| @ -137,7 +138,10 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> { | ||||
| } | ||||
| 
 | ||||
| pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> { | ||||
|     let initial_context = NomContext::new(Rc::new(RefCell::new(paragraph_end))); | ||||
|     let ret = many1(parser_with_context!(paragraph)(&initial_context))(input); | ||||
|     let initial_context = TestContext::new(); | ||||
|     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); | ||||
|     ret | ||||
| } | ||||
|  | ||||
| @ -5,7 +5,9 @@ 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::NomContext; | ||||
| use super::nom_context::TestContext; | ||||
| use super::text::bold_end; | ||||
| use super::text::bold_start; | ||||
| use super::text::line_break; | ||||
| @ -24,8 +26,11 @@ use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| use nom::IResult; | ||||
| 
 | ||||
| fn flat_text_element<'s, 'r>(i: &'s str, context: &'r NomContext) -> Res<&'s str, TextElement<'s>> { | ||||
|     context.not_matching_fail(i)?; | ||||
| fn flat_text_element<'s, 'r>( | ||||
|     i: &'s str, | ||||
|     context: &'r TestContext<ContextData>, | ||||
| ) -> Res<&'s str, TextElement<'s>> { | ||||
|     // context.not_matching_fail(i)?;
 | ||||
| 
 | ||||
|     alt(( | ||||
|         map(span, TextElement::Span), | ||||
| @ -37,14 +42,14 @@ fn flat_text_element<'s, 'r>(i: &'s str, context: &'r NomContext) -> Res<&'s str | ||||
|     ))(i) | ||||
| } | ||||
| 
 | ||||
| fn flat_bold<'s, 'r>(i: &'s str, context: &'r NomContext) -> Res<&'s str, TextElement<'s>> { | ||||
| fn flat_bold<'s, 'r>(i: &'s str, context: &'r TestContext<ContextData>) -> Res<&'s str, TextElement<'s>> { | ||||
|     // let new_context = context.without_bold(Rc::new(RefCell::new(recognize(bold_end))));
 | ||||
|     todo!() | ||||
| } | ||||
| 
 | ||||
| pub fn paragraph<'s, 'r>( | ||||
|     i: &'s str, | ||||
|     context: &'r NomContext, | ||||
|     context: &'r TestContext<ContextData>, | ||||
| ) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> { | ||||
|     let text_element_parser = parser_with_context!(flat_text_element)(context); | ||||
|     many_till(text_element_parser, paragraph_end)(i) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander