Merge branch 'keyword'
This commit is contained in:
		
						commit
						759d9088f2
					
				
							
								
								
									
										8
									
								
								build.rs
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								build.rs
									
									
									
									
									
								
							| @ -71,12 +71,8 @@ use organic::parser::sexp::sexp_with_padding; | ||||
| fn is_expect_fail(name: &str) -> Option<&str> { | ||||
|     match name { | ||||
|         "drawer_drawer_with_headline_inside" => Some("Apparently lines with :end: become their own paragraph. This odd behavior needs to be investigated more."), | ||||
|         "element_container_priority_drawer_dynamic_block" => Some("Keyword needs to be implemented."), | ||||
|         "element_container_priority_dynamic_block_dynamic_block" => Some("Keyword needs to be implemented."), | ||||
|         "element_container_priority_footnote_definition_dynamic_block" => Some("Keyword needs to be implemented."), | ||||
|         "element_container_priority_greater_block_dynamic_block" => Some("Keyword needs to be implemented."), | ||||
|         "element_container_priority_section_dynamic_block" => Some("Keyword needs to be implemented."), | ||||
|         "element_container_priority_readme" => Some("A lot needs to be implemented."), | ||||
|         "element_container_priority_footnote_definition_dynamic_block" => Some("Apparently broken begin lines become their own paragraph."), | ||||
|         "keyword_affiliated_keyword" => Some("Affiliated keywords would have to be implemented first."), | ||||
|         _ => None, | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										8
									
								
								org_mode_samples/keyword/affiliated_keyword.org
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								org_mode_samples/keyword/affiliated_keyword.org
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| #+name: foo | ||||
| #+caption: bar | ||||
| #+caption: baz | ||||
| [[file:lorem/ipsum.png]] | ||||
| 
 | ||||
| #+name: cat | ||||
| #+caption: dog | ||||
| [[file:lorem/ipsum.png]] | ||||
							
								
								
									
										2
									
								
								org_mode_samples/keyword/simple.org
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								org_mode_samples/keyword/simple.org
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| #+FOO: BAR | ||||
| #+LOREM: IPSUM | ||||
| @ -17,6 +17,7 @@ use crate::parser::FootnoteDefinition; | ||||
| use crate::parser::GreaterBlock; | ||||
| use crate::parser::Heading; | ||||
| use crate::parser::HorizontalRule; | ||||
| use crate::parser::Keyword; | ||||
| use crate::parser::Paragraph; | ||||
| use crate::parser::PlainList; | ||||
| use crate::parser::PlainListItem; | ||||
| @ -223,6 +224,7 @@ fn compare_element<'s>( | ||||
|         Element::Planning(obj) => compare_planning(source, emacs, obj), | ||||
|         Element::FixedWidthArea(obj) => compare_fixed_width_area(source, emacs, obj), | ||||
|         Element::HorizontalRule(obj) => compare_horizontal_rule(source, emacs, obj), | ||||
|         Element::Keyword(obj) => compare_keyword(source, emacs, obj), | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -804,3 +806,27 @@ fn compare_horizontal_rule<'s>( | ||||
|         children: child_status, | ||||
|     }) | ||||
| } | ||||
| 
 | ||||
| fn compare_keyword<'s>( | ||||
|     source: &'s str, | ||||
|     emacs: &'s Token<'s>, | ||||
|     rust: &'s Keyword<'s>, | ||||
| ) -> Result<DiffResult, Box<dyn std::error::Error>> { | ||||
|     let child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let emacs_name = "keyword"; | ||||
|     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: child_status, | ||||
|     }) | ||||
| } | ||||
|  | ||||
| @ -12,6 +12,7 @@ use super::lesser_element::ExampleBlock; | ||||
| use super::lesser_element::ExportBlock; | ||||
| use super::lesser_element::FixedWidthArea; | ||||
| use super::lesser_element::HorizontalRule; | ||||
| use super::lesser_element::Keyword; | ||||
| use super::lesser_element::Paragraph; | ||||
| use super::lesser_element::Planning; | ||||
| use super::lesser_element::SrcBlock; | ||||
| @ -40,6 +41,7 @@ pub enum Element<'s> { | ||||
|     Planning(Planning<'s>), | ||||
|     FixedWidthArea(FixedWidthArea<'s>), | ||||
|     HorizontalRule(HorizontalRule<'s>), | ||||
|     Keyword(Keyword<'s>), | ||||
| } | ||||
| 
 | ||||
| impl<'s> Source<'s> for Element<'s> { | ||||
| @ -64,6 +66,7 @@ impl<'s> Source<'s> for Element<'s> { | ||||
|             Element::Planning(obj) => obj.source, | ||||
|             Element::FixedWidthArea(obj) => obj.source, | ||||
|             Element::HorizontalRule(obj) => obj.source, | ||||
|             Element::Keyword(obj) => obj.source, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -8,6 +8,7 @@ use super::fixed_width_area::fixed_width_area; | ||||
| use super::footnote_definition::footnote_definition; | ||||
| use super::greater_block::greater_block; | ||||
| use super::horizontal_rule::horizontal_rule; | ||||
| use super::keyword::keyword; | ||||
| use super::lesser_block::comment_block; | ||||
| use super::lesser_block::example_block; | ||||
| use super::lesser_block::export_block; | ||||
| @ -53,6 +54,7 @@ pub fn non_paragraph_element<'r, 's>( | ||||
|     let diary_sexp_matcher = parser_with_context!(diary_sexp)(context); | ||||
|     let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context); | ||||
|     let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context); | ||||
|     let keyword_matcher = parser_with_context!(keyword)(context); | ||||
|     alt(( | ||||
|         map(plain_list_matcher, Element::PlainList), | ||||
|         map(greater_block_matcher, Element::GreaterBlock), | ||||
| @ -70,5 +72,6 @@ pub fn non_paragraph_element<'r, 's>( | ||||
|         map(diary_sexp_matcher, Element::DiarySexp), | ||||
|         map(fixed_width_area_matcher, Element::FixedWidthArea), | ||||
|         map(horizontal_rule_matcher, Element::HorizontalRule), | ||||
|         map(keyword_matcher, Element::Keyword), | ||||
|     ))(input) | ||||
| } | ||||
|  | ||||
							
								
								
									
										34
									
								
								src/parser/keyword.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/parser/keyword.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| use nom::branch::alt; | ||||
| use nom::bytes::complete::is_not; | ||||
| use nom::bytes::complete::tag; | ||||
| use nom::bytes::complete::tag_no_case; | ||||
| use nom::character::complete::line_ending; | ||||
| use nom::character::complete::space0; | ||||
| use nom::character::complete::space1; | ||||
| use nom::combinator::eof; | ||||
| use nom::combinator::not; | ||||
| use nom::combinator::peek; | ||||
| use nom::combinator::recognize; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::Context; | ||||
| use crate::error::Res; | ||||
| use crate::parser::util::start_of_line; | ||||
| use crate::parser::Keyword; | ||||
| 
 | ||||
| #[tracing::instrument(ret, level = "debug")] | ||||
| pub fn keyword<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Keyword<'s>> { | ||||
|     start_of_line(context, input)?; | ||||
|     // TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
 | ||||
|     let (remaining, rule) = recognize(tuple(( | ||||
|         space0, | ||||
|         tag("#+"), | ||||
|         not(peek(tag_no_case("call"))), | ||||
|         not(peek(tag_no_case("begin"))), | ||||
|         is_not(" \t\r\n:"), | ||||
|         tag(":"), | ||||
|         alt((recognize(tuple((space1, is_not("\r\n")))), space0)), | ||||
|         alt((line_ending, eof)), | ||||
|     )))(input)?; | ||||
|     Ok((remaining, Keyword { source: rule })) | ||||
| } | ||||
| @ -84,6 +84,11 @@ pub struct HorizontalRule<'s> { | ||||
|     pub source: &'s str, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct Keyword<'s> { | ||||
|     pub source: &'s str, | ||||
| } | ||||
| 
 | ||||
| impl<'s> Paragraph<'s> { | ||||
|     pub fn of_text(input: &'s str) -> Self { | ||||
|         let mut objects = Vec::with_capacity(1); | ||||
| @ -168,3 +173,9 @@ impl<'s> Source<'s> for HorizontalRule<'s> { | ||||
|         self.source | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<'s> Source<'s> for Keyword<'s> { | ||||
|     fn get_source(&'s self) -> &'s str { | ||||
|         self.source | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -12,6 +12,7 @@ mod footnote_definition; | ||||
| mod greater_block; | ||||
| mod greater_element; | ||||
| mod horizontal_rule; | ||||
| mod keyword; | ||||
| mod lesser_block; | ||||
| mod lesser_element; | ||||
| mod list; | ||||
| @ -51,6 +52,7 @@ pub use lesser_element::ExampleBlock; | ||||
| pub use lesser_element::ExportBlock; | ||||
| pub use lesser_element::FixedWidthArea; | ||||
| pub use lesser_element::HorizontalRule; | ||||
| pub use lesser_element::Keyword; | ||||
| pub use lesser_element::Paragraph; | ||||
| pub use lesser_element::Planning; | ||||
| pub use lesser_element::SrcBlock; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander