Compare contents begin/end.

This commit is contained in:
Tom Alexander 2023-10-31 22:10:19 -04:00
parent 33f4614d28
commit 92592104a4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
8 changed files with 98 additions and 75 deletions

View File

@ -79,18 +79,41 @@ fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
rust: &'b S,
) -> Result<(), Box<dyn std::error::Error>> {
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(())

View File

@ -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(),

View File

@ -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(),

View File

@ -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(),

View File

@ -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!()
}

View File

@ -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!()
}

View File

@ -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(),

View File

@ -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.
///