From 95233650905fe942c299a67e7ad0ddea3d22feb8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 14:44:25 -0400 Subject: [PATCH] Update all elements to the new AffiliatedKeywords. --- src/compare/diff.rs | 47 +++++++++++++++++++++---------- src/parser/babel_call.rs | 12 ++++++-- src/parser/diary_sexp.rs | 7 +++-- src/parser/drawer.rs | 7 +++-- src/parser/dynamic_block.rs | 7 +++-- src/parser/fixed_width_area.rs | 7 +++-- src/parser/footnote_definition.rs | 7 +++-- src/parser/greater_block.rs | 31 ++++++++++++-------- src/parser/horizontal_rule.rs | 7 +++-- src/parser/keyword.rs | 10 ++++--- src/parser/latex_environment.rs | 7 +++-- src/parser/lesser_block.rs | 27 ++++++++++++++---- src/parser/paragraph.rs | 7 +++-- src/parser/plain_list.rs | 3 -- src/parser/table.rs | 7 +++-- src/parser/util.rs | 16 ----------- src/types/affiliated_keyword.rs | 8 ++++++ src/types/greater_element.rs | 15 +++++----- src/types/lesser_element.rs | 27 +++++++++--------- 19 files changed, 162 insertions(+), 97 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 2ce309d..a1856b9 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -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, Box> { - 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 { diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index cafb83e..eaeae75 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -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), diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 7b667ab..698b30f 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -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), }, )) diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 36fda09..438a007 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -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, }, diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 8bd0739..6086176 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -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, diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 4025c8e..0260784 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -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, }, )) diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 3386c59..1ce9aef 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -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(), }, diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 4d5e72d..17ba072 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -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>, + affiliated_keywords: Vec>, ) -> Res, 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>, + affiliated_keywords: Vec>, ) -> Res, 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>, + Vec>, ) -> Res, 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>, + affiliated_keywords: Vec>, ) -> Res, 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)), diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index f6466df..d331f91 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -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, + ), }, )) } diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 70bf4ed..cb6ae15 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -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)) } diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 692d046..44002f5 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -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(), }, )) diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 06e5de9..2870c82 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -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), diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 6848726..23dff72 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -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, }, )) diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index b5f0f83..3035f6b 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -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(), }, diff --git a/src/parser/table.rs b/src/parser/table.rs index f3b5a33..857a55d 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -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, }, diff --git a/src/parser/util.rs b/src/parser/util.rs index 14388ad..05a292e 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -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>) -> 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> { diff --git a/src/types/affiliated_keyword.rs b/src/types/affiliated_keyword.rs index fb2f0ee..f3dd94e 100644 --- a/src/types/affiliated_keyword.rs +++ b/src/types/affiliated_keyword.rs @@ -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(), + } + } +} diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index 3660f74..2ffcbd0 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -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>, } @@ -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>, } #[derive(Debug)] pub struct QuoteBlock<'s> { pub source: &'s str, - pub name: Option<&'s str>, + pub affiliated_keywords: AffiliatedKeywords<'s>, pub children: Vec>, } #[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>, @@ -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>, @@ -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>, } @@ -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>, } @@ -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>, pub children: Vec>, } diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index bf2ac27..51fd6cb 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -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>, } @@ -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>, } @@ -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, pub preserve_indent: Option, @@ -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, } }