Switch to a centrally-defined context type.
This commit is contained in:
		
							parent
							
								
									a3286b2542
								
							
						
					
					
						commit
						b91e4df797
					
				| @ -5,3 +5,4 @@ mod parser_with_context; | ||||
| mod text; | ||||
| mod text_element_parser; | ||||
| pub use text_element_parser::document; | ||||
| type Context<'r> = new_context::ContextTree<'r>; | ||||
|  | ||||
| @ -21,6 +21,7 @@ use super::text::Bold; | ||||
| use super::text::Link; | ||||
| use super::text::Res; | ||||
| use super::text::TextElement; | ||||
| use super::Context; | ||||
| use nom::branch::alt; | ||||
| use nom::combinator::eof; | ||||
| use nom::combinator::map; | ||||
| @ -39,7 +40,7 @@ use tracing::instrument; | ||||
| use tracing::trace; | ||||
| 
 | ||||
| fn context_many_till<'r, I, O, E, F, M, T>( | ||||
|     context: ContextTree<'r>, | ||||
|     context: Context<'r>, | ||||
|     mut many_matcher: M, | ||||
|     mut till_matcher: T, | ||||
| ) -> impl FnMut(I) -> IResult<I, (Vec<O>, F), E> | ||||
| @ -89,7 +90,7 @@ pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> { | ||||
| } | ||||
| 
 | ||||
| pub fn paragraph<'s, 'r>( | ||||
|     context: ContextTree<'r>, | ||||
|     context: Context<'r>, | ||||
|     i: &'s str, | ||||
| ) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> { | ||||
|     // Add a not(eof) check because many_till cannot match a zero-length string
 | ||||
| @ -109,10 +110,7 @@ pub fn paragraph<'s, 'r>( | ||||
|     ret | ||||
| } | ||||
| 
 | ||||
| fn flat_text_element<'s, 'r>( | ||||
|     context: ContextTree<'r>, | ||||
|     i: &'s str, | ||||
| ) -> Res<&'s str, TextElement<'s>> { | ||||
| fn flat_text_element<'s, 'r>(context: Context<'r>, i: &'s str) -> Res<&'s str, TextElement<'s>> { | ||||
|     not(|i| context.check_fail_matcher(i))(i)?; | ||||
| 
 | ||||
|     let bold_matcher = parser_with_context!(flat_bold)(context); | ||||
| @ -134,7 +132,7 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> { | ||||
|     recognize(bold_end)(input) | ||||
| } | ||||
| 
 | ||||
| fn flat_bold<'s, 'r>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> { | ||||
| fn flat_bold<'s, 'r>(context: Context<'r>, i: &'s str) -> Res<&'s str, Bold<'s>> { | ||||
|     let new_context = | ||||
|         context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { | ||||
|             fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)), | ||||
| @ -153,7 +151,7 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> { | ||||
|     recognize(link_end)(input) | ||||
| } | ||||
| 
 | ||||
| fn flat_link<'s, 'r, C>(context: ContextTree<'r>, i: &'s str) -> Res<&'s str, Link<'s>> { | ||||
| fn flat_link<'s, 'r, C>(context: Context<'r>, i: &'s str) -> Res<&'s str, Link<'s>> { | ||||
|     let new_context = | ||||
|         context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { | ||||
|             fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander