diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 9a0fe22..ca79a9e 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -3347,14 +3347,45 @@ fn compare_footnote_reference<'b, 's>( } fn compare_citation<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Citation<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut child_status = Vec::new(); + let mut this_status = DiffStatus::Good; + let mut message = None; - // TODO: Compare :style :prefix :suffix + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + + if let Some((new_status, new_message)) = compare_properties!( + emacs, + rust, + ( + EmacsField::Required(":style"), + |r| r.style, + compare_property_quoted_string + ), + ( + EmacsField::Required(":prefix"), + |r| r.prefix, + compare_property_unquoted_atom + ), + ( + EmacsField::Required(":suffix"), + |r| r.suffix, + compare_property_unquoted_atom + ) + )? { + this_status = new_status; + message = new_message; + } Ok(DiffResult { status: this_status, @@ -3375,7 +3406,30 @@ fn compare_citation_reference<'b, 's>( let this_status = DiffStatus::Good; let message = None; - // TODO: Compare :key :prefix :suffix + assert_no_children(emacs, &mut this_status, &mut message)?; + + if let Some((new_status, new_message)) = compare_properties!( + emacs, + rust, + ( + EmacsField::Required(":key"), + |r| Some(r.key), + compare_property_quoted_string + ), + ( + EmacsField::Required(":prefix"), + |r| r.prefix, + compare_property_unquoted_atom + ), + ( + EmacsField::Required(":suffix"), + |r| r.suffix, + compare_property_unquoted_atom + ) + )? { + this_status = new_status; + message = new_message; + } Ok(DiffResult { status: this_status, diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 696d9a4..bd7cc05 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -33,10 +33,10 @@ pub(crate) fn citation_reference<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, CitationReference<'s>> { - let (remaining, _prefix) = + let (remaining, prefix) = must_balance_bracket(opt(parser_with_context!(key_prefix)(context)))(input)?; - let (remaining, _key) = parser_with_context!(citation_reference_key)(context)(remaining)?; - let (remaining, _suffix) = + let (remaining, key) = parser_with_context!(citation_reference_key)(context)(remaining)?; + let (remaining, suffix) = must_balance_bracket(opt(parser_with_context!(key_suffix)(context)))(remaining)?; let source = get_consumed(input, remaining); @@ -44,6 +44,9 @@ pub(crate) fn citation_reference<'b, 'g, 'r, 's>( remaining, CitationReference { source: source.into(), + key: key.into(), + prefix: prefix.unwrap_or(Vec::new()), + suffix: suffix.unwrap_or(Vec::new()), }, )) } diff --git a/src/types/object.rs b/src/types/object.rs index 7d7e287..9018b40 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -209,6 +209,9 @@ pub struct Citation<'s> { #[derive(Debug, PartialEq)] pub struct CitationReference<'s> { pub source: &'s str, + pub key: &'s str, + pub prefix: Vec>, + pub suffix: Vec>, } #[derive(Debug, PartialEq)]