Update all elements to the new AffiliatedKeywords.
This commit is contained in:
		
							parent
							
								
									aa33fe42a8
								
							
						
					
					
						commit
						9523365090
					
				| @ -27,7 +27,6 @@ use super::util::compare_affiliated_keywords; | ||||
| use super::util::compare_children; | ||||
| use super::util::compare_children_iter; | ||||
| use super::util::compare_standard_properties; | ||||
| use super::util::get_property_quoted_string; | ||||
| use crate::compare::compare_field::ComparePropertiesResult; | ||||
| use crate::compare::compare_field::EmacsField; | ||||
| use crate::compare::macros::compare_properties; | ||||
| @ -900,24 +899,42 @@ fn compare_center_block<'b, 's>( | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b CenterBlock<'s>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     let children = emacs.as_list()?; | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut message = None; | ||||
| 
 | ||||
|     // TODO: Compare :caption
 | ||||
|     // Compare name
 | ||||
|     let name = get_property_quoted_string(emacs, ":name")?; | ||||
|     if name.as_ref().map(String::as_str) != rust.name { | ||||
|         this_status = DiffStatus::Bad; | ||||
|         message = Some(format!( | ||||
|             "Name mismatch (emacs != rust) {:?} != {:?}", | ||||
|             name, rust.name | ||||
|         )); | ||||
|     } | ||||
|     compare_children( | ||||
|         source, | ||||
|         emacs, | ||||
|         &rust.children, | ||||
|         &mut child_status, | ||||
|         &mut this_status, | ||||
|         &mut message, | ||||
|     )?; | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     for diff in compare_properties!( | ||||
|         source, | ||||
|         emacs, | ||||
|         rust, | ||||
|         ( | ||||
|             EmacsField::Optional(":name"), | ||||
|             |r| r.name, | ||||
|             compare_property_quoted_string | ||||
|         ), | ||||
|         ( | ||||
|             EmacsField::Optional(":caption"), | ||||
|             compare_identity, | ||||
|             compare_noop | ||||
|         ) | ||||
|     ) { | ||||
|         match diff { | ||||
|             ComparePropertiesResult::NoChange => {} | ||||
|             ComparePropertiesResult::SelfChange(new_status, new_message) => { | ||||
|                 this_status = new_status; | ||||
|                 message = new_message | ||||
|             } | ||||
|             ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
|  | ||||
| @ -14,9 +14,9 @@ use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| use nom::InputTake; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::BracketDepth; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use super::util::start_of_line; | ||||
| use super::OrgSource; | ||||
| @ -50,7 +50,10 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>( | ||||
|             remaining, | ||||
|             BabelCall { | ||||
|                 source: Into::<&str>::into(source), | ||||
|                 name: get_name(&affiliated_keywords), | ||||
|                 affiliated_keywords: parse_affiliated_keywords( | ||||
|                     context.get_global_settings(), | ||||
|                     affiliated_keywords, | ||||
|                 ), | ||||
|                 value: Into::<&str>::into(line_break.take(0)), | ||||
|                 call: None, | ||||
|                 inside_header: None, | ||||
| @ -73,7 +76,10 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         BabelCall { | ||||
|             source: Into::<&str>::into(source), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             value: Into::<&str>::into(value).trim_end(), | ||||
|             call: call.map(Into::<&str>::into), | ||||
|             inside_header: inside_header.map(Into::<&str>::into), | ||||
|  | ||||
| @ -4,9 +4,9 @@ use nom::combinator::recognize; | ||||
| use nom::multi::many0; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use super::util::org_line_ending; | ||||
| use crate::context::RefContext; | ||||
| @ -35,7 +35,10 @@ pub(crate) fn diary_sexp<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         DiarySexp { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             value: Into::<&str>::into(value), | ||||
|         }, | ||||
|     )) | ||||
|  | ||||
| @ -11,9 +11,9 @@ use nom::multi::many0; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::parser_with_context; | ||||
| use crate::context::ContextElement; | ||||
| @ -100,7 +100,10 @@ pub(crate) fn drawer<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         Drawer { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             drawer_name: drawer_name.into(), | ||||
|             children, | ||||
|         }, | ||||
|  | ||||
| @ -17,9 +17,9 @@ use nom::multi::many_till; | ||||
| use nom::sequence::preceded; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::parser_with_context; | ||||
| use crate::context::ContextElement; | ||||
| @ -107,7 +107,10 @@ pub(crate) fn dynamic_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         DynamicBlock { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             block_name: name.into(), | ||||
|             parameters: parameters.map(|val| val.into()), | ||||
|             children, | ||||
|  | ||||
| @ -9,9 +9,9 @@ use nom::multi::many_till; | ||||
| use nom::sequence::preceded; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use super::util::org_line_ending; | ||||
| use crate::context::parser_with_context; | ||||
| @ -57,7 +57,10 @@ pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         FixedWidthArea { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             value, | ||||
|         }, | ||||
|     )) | ||||
|  | ||||
| @ -11,9 +11,9 @@ use nom::multi::many1; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::include_input; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use super::util::WORD_CONSTITUENT_CHARACTERS; | ||||
| @ -94,7 +94,10 @@ pub(crate) fn footnote_definition<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         FootnoteDefinition { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             label: lbl.into(), | ||||
|             children: children.into_iter().map(|(_, item)| item).collect(), | ||||
|         }, | ||||
|  | ||||
| @ -17,9 +17,9 @@ use nom::multi::many_till; | ||||
| use nom::sequence::preceded; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::in_section; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::parser_with_context; | ||||
| @ -71,19 +71,19 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>( | ||||
|             context, | ||||
|             remaining, | ||||
|             pre_affiliated_keywords_input, | ||||
|             &affiliated_keywords, | ||||
|             affiliated_keywords, | ||||
|         )?, | ||||
|         "quote" => quote_block( | ||||
|             context, | ||||
|             remaining, | ||||
|             pre_affiliated_keywords_input, | ||||
|             &affiliated_keywords, | ||||
|             affiliated_keywords, | ||||
|         )?, | ||||
|         _ => special_block(name)( | ||||
|             context, | ||||
|             remaining, | ||||
|             pre_affiliated_keywords_input, | ||||
|             &affiliated_keywords, | ||||
|             affiliated_keywords, | ||||
|         )?, | ||||
|     }; | ||||
|     Ok((remaining, element)) | ||||
| @ -97,7 +97,7 @@ fn center_block<'b, 'g, 'r, 's>( | ||||
|     context: RefContext<'b, 'g, 'r, 's>, | ||||
|     input: OrgSource<'s>, | ||||
|     pre_affiliated_keywords_input: OrgSource<'s>, | ||||
|     affiliated_keywords: &Vec<Keyword<'s>>, | ||||
|     affiliated_keywords: Vec<Keyword<'s>>, | ||||
| ) -> Res<OrgSource<'s>, Element<'s>> { | ||||
|     let (remaining, (source, children)) = greater_block_body( | ||||
|         context, | ||||
| @ -110,7 +110,10 @@ fn center_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         Element::CenterBlock(CenterBlock { | ||||
|             source, | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             children, | ||||
|         }), | ||||
|     )) | ||||
| @ -124,7 +127,7 @@ fn quote_block<'b, 'g, 'r, 's>( | ||||
|     context: RefContext<'b, 'g, 'r, 's>, | ||||
|     input: OrgSource<'s>, | ||||
|     pre_affiliated_keywords_input: OrgSource<'s>, | ||||
|     affiliated_keywords: &Vec<Keyword<'s>>, | ||||
|     affiliated_keywords: Vec<Keyword<'s>>, | ||||
| ) -> Res<OrgSource<'s>, Element<'s>> { | ||||
|     let (remaining, (source, children)) = greater_block_body( | ||||
|         context, | ||||
| @ -137,7 +140,10 @@ fn quote_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         Element::QuoteBlock(QuoteBlock { | ||||
|             source, | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             children, | ||||
|         }), | ||||
|     )) | ||||
| @ -149,7 +155,7 @@ fn special_block<'s>( | ||||
|     RefContext<'b, 'g, 'r, 's>, | ||||
|     OrgSource<'s>, | ||||
|     OrgSource<'s>, | ||||
|     &Vec<Keyword<'s>>, | ||||
|     Vec<Keyword<'s>>, | ||||
| ) -> Res<OrgSource<'s>, Element<'s>> | ||||
|        + 's { | ||||
|     let context_name = format!("special block {}", name); | ||||
| @ -175,7 +181,7 @@ fn _special_block<'c, 'b, 'g, 'r, 's>( | ||||
|     pre_affiliated_keywords_input: OrgSource<'s>, | ||||
|     name: &'s str, | ||||
|     context_name: &'c str, | ||||
|     affiliated_keywords: &Vec<Keyword<'s>>, | ||||
|     affiliated_keywords: Vec<Keyword<'s>>, | ||||
| ) -> Res<OrgSource<'s>, Element<'s>> { | ||||
|     let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?; | ||||
|     let (remaining, (source, children)) = greater_block_body( | ||||
| @ -189,7 +195,10 @@ fn _special_block<'c, 'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         Element::SpecialBlock(SpecialBlock { | ||||
|             source, | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             children, | ||||
|             block_type: name, | ||||
|             parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)), | ||||
|  | ||||
| @ -9,10 +9,10 @@ use nom::multi::many0; | ||||
| use nom::multi::many1_count; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_consumed; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::RefContext; | ||||
| use crate::error::Res; | ||||
| @ -42,7 +42,10 @@ pub(crate) fn horizontal_rule<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         HorizontalRule { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|         }, | ||||
|     )) | ||||
| } | ||||
|  | ||||
| @ -17,10 +17,10 @@ use nom::multi::many0; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::org_source::BracketDepth; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_consumed; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::Matcher; | ||||
| use crate::context::RefContext; | ||||
| @ -28,6 +28,7 @@ use crate::error::CustomError; | ||||
| use crate::error::MyError; | ||||
| use crate::error::Res; | ||||
| use crate::parser::util::start_of_line; | ||||
| use crate::types::AffiliatedKeywords; | ||||
| use crate::types::Keyword; | ||||
| 
 | ||||
| const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [ | ||||
| @ -64,7 +65,7 @@ fn _filtered_keyword<'s, F: Matcher>( | ||||
|                 remaining, | ||||
|                 Keyword { | ||||
|                     source: consumed_input.into(), | ||||
|                     name: None, // To be populated by the caller if this keyword is in a context to support affiliated keywords.
 | ||||
|                     affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
 | ||||
|                     key: parsed_key.into(), | ||||
|                     value: "".into(), | ||||
|                 }, | ||||
| @ -82,7 +83,7 @@ fn _filtered_keyword<'s, F: Matcher>( | ||||
|         remaining, | ||||
|         Keyword { | ||||
|             source: consumed_input.into(), | ||||
|             name: None, // To be populated by the caller if this keyword is in a context to support affiliated keywords.
 | ||||
|             affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
 | ||||
|             key: parsed_key.into(), | ||||
|             value: parsed_value.into(), | ||||
|         }, | ||||
| @ -102,7 +103,8 @@ pub(crate) fn keyword<'b, 'g, 'r, 's>( | ||||
|     let (remaining, _trailing_ws) = | ||||
|         maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; | ||||
|     let source = get_consumed(input, remaining); | ||||
|     kw.name = get_name(&affiliated_keywords); | ||||
|     kw.affiliated_keywords = | ||||
|         parse_affiliated_keywords(context.get_global_settings(), affiliated_keywords); | ||||
|     kw.source = Into::<&str>::into(source); | ||||
|     Ok((remaining, kw)) | ||||
| } | ||||
|  | ||||
| @ -12,10 +12,10 @@ use nom::multi::many0; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_consumed; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::parser_with_context; | ||||
| use crate::context::ContextElement; | ||||
| @ -67,7 +67,10 @@ pub(crate) fn latex_environment<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         LatexEnvironment { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             value: value.into(), | ||||
|         }, | ||||
|     )) | ||||
|  | ||||
| @ -18,9 +18,9 @@ use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| use nom::InputTake; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::parser_with_context; | ||||
| use crate::context::ContextElement; | ||||
| @ -103,7 +103,10 @@ pub(crate) fn verse_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         VerseBlock { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             data: parameters.map(|parameters| Into::<&str>::into(parameters)), | ||||
|             children, | ||||
|         }, | ||||
| @ -145,7 +148,10 @@ pub(crate) fn comment_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         CommentBlock { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             contents: contents.into(), | ||||
|         }, | ||||
|     )) | ||||
| @ -213,7 +219,10 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         ExampleBlock { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             switches, | ||||
|             number_lines, | ||||
|             preserve_indent, | ||||
| @ -266,7 +275,10 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         ExportBlock { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             export_type: export_type.map(Into::<&str>::into), | ||||
|             data: parameters.map(|parameters| Into::<&str>::into(parameters)), | ||||
|             contents, | ||||
| @ -332,7 +344,10 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         SrcBlock { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             language: language.map(Into::<&str>::into), | ||||
|             switches, | ||||
|             parameters: parameters.map(Into::<&str>::into), | ||||
|  | ||||
| @ -7,13 +7,13 @@ use nom::multi::many1; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::element_parser::detect_element; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::blank_line; | ||||
| use super::util::get_consumed; | ||||
| use super::util::get_has_affiliated_keyword; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use crate::context::parser_with_context; | ||||
| use crate::context::ContextElement; | ||||
| @ -68,7 +68,10 @@ pub(crate) fn paragraph<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         Paragraph { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             children, | ||||
|         }, | ||||
|     )) | ||||
|  | ||||
| @ -23,7 +23,6 @@ use super::element_parser::element; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::object_parser::standard_set_object; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::get_name; | ||||
| use super::util::include_input; | ||||
| use super::util::indentation_level; | ||||
| use super::util::non_whitespace_character; | ||||
| @ -160,7 +159,6 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>( | ||||
|     let (remaining, _trailing_ws) = | ||||
|         maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; | ||||
|     let source = get_consumed(input, remaining); | ||||
|     let name = get_name(&affiliated_keywords); | ||||
|     Ok(( | ||||
|         remaining, | ||||
|         PlainList { | ||||
| @ -169,7 +167,6 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             name, | ||||
|             list_type: first_item_list_type.expect("Plain lists require at least one element."), | ||||
|             children: children.into_iter().map(|(_start, item)| item).collect(), | ||||
|         }, | ||||
|  | ||||
| @ -13,12 +13,12 @@ use nom::multi::many1; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| 
 | ||||
| use super::affiliated_keyword::parse_affiliated_keywords; | ||||
| use super::keyword::affiliated_keyword; | ||||
| use super::keyword::table_formula_keyword; | ||||
| use super::object_parser::table_cell_set_object; | ||||
| use super::org_source::OrgSource; | ||||
| use super::util::exit_matcher_parser; | ||||
| use super::util::get_name; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| use super::util::org_line_ending; | ||||
| use crate::context::parser_with_context; | ||||
| @ -77,7 +77,10 @@ pub(crate) fn org_mode_table<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         Table { | ||||
|             source: source.into(), | ||||
|             name: get_name(&affiliated_keywords), | ||||
|             affiliated_keywords: parse_affiliated_keywords( | ||||
|                 context.get_global_settings(), | ||||
|                 affiliated_keywords, | ||||
|             ), | ||||
|             formulas, | ||||
|             children, | ||||
|         }, | ||||
|  | ||||
| @ -23,7 +23,6 @@ use crate::error::CustomError; | ||||
| use crate::error::MyError; | ||||
| use crate::error::Res; | ||||
| use crate::types::IndentationLevel; | ||||
| use crate::types::Keyword; | ||||
| 
 | ||||
| pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str = | ||||
|     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||||
| @ -272,21 +271,6 @@ pub(crate) fn indentation_level<'b, 'g, 'r, 's>( | ||||
|     Ok((remaining, (indentation_level, leading_whitespace))) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn get_name<'s>(affiliated_keywords: &Vec<Keyword<'s>>) -> Option<&'s str> { | ||||
|     let name_keyword = affiliated_keywords | ||||
|         .iter() | ||||
|         .filter(|kw| { | ||||
|             kw.key.eq_ignore_ascii_case("name") | ||||
|                 || kw.key.eq_ignore_ascii_case("source") | ||||
|                 || kw.key.eq_ignore_ascii_case("tblname") | ||||
|                 || kw.key.eq_ignore_ascii_case("resname") | ||||
|                 || kw.key.eq_ignore_ascii_case("srcname") | ||||
|                 || kw.key.eq_ignore_ascii_case("label") | ||||
|         }) | ||||
|         .last(); | ||||
|     name_keyword.map(|kw| kw.value) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn get_has_affiliated_keyword<'b, 'g, 'r, 's>( | ||||
|     context: RefContext<'b, 'g, 'r, 's>, | ||||
| ) -> Option<OrgSource<'s>> { | ||||
|  | ||||
| @ -23,3 +23,11 @@ pub struct AffiliatedKeywords<'s> { | ||||
| pub trait GetAffiliatedKeywords<'s> { | ||||
|     fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s>; | ||||
| } | ||||
| 
 | ||||
| impl<'s> Default for AffiliatedKeywords<'s> { | ||||
|     fn default() -> Self { | ||||
|         AffiliatedKeywords { | ||||
|             keywords: BTreeMap::new(), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -10,7 +10,6 @@ use super::StandardProperties; | ||||
| pub struct PlainList<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub list_type: PlainListType, | ||||
|     pub children: Vec<PlainListItem<'s>>, | ||||
| } | ||||
| @ -50,21 +49,21 @@ pub enum CheckboxType { | ||||
| #[derive(Debug)] | ||||
| pub struct CenterBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub children: Vec<Element<'s>>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct QuoteBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub children: Vec<Element<'s>>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct SpecialBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub block_type: &'s str, | ||||
|     pub parameters: Option<&'s str>, | ||||
|     pub children: Vec<Element<'s>>, | ||||
| @ -73,7 +72,7 @@ pub struct SpecialBlock<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct DynamicBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub block_name: &'s str, | ||||
|     pub parameters: Option<&'s str>, | ||||
|     pub children: Vec<Element<'s>>, | ||||
| @ -82,7 +81,7 @@ pub struct DynamicBlock<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct FootnoteDefinition<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub label: &'s str, | ||||
|     pub children: Vec<Element<'s>>, | ||||
| } | ||||
| @ -90,7 +89,7 @@ pub struct FootnoteDefinition<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct Drawer<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub drawer_name: &'s str, | ||||
|     pub children: Vec<Element<'s>>, | ||||
| } | ||||
| @ -111,7 +110,7 @@ pub struct NodeProperty<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct Table<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub formulas: Vec<Keyword<'s>>, | ||||
|     pub children: Vec<TableRow<'s>>, | ||||
| } | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| use super::object::Object; | ||||
| use super::AffiliatedKeywords; | ||||
| use super::PlainText; | ||||
| use super::StandardProperties; | ||||
| use super::Timestamp; | ||||
| @ -6,7 +7,7 @@ use super::Timestamp; | ||||
| #[derive(Debug)] | ||||
| pub struct Paragraph<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub children: Vec<Object<'s>>, | ||||
| } | ||||
| 
 | ||||
| @ -25,7 +26,7 @@ pub struct TableCell<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct VerseBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub data: Option<&'s str>, | ||||
|     pub children: Vec<Object<'s>>, | ||||
| } | ||||
| @ -33,7 +34,7 @@ pub struct VerseBlock<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct CommentBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub contents: &'s str, | ||||
| } | ||||
| 
 | ||||
