diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 5d34d35..787f038 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -757,11 +757,9 @@ fn compare_plain_list<'b, 's>( &mut message, )?; - compare_affiliated_keywords(emacs, rust)?.apply( - &mut child_status, - &mut this_status, - &mut message, - ); + for diff in compare_affiliated_keywords(source, emacs, rust)? { + diff.apply(&mut child_status, &mut this_status, &mut message); + } let affiliated_keywords_names: Vec = affiliated_keywords_names(rust).collect(); for diff in compare_properties!( diff --git a/src/compare/util.rs b/src/compare/util.rs index d7532bc..25a3eb7 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -1,5 +1,6 @@ use std::str::FromStr; +use super::compare_field::compare_property_quoted_string; use super::compare_field::ComparePropertiesResult; use super::diff::DiffEntry; use super::diff::DiffStatus; @@ -7,6 +8,7 @@ use super::elisp_fact::GetElispFact; use super::sexp::Token; use crate::compare::diff::compare_ast_node; use crate::compare::sexp::unquote; +use crate::types::AffiliatedKeywordValue; use crate::types::AstNode; use crate::types::GetAffiliatedKeywords; use crate::types::GetStandardProperties; @@ -340,28 +342,37 @@ where } pub(crate) fn compare_affiliated_keywords<'b, 's, GAK>( + source: &'s str, emacs: &'b Token<'s>, rust: &'b GAK, -) -> Result, Box> +) -> Result>, Box> where GAK: GetAffiliatedKeywords<'s>, { + let mut ret = Vec::new(); let affiliated_keywords = rust.get_affiliated_keywords(); for (rust_name, rust_value) in affiliated_keywords.keywords.iter() { let emacs_property_name = format!(":{}", rust_name); - let emacs_property = get_property(emacs, emacs_property_name.as_str())?; - if let Some(emacs_property) = emacs_property { - // foo - } else { - let this_status = DiffStatus::Bad; - let message = Some(format!( - "{} mismatch (emacs != rust) {:?} != {:?}", - rust_name, emacs_property, rust_value - )); - return Ok(ComparePropertiesResult::SelfChange(this_status, message)); - } + match rust_value { + AffiliatedKeywordValue::SingleString(rust_value) => { + let diff = compare_property_quoted_string( + source, + emacs, + rust, + emacs_property_name.as_str(), + |_| Some(*rust_value), + )?; + ret.push(diff); + } + AffiliatedKeywordValue::ListOfStrings(rust_value) => { + // foo + } + AffiliatedKeywordValue::ListOfListsOfObjects(rust_value) => { + // foo + } + }; } - Ok(ComparePropertiesResult::NoChange) + Ok(ret) } pub(crate) fn affiliated_keywords_names<'s, GAK>(rust: &'s GAK) -> impl Iterator + 's diff --git a/src/parser/affiliated_keyword.rs b/src/parser/affiliated_keyword.rs index 96ce33d..b096116 100644 --- a/src/parser/affiliated_keyword.rs +++ b/src/parser/affiliated_keyword.rs @@ -20,12 +20,12 @@ pub(crate) fn parse_affiliated_keywords<'g, 's>( let mut ret = BTreeMap::new(); for kw in input.into_iter() { let translated_name = translate_name(global_settings, kw.key); - if is_single_string_keyword(global_settings, translated_name) { + if is_single_string_keyword(global_settings, translated_name.as_str()) { ret.insert( translated_name, AffiliatedKeywordValue::SingleString(kw.value), ); - } else if is_list_of_objects_keyword(global_settings, translated_name) { + } else if is_list_of_objects_keyword(global_settings, translated_name.as_str()) { let initial_context = ContextElement::document_context(); let initial_context = Context::new(global_settings, List::new(&initial_context)); @@ -58,13 +58,13 @@ pub(crate) fn parse_affiliated_keywords<'g, 's>( AffiliatedKeywords { keywords: ret } } -fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s str) -> &'s str { +fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s str) -> String { for (src, dst) in global_settings.element_keyword_translation_alist { if name.eq_ignore_ascii_case(src) { - return *dst; + return dst.to_lowercase(); } } - name + name.to_lowercase() } fn is_single_string_keyword<'g, 's>( diff --git a/src/types/affiliated_keyword.rs b/src/types/affiliated_keyword.rs index ec1c0f6..fb2f0ee 100644 --- a/src/types/affiliated_keyword.rs +++ b/src/types/affiliated_keyword.rs @@ -17,7 +17,7 @@ pub struct AffiliatedKeyword<'s> { #[derive(Debug)] pub struct AffiliatedKeywords<'s> { - pub(crate) keywords: BTreeMap<&'s str, AffiliatedKeywordValue<'s>>, + pub(crate) keywords: BTreeMap>, } pub trait GetAffiliatedKeywords<'s> {