Update the paragraph parser to work at the end of the file.
This commit is contained in:
		
							parent
							
								
									185c761a5d
								
							
						
					
					
						commit
						65c51f79d6
					
				| @ -1,6 +1,7 @@ | ||||
| use std::cell::RefCell; | ||||
| use std::rc::Rc; | ||||
| 
 | ||||
| use nom::branch::alt; | ||||
| /* | ||||
| 
 | ||||
| hypothetical link: | ||||
| @ -18,6 +19,7 @@ use nom::bytes::complete::tag; | ||||
| use nom::character::complete::alphanumeric1; | ||||
| use nom::character::complete::line_ending; | ||||
| use nom::character::complete::space1; | ||||
| use nom::combinator::eof; | ||||
| use nom::combinator::map; | ||||
| use nom::combinator::recognize; | ||||
| use nom::error::VerboseError; | ||||
| @ -130,10 +132,13 @@ pub fn link_end(input: &str) -> Res<&str, TextElement> { | ||||
| } | ||||
| 
 | ||||
| pub fn paragraph_end(input: &str) -> Res<&str, &str> { | ||||
|     recognize(tuple(( | ||||
|         map(line_break, TextElement::LineBreak), | ||||
|         many1(blank_line), | ||||
|     )))(input) | ||||
|     alt(( | ||||
|         recognize(tuple(( | ||||
|             map(line_break, TextElement::LineBreak), | ||||
|             many1(blank_line), | ||||
|         ))), | ||||
|         eof, | ||||
|     ))(input) | ||||
| } | ||||
| 
 | ||||
| pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> { | ||||
|  | ||||
| @ -23,11 +23,14 @@ use nom::branch::alt; | ||||
| use nom::combinator::map; | ||||
| use nom::combinator::not; | ||||
| use nom::combinator::recognize; | ||||
| use nom::error::ErrorKind; | ||||
| use nom::error::ParseError; | ||||
| use nom::error::VerboseError; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| use nom::IResult; | ||||
| use tracing::instrument; | ||||
| use tracing::trace; | ||||
| 
 | ||||
| fn flat_text_element<'s, 'r>( | ||||
|     i: &'s str, | ||||
| @ -84,8 +87,18 @@ pub fn paragraph<'s, 'r>( | ||||
|     i: &'s str, | ||||
|     context: &'r OrgModeContext<'r>, | ||||
| ) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> { | ||||
|     // not(eof)(i)?;
 | ||||
|     let paragraph_context = context.with_additional_fail_matcher(¶graph_end); | ||||
|     let text_element_parser = parser_with_context!(flat_text_element)(¶graph_context); | ||||
|     let ret = many_till(text_element_parser, paragraph_end)(i); | ||||
|     trace!("Returning from paragraph with {:#?}", ret); | ||||
|     if let Ok((remaining, (text_elements, end_of_paragraph))) = &ret { | ||||
|         if text_elements.len() == 0 { | ||||
|             return Err(nom::Err::Error(nom::error::VerboseError::from_error_kind( | ||||
|                 remaining, | ||||
|                 ErrorKind::ManyTill, | ||||
|             ))); | ||||
|         } | ||||
|     } | ||||
|     ret | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander