Populate citation reference properties.

This commit is contained in:
Tom Alexander 2023-10-09 14:17:37 -04:00
parent 1ecc3ecf9d
commit c077d34933
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 68 additions and 8 deletions

View File

@ -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<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
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,

View File

@ -33,10 +33,10 @@ pub(crate) fn citation_reference<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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()),
},
))
}

View File

@ -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<Object<'s>>,
pub suffix: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]