From 6bc6fdc87bd0d78baebd731564ab42378dc0ecf7 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 19:21:58 -0400 Subject: [PATCH] Compare properties for inline babel calls. --- .../object/inline_babel_call/simple.org | 1 + src/compare/diff.rs | 51 +++++++++++++++++-- src/parser/inline_babel_call.rs | 5 ++ src/types/object.rs | 5 ++ 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/org_mode_samples/object/inline_babel_call/simple.org b/org_mode_samples/object/inline_babel_call/simple.org index 4add233..f98222a 100644 --- a/org_mode_samples/object/inline_babel_call/simple.org +++ b/org_mode_samples/object/inline_babel_call/simple.org @@ -1,3 +1,4 @@ +call_foo() call_foo(arguments) call_bar[header](arguments) call_baz(arguments)[header] diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 7eeb4d3..5cead57 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -3592,20 +3592,61 @@ fn compare_citation_reference<'b, 's>( } fn compare_inline_babel_call<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b InlineBabelCall<'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 :call :inside-header :arguments :end-header :value + assert_no_children(emacs, &mut this_status, &mut message)?; + + for diff in compare_properties!( + source, + emacs, + rust, + ( + EmacsField::Required(":call"), + |r| Some(r.call), + compare_property_quoted_string + ), + ( + EmacsField::Required(":inside-header"), + |r| r.inside_header, + compare_property_quoted_string + ), + ( + EmacsField::Required(":arguments"), + |r| r.arguments, + compare_property_quoted_string + ), + ( + EmacsField::Required(":end-header"), + |r| r.end_header, + compare_property_quoted_string + ), + ( + 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/inline_babel_call.rs b/src/parser/inline_babel_call.rs index 41abea6..d1d3f6b 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -45,6 +45,11 @@ pub(crate) fn inline_babel_call<'b, 'g, 'r, 's>( remaining, InlineBabelCall { source: source.into(), + value: todo!(), + call: todo!(), + inside_header: todo!(), + arguments: todo!(), + end_header: todo!(), }, )) } diff --git a/src/types/object.rs b/src/types/object.rs index 9018b40..004abdf 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -217,6 +217,11 @@ pub struct CitationReference<'s> { #[derive(Debug, PartialEq)] pub struct InlineBabelCall<'s> { pub source: &'s str, + pub value: &'s str, + pub call: &'s str, + pub inside_header: Option<&'s str>, + pub arguments: Option<&'s str>, + pub end_header: Option<&'s str>, } #[derive(Debug, PartialEq)]