From a26640355c140eebad26ee45961b37bd88b60000 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 4 Oct 2023 19:56:39 -0400 Subject: [PATCH] Add check for name on paragraph. --- org_mode_samples/lesser_element/paragraph/name.org | 2 ++ src/compare/diff.rs | 14 ++++++++++++-- src/parser/element_parser.rs | 10 +++++++++- src/parser/paragraph.rs | 1 + src/types/lesser_element.rs | 2 ++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 org_mode_samples/lesser_element/paragraph/name.org diff --git a/org_mode_samples/lesser_element/paragraph/name.org b/org_mode_samples/lesser_element/paragraph/name.org new file mode 100644 index 00000000..5cc5a63f --- /dev/null +++ b/org_mode_samples/lesser_element/paragraph/name.org @@ -0,0 +1,2 @@ +#+NAME: foo +bar diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 085a804d..f4e82d01 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -841,8 +841,18 @@ fn compare_paragraph<'b, 's>( ) -> Result, Box> { let children = emacs.as_list()?; let mut child_status = Vec::new(); - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut message = None; + + // Compare name + let name = get_property_quoted_string(emacs, ":name")?; + if name.as_ref().map(String::as_str) != rust.name { + this_status = DiffStatus::Bad; + message = Some(format!( + "Name mismatch (emacs != rust) {:?} != {:?}", + name, rust.name + )); + } for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 2fd0f6c7..5bc49339 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -1,6 +1,8 @@ use nom::branch::alt; use nom::combinator::map; +use nom::combinator::not; use nom::multi::many0; +use nom::sequence::tuple; use super::clock::clock; use super::comment::comment; @@ -98,7 +100,13 @@ fn _element<'b, 'g, 'r, 's>( map(horizontal_rule_matcher, Element::HorizontalRule), map(latex_environment_matcher, Element::LatexEnvironment), map(babel_keyword_matcher, Element::BabelCall), - map(keyword_matcher, Element::Keyword), + map( + map( + tuple((not(affiliated_keyword_matcher), keyword_matcher)), + |(_, kw)| kw, + ), + Element::Keyword, + ), ))(remaining) { the_ok @ Ok(_) => the_ok, diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index ba5aeeef..049fe784 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -47,6 +47,7 @@ pub(crate) fn paragraph<'b, 'g, 'r, 's>( remaining, Paragraph { source: source.into(), + name: None, // TODO children, }, )) diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 92302e35..759ad996 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -6,6 +6,7 @@ use super::Timestamp; #[derive(Debug)] pub struct Paragraph<'s> { pub source: &'s str, + pub name: Option<&'s str>, pub children: Vec>, } @@ -146,6 +147,7 @@ impl<'s> Paragraph<'s> { objects.push(Object::PlainText(PlainText { source: input })); Paragraph { source: input, + name: None, // TODO children: objects, } }