Create structure for inline source blocks.
This commit is contained in:
		
							parent
							
								
									b323a407c4
								
							
						
					
					
						commit
						e0d2bb8213
					
				| @ -26,6 +26,7 @@ use crate::parser::GreaterBlock; | ||||
| use crate::parser::Heading; | ||||
| use crate::parser::HorizontalRule; | ||||
| use crate::parser::InlineBabelCall; | ||||
| use crate::parser::InlineSourceBlock; | ||||
| use crate::parser::Italic; | ||||
| use crate::parser::Keyword; | ||||
| use crate::parser::LatexEnvironment; | ||||
| @ -168,6 +169,7 @@ fn compare_object<'s>( | ||||
|         Object::Citation(obj) => compare_citation(source, emacs, obj), | ||||
|         Object::CitationReference(obj) => compare_citation_reference(source, emacs, obj), | ||||
|         Object::InlineBabelCall(obj) => compare_inline_babel_call(source, emacs, obj), | ||||
|         Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj), | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -1413,3 +1415,26 @@ fn compare_inline_babel_call<'s>( | ||||
|         children: Vec::new(), | ||||
|     }) | ||||
| } | ||||
| 
 | ||||
| fn compare_inline_source_block<'s>( | ||||
|     source: &'s str, | ||||
|     emacs: &'s Token<'s>, | ||||
|     rust: &'s InlineSourceBlock<'s>, | ||||
| ) -> Result<DiffResult, Box<dyn std::error::Error>> { | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let emacs_name = "inline-source-block"; | ||||
|     if assert_name(emacs, emacs_name).is_err() { | ||||
|         this_status = DiffStatus::Bad; | ||||
|     } | ||||
| 
 | ||||
|     if assert_bounds(source, emacs, rust).is_err() { | ||||
|         this_status = DiffStatus::Bad; | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
|         status: this_status, | ||||
|         name: emacs_name.to_owned(), | ||||
|         message: None, | ||||
|         children: Vec::new(), | ||||
|     }) | ||||
| } | ||||
|  | ||||
							
								
								
									
										13
									
								
								src/parser/inline_source_block.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/parser/inline_source_block.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| use super::Context; | ||||
| use crate::error::Res; | ||||
| use crate::parser::util::not_yet_implemented; | ||||
| use crate::parser::InlineSourceBlock; | ||||
| 
 | ||||
