From a588da2c4a108c66ad4afb7b3a46d27300e0eee5 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 19:37:47 -0400 Subject: [PATCH] Compare target properties. --- src/compare/diff.rs | 31 ++++++++++++++++++++++++++----- src/parser/target.rs | 10 +++------- src/types/object.rs | 1 + 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 60c251c..8802988 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -3739,20 +3739,41 @@ fn compare_line_break<'b, 's>( } fn compare_target<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Target<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); + let mut message = None; - // TODO: Compare :value + assert_no_children(emacs, &mut this_status, &mut message)?; + + for diff in compare_properties!( + source, + emacs, + rust, + ( + EmacsField::Required(":value"), + |r| Some(r.value), + compare_property_quoted_string + ) + ) { + 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 { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } diff --git a/src/parser/target.rs b/src/parser/target.rs index b73acd4..187721c 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -4,12 +4,10 @@ use nom::character::complete::one_of; use nom::combinator::peek; use nom::combinator::recognize; use nom::combinator::verify; -use nom::multi::many_till; use super::org_source::OrgSource; -use super::util::exit_matcher_parser; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use crate::context::parser_with_context; +use super::util::text_until_exit; use crate::context::ContextElement; use crate::context::ExitClass; use crate::context::ExitMatcherNode; @@ -38,10 +36,7 @@ pub(crate) fn target<'b, 'g, 'r, 's>( exit_matcher: &target_end, }); let parser_context = context.with_additional_node(&parser_context); - let (remaining, _body) = recognize(many_till( - anychar, - parser_with_context!(exit_matcher_parser)(&parser_context), - ))(remaining)?; + let (remaining, body) = text_until_exit(&parser_context, remaining)?; let preceding_character = remaining .get_preceding_character() @@ -60,6 +55,7 @@ pub(crate) fn target<'b, 'g, 'r, 's>( remaining, Target { source: source.into(), + value: body.into(), }, )) } diff --git a/src/types/object.rs b/src/types/object.rs index b35803f..5230eef 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -240,6 +240,7 @@ pub struct LineBreak<'s> { #[derive(Debug, PartialEq)] pub struct Target<'s> { pub source: &'s str, + pub value: &'s str, } #[derive(Debug, PartialEq)]