Trying a raw borrow with explicit lifetime.
This commit is contained in:
		
							parent
							
								
									091b70dff6
								
							
						
					
					
						commit
						7e07e00e4c
					
				| @ -4,16 +4,17 @@ use nom::IResult; | ||||
| use std::cell::RefCell; | ||||
| use std::rc::Rc; | ||||
| 
 | ||||
| pub struct NomContext<I, O, E> { | ||||
|     pub fail_matcher: Box<dyn FnMut(I) -> IResult<I, O, E>>, | ||||
| #[derive(Clone)] | ||||
| pub struct NomContext<'a, I, O, E> { | ||||
|     pub fail_matcher: &'a dyn FnMut(I) -> IResult<I, O, E>, | ||||
| 
 | ||||
|     /// You can't have nested bolds in org-mode
 | ||||
|     pub can_match_bold: bool, | ||||
|     pub can_match_link: bool, | ||||
| } | ||||
| 
 | ||||
| impl<I, O, E> NomContext<I, O, E> { | ||||
|     pub fn new(fail_matcher: Box<dyn FnMut(I) -> IResult<I, O, E>>) -> Self { | ||||
| 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, | ||||
| @ -21,13 +22,13 @@ impl<I, O, E> NomContext<I, O, E> { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // 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
 | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| macro_rules! parser_with_context { | ||||
|     ($name:ident,$typ:ty,$inp:ident,$context:ident,$fnbody:block) => { | ||||
|         pub fn $name<I, O, E>( | ||||
|             $context: &NomContext<I, O, E>, | ||||
|         pub fn $name<I: Clone, O, E: nom::error::ParseError<I>>( | ||||
|             $context: &mut NomContext<I, O, E>, | ||||
|         ) -> impl for<'a> FnMut(&'a str) -> IResult<&'a str, $typ, VerboseError<&'a str>> { | ||||
|             |$inp: &str| $fnbody | ||||
|         } | ||||
|  | ||||
| @ -13,7 +13,7 @@ use nom::error::VerboseError; | ||||
| use nom::IResult; | ||||
| 
 | ||||
| parser_with_context!(text_element, TextElement, i, context, { | ||||
|     // not(|i| context.fail_matcher.borrow_mut().parse(i))(i)?;
 | ||||
|     not(|i| (context.fail_matcher)(i))(i)?; | ||||
|     alt(( | ||||
|         // map(
 | ||||
|         //     BoldParser::new(slf.context.fail_matcher.clone()),
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander