Move the document parser inside text_element_parser.
This is to put the context-sensitive parsers together during this early development stage.
This commit is contained in:
		
							parent
							
								
									a09c6838b3
								
							
						
					
					
						commit
						77f02a21b9
					
				| @ -2,4 +2,4 @@ mod nom_context; | ||||
| mod parser_with_context; | ||||
| mod text; | ||||
| mod text_element_parser; | ||||
| pub use text::document; | ||||
| pub use text_element_parser::document; | ||||
|  | ||||
| @ -5,6 +5,7 @@ use std::rc::Rc; | ||||
| use crate::parser::parser_with_context::parser_with_context; | ||||
| use crate::parser::text::paragraph_end; | ||||
| 
 | ||||
| use super::nom_context::ContextTree; | ||||
| use super::nom_context::OrgModeContext; | ||||
| use super::nom_context::OrgModeContextTree; | ||||
| use super::text::bold_end; | ||||
| @ -27,12 +28,31 @@ use nom::combinator::recognize; | ||||
| use nom::error::ErrorKind; | ||||
| use nom::error::ParseError; | ||||
| use nom::error::VerboseError; | ||||
| use nom::multi::many1; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| use nom::IResult; | ||||
| use tracing::instrument; | ||||
| use tracing::trace; | ||||
| 
 | ||||
| pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> { | ||||
|     let initial_context = ContextTree::new(); | ||||
|     let ret = many1(parser_with_context!(paragraph)(&initial_context))(input); | ||||
|     ret | ||||
| } | ||||
| 
 | ||||
| pub fn paragraph<'s, 'r>( | ||||
|     i: &'s str, | ||||
|     context: &'r OrgModeContext<'r>, | ||||
| ) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> { | ||||
|     // Add a not(eof) check because many_till cannot match a zero-length string
 | ||||
|     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); | ||||
|     ret | ||||
| } | ||||
| 
 | ||||
| fn flat_text_element<'s, 'r>( | ||||
|     i: &'s str, | ||||
|     context: &'r OrgModeContext<'r>, | ||||
| @ -83,15 +103,3 @@ fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str | ||||
|     let ret = Link { contents: captured }; | ||||
|     Ok((remaining, ret)) | ||||
| } | ||||
| 
 | ||||
| pub fn paragraph<'s, 'r>( | ||||
|     i: &'s str, | ||||
|     context: &'r OrgModeContext<'r>, | ||||
| ) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> { | ||||
|     // Add a not(eof) check because many_till cannot match a zero-length string
 | ||||
|     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); | ||||
|     ret | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander