From 8d621b32dc333428e20127fb0197dbe932898e8a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 7 Oct 2023 00:57:55 -0400 Subject: [PATCH] Compare radio link properties. --- src/compare/diff.rs | 58 ++++++++++++++++++++++++++++++++++---- src/parser/radio_link.rs | 3 ++ src/parser/regular_link.rs | 4 ++- src/types/object.rs | 3 ++ 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 0ea57a8..426f42e 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2758,11 +2758,13 @@ fn compare_strike_through<'b, 's>( } fn compare_regular_link<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b RegularLink<'s>, ) -> Result, Box> { + let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; if let Some((new_status, new_message)) = compare_properties!( @@ -2812,6 +2814,10 @@ fn compare_regular_link<'b, 's>( message = new_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())?); + } + Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2824,14 +2830,56 @@ fn compare_regular_link<'b, 's>( } fn compare_radio_link<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b RadioLink<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let children = emacs.as_list()?; + let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); + let mut message = None; - // TODO: Compare :type :path :format :raw-link :application :search-option + if let Some((new_status, new_message)) = compare_properties!( + emacs, + rust, + ( + EmacsField::Required(":type"), + |_| { Some("radio") }, + compare_property_quoted_string + ), + ( + EmacsField::Required(":path"), + |r| Some(&r.path), + compare_property_quoted_string + ), + ( + EmacsField::Required(":format"), + |_| Some("plain"), + compare_property_unquoted_atom + ), + ( + EmacsField::Required(":raw-link"), + |r| Some(&r.raw_link), + compare_property_quoted_string + ), + ( + EmacsField::Required(":application"), + compare_identity, + compare_property_always_nil + ), + ( + EmacsField::Required(":search-option"), + compare_identity, + compare_property_always_nil + ) + )? { + this_status = new_status; + message = new_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())?); + } Ok(DiffResult { status: this_status, diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index c76a94e..a83f171 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -30,6 +30,7 @@ pub(crate) fn radio_link<'b, 'g, 'r, 's>( for radio_target in &context.get_global_settings().radio_targets { let rematched_target = rematch_target(context, radio_target, input); if let Ok((remaining, rematched_target)) = rematched_target { + let path = get_consumed(input, remaining); let (remaining, _) = space0(remaining)?; let source = get_consumed(input, remaining); return Ok(( @@ -37,6 +38,8 @@ pub(crate) fn radio_link<'b, 'g, 'r, 's>( RadioLink { source: source.into(), children: rematched_target, + path: path.into(), + raw_link: path.into(), }, )); } diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index a99dee3..e0812fe 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -68,6 +68,7 @@ fn regular_link_without_description<'b, 'g, 'r, 's>( path: path.path, raw_link: path.raw_link, search_option: path.search_option, + children: Vec::new(), }, )) } @@ -80,7 +81,7 @@ fn regular_link_with_description<'b, 'g, 'r, 's>( let (remaining, _opening_bracket) = tag("[[")(input)?; let (remaining, path) = pathreg(context, remaining)?; let (remaining, _closing_bracket) = tag("][")(remaining)?; - let (remaining, _description) = description(context, remaining)?; + let (remaining, description) = description(context, remaining)?; let (remaining, _closing_bracket) = tag("]]")(remaining)?; let (remaining, _trailing_whitespace) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; @@ -93,6 +94,7 @@ fn regular_link_with_description<'b, 'g, 'r, 's>( path: path.path, raw_link: path.raw_link, search_option: path.search_option, + children: description, }, )) } diff --git a/src/types/object.rs b/src/types/object.rs index 68b5bc0..a177d41 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -84,6 +84,7 @@ pub struct RegularLink<'s> { pub path: Cow<'s, str>, pub raw_link: Cow<'s, str>, pub search_option: Option>, + pub children: Vec>, } #[derive(Debug, PartialEq)] @@ -95,6 +96,8 @@ pub struct RadioTarget<'s> { #[derive(Debug, PartialEq)] pub struct RadioLink<'s> { pub source: &'s str, + pub path: Cow<'s, str>, + pub raw_link: Cow<'s, str>, pub children: Vec>, }