From 90ba17b68ccecb16256bb459a7ce8edf6f8218c9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Oct 2023 22:32:01 -0400 Subject: [PATCH] Switch to a numeric post-blank. Turns out post-blank has different meanings to different object types so we need to return a number to properly do the compare. --- src/compare/util.rs | 4 +-- src/types/ast_node.rs | 3 +- src/types/document.rs | 9 ++--- src/types/element.rs | 3 +- src/types/greater_element.rs | 25 +++++++------- src/types/lesser_element.rs | 33 +++++++++--------- src/types/mod.rs | 1 + src/types/object.rs | 57 ++++++++++++++++---------------- src/types/standard_properties.rs | 8 +++-- 9 files changed, 76 insertions(+), 67 deletions(-) diff --git a/src/compare/util.rs b/src/compare/util.rs index 0a8b424..5e60021 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -128,11 +128,11 @@ fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>( rust: &'b S, ) -> Result<(), Box> { let standard_properties = get_emacs_standard_properties(emacs)?; // 1-based - let rust_post_blank = rust.get_post_blank().chars().count(); + let rust_post_blank = rust.get_post_blank(); let emacs_post_blank = standard_properties .post_blank .ok_or("Token should have a post-blank.")?; - if rust_post_blank != emacs_post_blank { + if rust_post_blank as usize != emacs_post_blank { Err(format!("Rust post-blank (in chars) {rust_post_blank} does not match emacs post-blank ({emacs_post_blank})", rust_post_blank = rust_post_blank, emacs_post_blank = emacs_post_blank))?; } diff --git a/src/types/ast_node.rs b/src/types/ast_node.rs index d634723..bd02c77 100644 --- a/src/types/ast_node.rs +++ b/src/types/ast_node.rs @@ -1,5 +1,6 @@ use super::macros::to_ast_node; use super::CenterBlock; +use super::PostBlank; use super::QuoteBlock; use super::SpecialBlock; use super::StandardProperties; @@ -386,7 +387,7 @@ impl<'r, 's> StandardProperties<'s> for AstNode<'r, 's> { } } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { match self { AstNode::Document(inner) => inner.get_post_blank(), AstNode::Heading(inner) => inner.get_post_blank(), diff --git a/src/types/document.rs b/src/types/document.rs index 8c756c0..42b9754 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use super::Element; use super::NodeProperty; use super::Object; +use super::PostBlank; use super::StandardProperties; use super::Timestamp; @@ -62,7 +63,7 @@ impl<'s> StandardProperties<'s> for Document<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -76,7 +77,7 @@ impl<'s> StandardProperties<'s> for Section<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -90,7 +91,7 @@ impl<'s> StandardProperties<'s> for Heading<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -158,7 +159,7 @@ impl<'s> StandardProperties<'s> for DocumentElement<'s> { } } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { match self { DocumentElement::Heading(inner) => inner.get_post_blank(), DocumentElement::Section(inner) => inner.get_post_blank(), diff --git a/src/types/element.rs b/src/types/element.rs index 8c3b03b..4d34554 100644 --- a/src/types/element.rs +++ b/src/types/element.rs @@ -20,6 +20,7 @@ use super::lesser_element::SrcBlock; use super::lesser_element::VerseBlock; use super::CenterBlock; use super::Drawer; +use super::PostBlank; use super::QuoteBlock; use super::SpecialBlock; use super::StandardProperties; @@ -112,7 +113,7 @@ impl<'s> StandardProperties<'s> for Element<'s> { } } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { match self { Element::Paragraph(inner) => inner.get_post_blank(), Element::PlainList(inner) => inner.get_post_blank(), diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index f3e3fc3..c30d078 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -4,6 +4,7 @@ use super::lesser_element::TableCell; use super::AffiliatedKeywords; use super::Keyword; use super::Object; +use super::PostBlank; use super::StandardProperties; #[derive(Debug)] @@ -136,7 +137,7 @@ impl<'s> StandardProperties<'s> for PlainList<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -150,7 +151,7 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -164,7 +165,7 @@ impl<'s> StandardProperties<'s> for CenterBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -178,7 +179,7 @@ impl<'s> StandardProperties<'s> for QuoteBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -192,7 +193,7 @@ impl<'s> StandardProperties<'s> for SpecialBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -206,7 +207,7 @@ impl<'s> StandardProperties<'s> for DynamicBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -220,7 +221,7 @@ impl<'s> StandardProperties<'s> for FootnoteDefinition<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -234,7 +235,7 @@ impl<'s> StandardProperties<'s> for Drawer<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -248,7 +249,7 @@ impl<'s> StandardProperties<'s> for PropertyDrawer<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -262,7 +263,7 @@ impl<'s> StandardProperties<'s> for NodeProperty<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -276,7 +277,7 @@ impl<'s> StandardProperties<'s> for Table<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -290,7 +291,7 @@ impl<'s> StandardProperties<'s> for TableRow<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 68a2b9d..7d6b2ad 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -16,6 +16,7 @@ use super::object::Object; use super::AffiliatedKeywords; use super::GetAffiliatedKeywords; use super::PlainText; +use super::PostBlank; use super::StandardProperties; use super::Timestamp; use crate::error::CustomError; @@ -203,7 +204,7 @@ impl<'s> StandardProperties<'s> for Paragraph<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -217,7 +218,7 @@ impl<'s> StandardProperties<'s> for TableCell<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -231,7 +232,7 @@ impl<'s> StandardProperties<'s> for Comment<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -245,7 +246,7 @@ impl<'s> StandardProperties<'s> for VerseBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -258,7 +259,7 @@ impl<'s> StandardProperties<'s> for CommentBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -271,7 +272,7 @@ impl<'s> StandardProperties<'s> for ExampleBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -284,7 +285,7 @@ impl<'s> StandardProperties<'s> for ExportBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -297,7 +298,7 @@ impl<'s> StandardProperties<'s> for SrcBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -311,7 +312,7 @@ impl<'s> StandardProperties<'s> for Clock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -325,7 +326,7 @@ impl<'s> StandardProperties<'s> for DiarySexp<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -339,7 +340,7 @@ impl<'s> StandardProperties<'s> for Planning<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -353,7 +354,7 @@ impl<'s> StandardProperties<'s> for FixedWidthArea<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -367,7 +368,7 @@ impl<'s> StandardProperties<'s> for HorizontalRule<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -381,7 +382,7 @@ impl<'s> StandardProperties<'s> for Keyword<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -395,7 +396,7 @@ impl<'s> StandardProperties<'s> for BabelCall<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -409,7 +410,7 @@ impl<'s> StandardProperties<'s> for LatexEnvironment<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 7dad80b..e142dce 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -110,4 +110,5 @@ pub use object::WarningDelay; pub use object::WarningDelayType; pub use object::Year; pub use object::YearInner; +pub use standard_properties::PostBlank; pub use standard_properties::StandardProperties; diff --git a/src/types/object.rs b/src/types/object.rs index ed7bf0e..b77d849 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -6,6 +6,7 @@ use super::util::coalesce_whitespace_if_line_break; use super::util::remove_line_break; use super::util::remove_whitespace_if_line_break; use super::util::to_lowercase; +use super::PostBlank; use super::StandardProperties; #[derive(Debug)] @@ -523,7 +524,7 @@ impl<'s> StandardProperties<'s> for Bold<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -537,7 +538,7 @@ impl<'s> StandardProperties<'s> for Italic<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -551,7 +552,7 @@ impl<'s> StandardProperties<'s> for Underline<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -565,7 +566,7 @@ impl<'s> StandardProperties<'s> for StrikeThrough<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -579,7 +580,7 @@ impl<'s> StandardProperties<'s> for Code<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -593,7 +594,7 @@ impl<'s> StandardProperties<'s> for Verbatim<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -607,7 +608,7 @@ impl<'s> StandardProperties<'s> for RegularLink<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -621,7 +622,7 @@ impl<'s> StandardProperties<'s> for RadioLink<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -635,7 +636,7 @@ impl<'s> StandardProperties<'s> for RadioTarget<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -649,7 +650,7 @@ impl<'s> StandardProperties<'s> for PlainLink<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -663,7 +664,7 @@ impl<'s> StandardProperties<'s> for AngleLink<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -677,7 +678,7 @@ impl<'s> StandardProperties<'s> for OrgMacro<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -691,7 +692,7 @@ impl<'s> StandardProperties<'s> for Entity<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -705,7 +706,7 @@ impl<'s> StandardProperties<'s> for LatexFragment<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -719,7 +720,7 @@ impl<'s> StandardProperties<'s> for ExportSnippet<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -733,7 +734,7 @@ impl<'s> StandardProperties<'s> for FootnoteReference<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -747,7 +748,7 @@ impl<'s> StandardProperties<'s> for Citation<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -761,7 +762,7 @@ impl<'s> StandardProperties<'s> for CitationReference<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -775,7 +776,7 @@ impl<'s> StandardProperties<'s> for InlineBabelCall<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -789,7 +790,7 @@ impl<'s> StandardProperties<'s> for InlineSourceBlock<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -803,7 +804,7 @@ impl<'s> StandardProperties<'s> for LineBreak<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -817,7 +818,7 @@ impl<'s> StandardProperties<'s> for Target<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -831,7 +832,7 @@ impl<'s> StandardProperties<'s> for StatisticsCookie<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -845,7 +846,7 @@ impl<'s> StandardProperties<'s> for Subscript<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -859,7 +860,7 @@ impl<'s> StandardProperties<'s> for Superscript<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -873,7 +874,7 @@ impl<'s> StandardProperties<'s> for Timestamp<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -887,7 +888,7 @@ impl<'s> StandardProperties<'s> for PlainText<'s> { todo!() } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { todo!() } } @@ -1048,7 +1049,7 @@ impl<'s> StandardProperties<'s> for Object<'s> { } } - fn get_post_blank<'b>(&'b self) -> &'s str { + fn get_post_blank<'b>(&'b self) -> PostBlank { match self { Object::Bold(inner) => inner.get_post_blank(), Object::Italic(inner) => inner.get_post_blank(), diff --git a/src/types/standard_properties.rs b/src/types/standard_properties.rs index e11dc54..49b8844 100644 --- a/src/types/standard_properties.rs +++ b/src/types/standard_properties.rs @@ -10,10 +10,10 @@ pub trait StandardProperties<'s> { /// This corresponds to :contents-begin to :contents-end fn get_contents<'b>(&'b self) -> &'s str; - /// Get the slice of the AST node's post-blank text. + /// Get the ast node's post-blank. /// - /// This is optional whitespace following the node. - fn get_post_blank<'b>(&'b self) -> &'s str; + /// For objects this is a count of the characters of whitespace after the object. For elements this is a count of the line breaks following an element. + fn get_post_blank<'b>(&'b self) -> PostBlank; } // TODO: Write some debugging code to alert when any of the unknown fields below are non-nil in our test data so we can see what these fields represent. @@ -61,3 +61,5 @@ pub trait StandardProperties<'s> { // X :parent - Some weird numeric reference to the containing object. Since we output a tree structure, I do not see any value in including this, especially considering the back-references would be a nightmare in rust. // Special case: Plain text. Plain text counts :begin and :end from the start of the text (so :begin is always 0 AFAICT) and instead of including the full set of standard properties, it only includes :begin, :end, and :parent. + +pub type PostBlank = u8;