| #[tracing::instrument(ret, level = "debug")] | ||||
| pub fn inline_source_block<'r, 's>( | ||||
|     context: Context<'r, 's>, | ||||
|     input: &'s str, | ||||
| ) -> Res<&'s str, InlineSourceBlock<'s>> { | ||||
|     not_yet_implemented()?; | ||||
|     todo!() | ||||
| } | ||||
| @ -19,6 +19,7 @@ mod greater_block; | ||||
| mod greater_element; | ||||
| mod horizontal_rule; | ||||
| mod inline_babel_call; | ||||
| mod inline_source_block; | ||||
| mod keyword; | ||||
| mod latex_environment; | ||||
| mod latex_fragment; | ||||
| @ -83,6 +84,7 @@ pub use object::Entity; | ||||
| pub use object::ExportSnippet; | ||||
| pub use object::FootnoteReference; | ||||
| pub use object::InlineBabelCall; | ||||
| pub use object::InlineSourceBlock; | ||||
| pub use object::Italic; | ||||
| pub use object::LatexFragment; | ||||
| pub use object::Object; | ||||
|  | ||||
| @ -22,6 +22,7 @@ pub enum Object<'s> { | ||||
|     Citation(Citation<'s>), | ||||
|     CitationReference(CitationReference<'s>), | ||||
|     InlineBabelCall(InlineBabelCall<'s>), | ||||
|     InlineSourceBlock(InlineSourceBlock<'s>), | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, PartialEq)] | ||||
| @ -143,6 +144,11 @@ pub struct InlineBabelCall<'s> { | ||||
|     pub source: &'s str, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, PartialEq)] | ||||
| pub struct InlineSourceBlock<'s> { | ||||
|     pub source: &'s str, | ||||
| } | ||||
| 
 | ||||
| impl<'s> Source<'s> for Object<'s> { | ||||
|     fn get_source(&'s self) -> &'s str { | ||||
|         match self { | ||||
| @ -166,6 +172,7 @@ impl<'s> Source<'s> for Object<'s> { | ||||
|             Object::Citation(obj) => obj.source, | ||||
|             Object::CitationReference(obj) => obj.source, | ||||
|             Object::InlineBabelCall(obj) => obj.source, | ||||
|             Object::InlineSourceBlock(obj) => obj.source, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -283,3 +290,9 @@ impl<'s> Source<'s> for InlineBabelCall<'s> { | ||||
|         self.source | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<'s> Source<'s> for InlineSourceBlock<'s> { | ||||
|     fn get_source(&'s self) -> &'s str { | ||||
|         self.source | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -13,6 +13,7 @@ use crate::parser::entity::entity; | ||||
| use crate::parser::export_snippet::export_snippet; | ||||
| use crate::parser::footnote_reference::footnote_reference; | ||||
| use crate::parser::inline_babel_call::inline_babel_call; | ||||
| use crate::parser::inline_source_block::inline_source_block; | ||||
| use crate::parser::latex_fragment::latex_fragment; | ||||
| use crate::parser::object::Object; | ||||
| use crate::parser::org_macro::org_macro; | ||||
| @ -26,10 +27,14 @@ pub fn standard_set_object<'r, 's>( | ||||
|     context: Context<'r, 's>, | ||||
|     input: &'s str, | ||||
| ) -> Res<&'s str, Object<'s>> { | ||||
|     // TODO: inline source blocks, line breaks, targets (different from radio targets), statistics cookies, subscript and superscript, timestamps.
 | ||||
|     // TODO: line breaks, targets (different from radio targets), statistics cookies, subscript and superscript, timestamps.
 | ||||
|     not(|i| context.check_exit_matcher(i))(input)?; | ||||
| 
 | ||||
|     alt(( | ||||
|         map( | ||||
|             parser_with_context!(inline_source_block)(context), | ||||
|             Object::InlineSourceBlock, | ||||
|         ), | ||||
|         map( | ||||
|             parser_with_context!(inline_babel_call)(context), | ||||
|             Object::InlineBabelCall, | ||||
| @ -91,6 +96,10 @@ pub fn any_object_except_plain_text<'r, 's>( | ||||
| ) -> Res<&'s str, Object<'s>> { | ||||
|     // Used for exit matchers so this does not check exit matcher condition.
 | ||||
|     alt(( | ||||
|         map( | ||||
|             parser_with_context!(inline_source_block)(context), | ||||
|             Object::InlineSourceBlock, | ||||
|         ), | ||||
|         map( | ||||
|             parser_with_context!(inline_babel_call)(context), | ||||
|             Object::InlineBabelCall, | ||||
| @ -130,8 +139,12 @@ pub fn regular_link_description_object_set<'r, 's>( | ||||
|     context: Context<'r, 's>, | ||||
|     input: &'s str, | ||||
| ) -> Res<&'s str, Object<'s>> { | ||||
|     // TODO: minimal set of objects as well as export snippets, inline source blocks, and statistics cookies. It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
 | ||||
|     // TODO: minimal set of objects as well as export snippets, and statistics cookies. It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
 | ||||
|     alt(( | ||||
|         map( | ||||
|             parser_with_context!(inline_source_block)(context), | ||||
|             Object::InlineSourceBlock, | ||||
|         ), | ||||
|         map( | ||||
|             parser_with_context!(inline_babel_call)(context), | ||||
|             Object::InlineBabelCall, | ||||
|  | ||||
| @ -61,6 +61,7 @@ impl<'r, 's> Token<'r, 's> { | ||||
|                 Object::Citation(_) => Box::new(std::iter::empty()), // TODO: Iterate over children
 | ||||
|                 Object::CitationReference(_) => Box::new(std::iter::empty()), // TODO: Iterate over children
 | ||||
|                 Object::InlineBabelCall(_) => Box::new(std::iter::empty()), | ||||
|                 Object::InlineSourceBlock(_) => Box::new(std::iter::empty()), | ||||
|             }, | ||||
|             Token::Element(elem) => match elem { | ||||
|                 Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander