Compare export type.

This commit is contained in:
Tom Alexander 2023-10-05 02:15:32 -04:00
parent 1da521b08a
commit 58ca9569a6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 22 additions and 1 deletions

View File

@ -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 {

View File

@ -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,
},

View File

@ -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<String> {
self.export_type.map(|s| s.to_uppercase())
}
}