From 58ca9569a6c41e9665694b022a790788c5be20c7 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 02:15:32 -0400 Subject: [PATCH] Compare export type. --- src/compare/diff.rs | 12 +++++++++++- src/parser/lesser_block.rs | 4 ++++ src/types/lesser_element.rs | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 9c82f011..cef815e1 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1845,9 +1845,19 @@ fn compare_export_block<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; - // TODO: Compare :type // TODO: Compare :caption + // Compare type + let export_type = get_property_quoted_string(emacs, ":type")?; + let rust_export_type = rust.get_export_type(); + if export_type != rust_export_type { + this_status = DiffStatus::Bad; + message = Some(format!( + "Export type mismatch (emacs != rust) {:?} != {:?}", + export_type, rust.export_type + )); + } + // Compare value let contents = get_property_quoted_string(emacs, ":value")?.unwrap_or(String::new()); if contents != rust.contents { diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 994f4f76..fe987cbf 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -208,6 +208,9 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>( let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; let (remaining, _) = lesser_block_begin("export")(context, input)?; // https://orgmode.org/worg/org-syntax.html#Blocks claims that export blocks must have a single word for data but testing shows no data and multi-word data still parses as an export block. + let (remaining, export_type) = opt(map(tuple((space1, switch_word)), |(_, export_type)| { + export_type + }))(remaining)?; let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = recognize(tuple((space0, line_ending)))(remaining)?; let lesser_block_end_specialized = lesser_block_end("export"); @@ -236,6 +239,7 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>( ExportBlock { source: source.into(), name: get_name(&affiliated_keywords), + export_type: export_type.map(Into::<&str>::into), data: parameters.map(|parameters| Into::<&str>::into(parameters)), contents, }, diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index b62f61c6..4b41a568 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -64,6 +64,7 @@ pub struct ExampleBlock<'s> { pub struct ExportBlock<'s> { pub source: &'s str, pub name: Option<&'s str>, + pub export_type: Option<&'s str>, pub data: Option<&'s str>, pub contents: String, } @@ -266,3 +267,9 @@ impl<'s> Comment<'s> { ret } } + +impl<'s> ExportBlock<'s> { + pub fn get_export_type(&self) -> Option { + self.export_type.map(|s| s.to_uppercase()) + } +}