Update all comparisons to handle affiliated keywords.

This commit is contained in:
Tom Alexander 2023-10-11 14:57:32 -04:00
parent 9523365090
commit 41b4b1015e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 143 additions and 234 deletions

View File

@ -713,21 +713,7 @@ fn compare_paragraph<'b, 's>(
&mut message,
)?;
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
)
) {
for diff in compare_properties!(source, emacs, rust, [],) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
@ -772,16 +758,6 @@ fn compare_plain_list<'b, 's>(
emacs,
rust,
[],
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
(
EmacsField::Required(":type"),
|r| Some(match r.list_type {
@ -912,21 +888,7 @@ fn compare_center_block<'b, 's>(
&mut message,
)?;
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
)
) {
for diff in compare_properties!(source, emacs, rust, [],) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
@ -966,21 +928,7 @@ fn compare_quote_block<'b, 's>(
&mut message,
)?;
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
)
) {
for diff in compare_properties!(source, emacs, rust, [],) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
@ -1024,16 +972,7 @@ fn compare_special_block<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":type"),
|r| Some(r.block_type),
@ -1093,16 +1032,7 @@ fn compare_dynamic_block<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":block-name"),
|r| Some(r.block_name),
@ -1157,16 +1087,7 @@ fn compare_footnote_definition<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":label"),
|r| Some(r.label),
@ -1263,16 +1184,7 @@ fn compare_drawer<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":drawer-name"),
|r| Some(r.drawer_name),
@ -1409,16 +1321,7 @@ fn compare_table<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":tblfm"),
|r| if r.formulas.is_empty() {
@ -1570,21 +1473,7 @@ fn compare_verse_block<'b, 's>(
&mut message,
)?;
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
)
) {
for diff in compare_properties!(source, emacs, rust, [],) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
@ -1621,16 +1510,7 @@ fn compare_comment_block<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":value"),
|r| Some(r.contents),
@ -1673,16 +1553,7 @@ fn compare_example_block<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":value"),
|r| Some(r.contents.as_str()),
@ -1755,16 +1626,7 @@ fn compare_export_block<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":type"),
|r| r.get_export_type(),
@ -1812,16 +1674,7 @@ fn compare_src_block<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":language"),
|r| r.language,
@ -1959,16 +1812,7 @@ fn compare_diary_sexp<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":value"),
|r| Some(r.value),
@ -2063,16 +1907,7 @@ fn compare_fixed_width_area<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":value"),
|r| Some(r.get_value()),
@ -2111,21 +1946,7 @@ fn compare_horizontal_rule<'b, 's>(
assert_no_children(emacs, &mut this_status, &mut message)?;
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
)
) {
for diff in compare_properties!(source, emacs, rust, [],) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
@ -2162,16 +1983,7 @@ fn compare_keyword<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":key"),
|r| Some(r.key.to_uppercase()),
@ -2219,16 +2031,7 @@ fn compare_babel_call<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":value"),
|r| Some(r.value),
@ -2291,16 +2094,7 @@ fn compare_latex_environment<'b, 's>(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
[],
(
EmacsField::Required(":value"),
|r| Some(r.value),

View File

@ -30,7 +30,7 @@
/// }
/// ```
macro_rules! compare_properties {
($source:expr, $emacs:expr, $rust:expr, $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),+) => {
($source:expr, $emacs:expr, $rust:expr, $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),*) => {
{
let mut new_status = Vec::new();
let children = $emacs.as_list()?;
@ -63,7 +63,7 @@ macro_rules! compare_properties {
},
EmacsField::Optional(_name) => {},
}
)+
)*
if !emacs_keys.is_empty() {
let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect();
@ -91,13 +91,13 @@ macro_rules! compare_properties {
new_status.push(result);
}
}
)+
)*
new_status
}
};
// For elements with affiliated keywords
($source:expr, $emacs:expr, $rust:expr, [], $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),+) => {
($source:expr, $emacs:expr, $rust:expr, [], $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),*) => {
{
let mut new_status = Vec::new();
let children = $emacs.as_list()?;
@ -148,7 +148,7 @@ macro_rules! compare_properties {
},
EmacsField::Optional(_name) => {},
}
)+
)*
if !emacs_keys.is_empty() {
let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect();
@ -180,13 +180,13 @@ macro_rules! compare_properties {
new_status.push(result);
}
}
)+
)*
new_status
}
};
// Specifies additional properties
($source:expr, $emacs:expr, $rust:expr, $additionalproperties: expr, $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),+) => {
($source:expr, $emacs:expr, $rust:expr, $additionalproperties: expr, $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),*) => {
{
let mut new_status = Vec::new();
let children = $emacs.as_list()?;
@ -236,7 +236,7 @@ macro_rules! compare_properties {
},
EmacsField::Optional(_name) => {},
}
)+
)*
if !emacs_keys.is_empty() {
let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect();
@ -264,7 +264,7 @@ macro_rules! compare_properties {
new_status.push(result);
}
}
)+
)*
new_status
}

View File

@ -226,3 +226,45 @@ impl<'s> GetAffiliatedKeywords<'s> for PlainList<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for Table<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for Drawer<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for FootnoteDefinition<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for DynamicBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for SpecialBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for CenterBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for QuoteBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}

View File

@ -1,5 +1,6 @@
use super::object::Object;
use super::AffiliatedKeywords;
use super::GetAffiliatedKeywords;
use super::PlainText;
use super::StandardProperties;
use super::Timestamp;
@ -303,3 +304,75 @@ impl<'s> ExportBlock<'s> {
self.export_type.map(|s| s.to_uppercase())
}
}
impl<'s> GetAffiliatedKeywords<'s> for Paragraph<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for LatexEnvironment<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for BabelCall<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for Keyword<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for HorizontalRule<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for FixedWidthArea<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for DiarySexp<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for SrcBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for ExportBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for ExampleBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for CommentBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}
impl<'s> GetAffiliatedKeywords<'s> for VerseBlock<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s> {
&self.affiliated_keywords
}
}