| @ -50,7 +51,7 @@ pub enum RetainLabels { | ||||
| #[derive(Debug)] | ||||
| pub struct ExampleBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub switches: Option<&'s str>, | ||||
|     pub number_lines: Option<SwitchNumberLines>, | ||||
|     pub preserve_indent: Option<CharOffsetInLine>, | ||||
| @ -63,7 +64,7 @@ pub struct ExampleBlock<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct ExportBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub export_type: Option<&'s str>, | ||||
|     pub data: Option<&'s str>, | ||||
|     pub contents: String, | ||||
| @ -72,7 +73,7 @@ pub struct ExportBlock<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct SrcBlock<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub language: Option<&'s str>, | ||||
|     pub switches: Option<&'s str>, | ||||
|     pub parameters: Option<&'s str>, | ||||
| @ -101,7 +102,7 @@ pub struct Clock<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct DiarySexp<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub value: &'s str, | ||||
| } | ||||
| 
 | ||||
| @ -116,20 +117,20 @@ pub struct Planning<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct FixedWidthArea<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub value: Vec<&'s str>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct HorizontalRule<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct Keyword<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub key: &'s str, | ||||
|     pub value: &'s str, | ||||
| } | ||||
| @ -137,7 +138,7 @@ pub struct Keyword<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct BabelCall<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub value: &'s str, | ||||
|     pub call: Option<&'s str>, | ||||
|     pub inside_header: Option<&'s str>, | ||||
| @ -148,7 +149,7 @@ pub struct BabelCall<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct LatexEnvironment<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub name: Option<&'s str>, | ||||
|     pub affiliated_keywords: AffiliatedKeywords<'s>, | ||||
|     pub value: &'s str, | ||||
| } | ||||
| 
 | ||||
| @ -172,7 +173,7 @@ impl<'s> Paragraph<'s> { | ||||
|         objects.push(Object::PlainText(PlainText { source: input })); | ||||
|         Paragraph { | ||||
|             source: input, | ||||
|             name: None, | ||||
|             affiliated_keywords: AffiliatedKeywords::default(), | ||||
|             children: objects, | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander