Hmmm it seems to be building.
This commit is contained in:
		
							parent
							
								
									99b19410c5
								
							
						
					
					
						commit
						8357837571
					
				| @ -16,32 +16,35 @@ where | ||||
|     pub can_match_link: bool, | ||||
| } | ||||
| 
 | ||||
| // impl<'a, I, O, E> NomContext<'a, I, O, E> {
 | ||||
| //     pub fn new(fail_matcher: &'a dyn FnMut(I) -> IResult<I, O, E>) -> Self {
 | ||||
| //         NomContext {
 | ||||
| //             fail_matcher: fail_matcher,
 | ||||
| //             can_match_bold: true,
 | ||||
| //             can_match_link: true,
 | ||||
| //         }
 | ||||
| //     }
 | ||||
| impl<F> NomContext<F> | ||||
| where | ||||
|     F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>, | ||||
| { | ||||
|     pub fn new(fail_matcher: F) -> Self { | ||||
|         NomContext { | ||||
|             fail_matcher: fail_matcher, | ||||
|             can_match_bold: true, | ||||
|             can_match_link: true, | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| //     pub fn with_no_bold(&self) -> NomContext<I, O, E> {
 | ||||
| //         NomContext {
 | ||||
| //             fail_matcher: self.fail_matcher.clone(),
 | ||||
| //             can_match_bold: false,
 | ||||
| //             can_match_link: self.can_match_link,
 | ||||
| //         }
 | ||||
| //     }
 | ||||
|     // pub fn with_no_bold(&self) -> NomContext<I, O, E> {
 | ||||
|     //     NomContext {
 | ||||
|     //         fail_matcher: self.fail_matcher.clone(),
 | ||||
|     //         can_match_bold: false,
 | ||||
|     //         can_match_link: self.can_match_link,
 | ||||
|     //     }
 | ||||
|     // }
 | ||||
| 
 | ||||
| //     // pub fn with_additional_fail_matcher(&self, additional_matcher: G) -> NomContext<G, I, O, E>
 | ||||
| //     // where
 | ||||
| //     //     G: for<'a> FnMut(I) -> IResult<I, O, E>,
 | ||||
| //     // {
 | ||||
| //     //     let new_fail_matcher = alt((self.fail_matcher, additional_matcher));
 | ||||
| //     //     NomContext {
 | ||||
| //     //         fail_matcher: Rc::new(RefCell::new(new_fail_matcher)),
 | ||||
| //     //         can_match_bold: self.can_match_bold,
 | ||||
| //     //         can_match_link: self.can_match_link,
 | ||||
| //     //     }
 | ||||
| //     // }
 | ||||
| // }
 | ||||
|     // pub fn with_additional_fail_matcher(&self, additional_matcher: G) -> NomContext<G, I, O, E>
 | ||||
|     // where
 | ||||
|     //     G: for<'a> FnMut(I) -> IResult<I, O, E>,
 | ||||
|     // {
 | ||||
|     //     let new_fail_matcher = alt((self.fail_matcher, additional_matcher));
 | ||||
|     //     NomContext {
 | ||||
|     //         fail_matcher: Rc::new(RefCell::new(new_fail_matcher)),
 | ||||
|     //         can_match_bold: self.can_match_bold,
 | ||||
|     //         can_match_link: self.can_match_link,
 | ||||
|     //     }
 | ||||
|     // }
 | ||||
| } | ||||
|  | ||||
| @ -16,10 +16,10 @@ | ||||
| 
 | ||||
| macro_rules! parser_with_context { | ||||
|     ($target:ident) => { | ||||
|         |context| { | ||||
|             |i| { | ||||
|         move |mut context| { | ||||
|             move |i| { | ||||
|                 // todo
 | ||||
|                 $target(i, context) | ||||
|                 $target(i, &mut context) | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
|  | ||||
| @ -133,7 +133,7 @@ pub fn paragraph(input: &str) -> Res<&str, (Vec<TextElement>, &str)> { | ||||
|     todo!() | ||||
| } | ||||
| 
 | ||||
| fn paragraph_end(input: &str) -> Res<&str, &str> { | ||||
| pub fn paragraph_end(input: &str) -> Res<&str, &str> { | ||||
|     recognize(tuple((map(line_break, TextElement::LineBreak), blank_line)))(input) | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,7 @@ | ||||
| //! A single element of text.
 | ||||
| use crate::parser::parser_with_context::parser_with_context; | ||||
| use crate::parser::text::paragraph_end; | ||||
| 
 | ||||
| use super::nom_context::NomContext; | ||||
| // use super::parser_with_context::parser_with_context;
 | ||||
| use super::text::line_break; | ||||
| @ -11,6 +14,7 @@ use nom::branch::alt; | ||||
| use nom::combinator::map; | ||||
| use nom::combinator::not; | ||||
| use nom::error::VerboseError; | ||||
| use nom::multi::many_till; | ||||
| use nom::IResult; | ||||
| 
 | ||||
| // parser_with_context!(text_element, TextElement, i, context, {
 | ||||
| @ -48,3 +52,9 @@ where | ||||
|     // todo
 | ||||
|     todo!() | ||||
| } | ||||
| 
 | ||||
| pub fn paragraph(input: &str) -> Res<&str, (Vec<TextElement>, &str)> { | ||||
|     let initial_context = NomContext::new(¶graph_end); | ||||
|     let text_element_parser = parser_with_context!(flat_text_element)(initial_context); | ||||
|     many_till(text_element_parser, paragraph_end)(input) | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander