From 92592104a424d0fbe2a5584dfd1c0c84cf15573e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Oct 2023 22:10:19 -0400 Subject: [PATCH] Compare contents begin/end. --- src/compare/util.rs | 47 ++++++++++++++++++++------- src/types/ast_node.rs | 2 +- src/types/document.rs | 8 ++--- src/types/element.rs | 2 +- src/types/greater_element.rs | 24 +++++++------- src/types/lesser_element.rs | 32 +++++++++--------- src/types/object.rs | 56 ++++++++++++++++---------------- src/types/standard_properties.rs | 2 +- 8 files changed, 98 insertions(+), 75 deletions(-) diff --git a/src/compare/util.rs b/src/compare/util.rs index 91ccaea7..f55a9a36 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -79,18 +79,41 @@ fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>( rust: &'b S, ) -> Result<(), Box> { let standard_properties = get_emacs_standard_properties(emacs)?; // 1-based - let (begin, end) = ( - standard_properties - .begin - .ok_or("Token should have a begin.")?, - standard_properties.end.ok_or("Token should have an end.")?, - ); - let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust.get_source()); // 0-based - let rust_begin_char_offset = original_document[..rust_begin].chars().count() + 1; // 1-based - let rust_end_char_offset = - rust_begin_char_offset + original_document[rust_begin..rust_end].chars().count(); // 1-based - if rust_begin_char_offset != begin || rust_end_char_offset != end { - Err(format!("Rust bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?; + + // Check begin/end + { + let (begin, end) = ( + standard_properties + .begin + .ok_or("Token should have a begin.")?, + standard_properties.end.ok_or("Token should have an end.")?, + ); + let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust.get_source()); // 0-based + let rust_begin_char_offset = original_document[..rust_begin].chars().count() + 1; // 1-based + let rust_end_char_offset = + rust_begin_char_offset + original_document[rust_begin..rust_end].chars().count(); // 1-based + if rust_begin_char_offset != begin || rust_end_char_offset != end { + Err(format!("Rust bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?; + } + } + + // Check contents-begin/contents-end + { + let (begin, end) = ( + standard_properties + .contents_begin + .ok_or("Token should have a begin.")?, + standard_properties + .contents_end + .ok_or("Token should have an end.")?, + ); + let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust.get_contents()); // 0-based + let rust_begin_char_offset = original_document[..rust_begin].chars().count() + 1; // 1-based + let rust_end_char_offset = + rust_begin_char_offset + original_document[rust_begin..rust_end].chars().count(); // 1-based + if rust_begin_char_offset != begin || rust_end_char_offset != end { + Err(format!("Rust bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?; + } } Ok(()) diff --git a/src/types/ast_node.rs b/src/types/ast_node.rs index 75749d3d..d634723b 100644 --- a/src/types/ast_node.rs +++ b/src/types/ast_node.rs @@ -323,7 +323,7 @@ impl<'r, 's> StandardProperties<'s> for AstNode<'r, 's> { } } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { match self { AstNode::Document(inner) => inner.get_contents(), AstNode::Heading(inner) => inner.get_contents(), diff --git a/src/types/document.rs b/src/types/document.rs index ccb468aa..8c756c0a 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -58,7 +58,7 @@ impl<'s> StandardProperties<'s> for Document<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -72,7 +72,7 @@ impl<'s> StandardProperties<'s> for Section<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -86,7 +86,7 @@ impl<'s> StandardProperties<'s> for Heading<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -151,7 +151,7 @@ impl<'s> StandardProperties<'s> for DocumentElement<'s> { } } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { match self { DocumentElement::Heading(inner) => inner.get_contents(), DocumentElement::Section(inner) => inner.get_contents(), diff --git a/src/types/element.rs b/src/types/element.rs index 49e54d1a..8c3b03b7 100644 --- a/src/types/element.rs +++ b/src/types/element.rs @@ -83,7 +83,7 @@ impl<'s> StandardProperties<'s> for Element<'s> { } } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { match self { Element::Paragraph(inner) => inner.get_contents(), Element::PlainList(inner) => inner.get_contents(), diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index f459537a..f3e3fc38 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -132,7 +132,7 @@ impl<'s> StandardProperties<'s> for PlainList<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -146,7 +146,7 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -160,7 +160,7 @@ impl<'s> StandardProperties<'s> for CenterBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -174,7 +174,7 @@ impl<'s> StandardProperties<'s> for QuoteBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -188,7 +188,7 @@ impl<'s> StandardProperties<'s> for SpecialBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -202,7 +202,7 @@ impl<'s> StandardProperties<'s> for DynamicBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -216,7 +216,7 @@ impl<'s> StandardProperties<'s> for FootnoteDefinition<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -230,7 +230,7 @@ impl<'s> StandardProperties<'s> for Drawer<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -244,7 +244,7 @@ impl<'s> StandardProperties<'s> for PropertyDrawer<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -258,7 +258,7 @@ impl<'s> StandardProperties<'s> for NodeProperty<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -272,7 +272,7 @@ impl<'s> StandardProperties<'s> for Table<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -286,7 +286,7 @@ impl<'s> StandardProperties<'s> for TableRow<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 3241a98f..68a2b9d4 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -199,7 +199,7 @@ impl<'s> StandardProperties<'s> for Paragraph<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -213,7 +213,7 @@ impl<'s> StandardProperties<'s> for TableCell<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -227,7 +227,7 @@ impl<'s> StandardProperties<'s> for Comment<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -241,7 +241,7 @@ impl<'s> StandardProperties<'s> for VerseBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -254,7 +254,7 @@ impl<'s> StandardProperties<'s> for CommentBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -267,7 +267,7 @@ impl<'s> StandardProperties<'s> for ExampleBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -280,7 +280,7 @@ impl<'s> StandardProperties<'s> for ExportBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -293,7 +293,7 @@ impl<'s> StandardProperties<'s> for SrcBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -307,7 +307,7 @@ impl<'s> StandardProperties<'s> for Clock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -321,7 +321,7 @@ impl<'s> StandardProperties<'s> for DiarySexp<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -335,7 +335,7 @@ impl<'s> StandardProperties<'s> for Planning<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -349,7 +349,7 @@ impl<'s> StandardProperties<'s> for FixedWidthArea<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -363,7 +363,7 @@ impl<'s> StandardProperties<'s> for HorizontalRule<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -377,7 +377,7 @@ impl<'s> StandardProperties<'s> for Keyword<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -391,7 +391,7 @@ impl<'s> StandardProperties<'s> for BabelCall<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -405,7 +405,7 @@ impl<'s> StandardProperties<'s> for LatexEnvironment<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } diff --git a/src/types/object.rs b/src/types/object.rs index 87a23b6b..ed7bf0ef 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -519,7 +519,7 @@ impl<'s> StandardProperties<'s> for Bold<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -533,7 +533,7 @@ impl<'s> StandardProperties<'s> for Italic<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -547,7 +547,7 @@ impl<'s> StandardProperties<'s> for Underline<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -561,7 +561,7 @@ impl<'s> StandardProperties<'s> for StrikeThrough<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -575,7 +575,7 @@ impl<'s> StandardProperties<'s> for Code<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -589,7 +589,7 @@ impl<'s> StandardProperties<'s> for Verbatim<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -603,7 +603,7 @@ impl<'s> StandardProperties<'s> for RegularLink<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -617,7 +617,7 @@ impl<'s> StandardProperties<'s> for RadioLink<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -631,7 +631,7 @@ impl<'s> StandardProperties<'s> for RadioTarget<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -645,7 +645,7 @@ impl<'s> StandardProperties<'s> for PlainLink<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -659,7 +659,7 @@ impl<'s> StandardProperties<'s> for AngleLink<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -673,7 +673,7 @@ impl<'s> StandardProperties<'s> for OrgMacro<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -687,7 +687,7 @@ impl<'s> StandardProperties<'s> for Entity<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -701,7 +701,7 @@ impl<'s> StandardProperties<'s> for LatexFragment<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -715,7 +715,7 @@ impl<'s> StandardProperties<'s> for ExportSnippet<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -729,7 +729,7 @@ impl<'s> StandardProperties<'s> for FootnoteReference<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -743,7 +743,7 @@ impl<'s> StandardProperties<'s> for Citation<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -757,7 +757,7 @@ impl<'s> StandardProperties<'s> for CitationReference<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -771,7 +771,7 @@ impl<'s> StandardProperties<'s> for InlineBabelCall<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -785,7 +785,7 @@ impl<'s> StandardProperties<'s> for InlineSourceBlock<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -799,7 +799,7 @@ impl<'s> StandardProperties<'s> for LineBreak<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -813,7 +813,7 @@ impl<'s> StandardProperties<'s> for Target<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -827,7 +827,7 @@ impl<'s> StandardProperties<'s> for StatisticsCookie<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -841,7 +841,7 @@ impl<'s> StandardProperties<'s> for Subscript<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -855,7 +855,7 @@ impl<'s> StandardProperties<'s> for Superscript<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -869,7 +869,7 @@ impl<'s> StandardProperties<'s> for Timestamp<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -883,7 +883,7 @@ impl<'s> StandardProperties<'s> for PlainText<'s> { self.source } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { todo!() } @@ -1016,7 +1016,7 @@ impl<'s> StandardProperties<'s> for Object<'s> { } } - fn get_contents(&'s self) -> &'s str { + fn get_contents<'b>(&'b self) -> &'s str { match self { Object::Bold(inner) => inner.get_contents(), Object::Italic(inner) => inner.get_contents(), diff --git a/src/types/standard_properties.rs b/src/types/standard_properties.rs index e2ecc622..e11dc546 100644 --- a/src/types/standard_properties.rs +++ b/src/types/standard_properties.rs @@ -8,7 +8,7 @@ pub trait StandardProperties<'s> { /// Get the slice of the AST node's contents. /// /// This corresponds to :contents-begin to :contents-end - fn get_contents(&'s self) -> &'s str; + fn get_contents<'b>(&'b self) -> &'s str; /// Get the slice of the AST node's post-blank text. ///