Compare commits

..

No commits in common. "3fb7cb82cda854839b3d97c2cd25ae8182aca387" and "31406fd520fa0ab328c043ce7dbde297508e6fe9" have entirely different histories.

14 changed files with 174 additions and 344 deletions

View File

@ -100,26 +100,20 @@ fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
// Check contents-begin/contents-end
{
if let Some(rust_contents) = rust.get_contents() {
let (begin, end) = (
standard_properties
.contents_begin
.ok_or("Token should have a contents-begin.")?,
standard_properties
.contents_end
.ok_or("Token should have an contents-end.")?,
);
let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust_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 contents bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs contents bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?;
}
} else if standard_properties.contents_begin.is_some()
|| standard_properties.contents_end.is_some()
{
Err(format!("Rust contents is None but emacs contents bounds are ({emacs_begin:?}, {emacs_end:?})", emacs_begin=standard_properties.contents_begin, emacs_end=standard_properties.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 contents bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs contents bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?;
}
}
@ -134,11 +128,11 @@ fn assert_post_blank<'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 rust_post_blank = rust.get_post_blank();
let rust_post_blank = rust.get_post_blank().chars().count();
let emacs_post_blank = standard_properties
.post_blank
.ok_or("Token should have a post-blank.")?;
if rust_post_blank as usize != emacs_post_blank {
if rust_post_blank != 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))?;
}

View File

@ -75,7 +75,6 @@ where
let parser_context = parser_context.with_additional_node(&contexts[2]);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let before_contents = remaining;
let (mut remaining, (mut children, _exit_contents)) =
many_till(include_input(element_matcher), exit_matcher)(remaining)?;
@ -91,16 +90,13 @@ where
}
}
let contents = get_consumed(before_contents, remaining);
let (remaining, post_blank) =
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
FootnoteDefinition {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,

View File

@ -2,7 +2,6 @@ use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::bytes::complete::tag_no_case;
use nom::combinator::all_consuming;
use nom::combinator::consumed;
use nom::combinator::map_parser;
use nom::combinator::verify;
use nom::multi::many1;
@ -60,7 +59,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
let initial_context = ContextElement::document_context();
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
let (remaining, (contents, children)) = consumed(map_parser(
let (remaining, children) = map_parser(
verify(
parser_with_context!(text_until_exit)(&parser_context),
|text| text.len() > 0,
@ -70,19 +69,17 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
&initial_context,
)))(i)
}),
))(remaining)?;
)(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
let (remaining, post_blank) =
let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
FootnoteReference {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
label: None,
definition: children,
},
@ -109,7 +106,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
let initial_context = ContextElement::document_context();
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
let (remaining, (contents, children)) = consumed(map_parser(
let (remaining, children) = map_parser(
verify(
parser_with_context!(text_until_exit)(&parser_context),
|text| text.len() > 0,
@ -119,19 +116,17 @@ fn inline_footnote<'b, 'g, 'r, 's>(
&initial_context,
)))(i)
}),
))(remaining)?;
)(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
let (remaining, post_blank) =
let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
FootnoteReference {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
label: Some(label_contents.into()),
definition: children,
},
@ -149,15 +144,13 @@ fn footnote_reference_only<'b, 'g, 'r, 's>(
let (remaining, _) = tag_no_case("[fn:")(input)?;
let (remaining, label_contents) = label(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
let (remaining, post_blank) =
let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
FootnoteReference {
source: source.into(),
contents: None,
post_blank: post_blank.map(Into::<&str>::into),
label: Some(label_contents.into()),
definition: Vec::with_capacity(0),
},

View File

@ -1,5 +1,4 @@
use nom::branch::alt;
use nom::combinator::consumed;
use nom::combinator::eof;
use nom::combinator::recognize;
use nom::combinator::verify;
@ -46,14 +45,14 @@ where
let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (contents, (children, _exit_contents))) = consumed(verify(
let (remaining, (children, _exit_contents)) = verify(
many_till(standard_set_object_matcher, exit_matcher),
|(children, _exit_contents)| !children.is_empty(),
))(remaining)?;
)(remaining)?;
// Not checking parent exit matcher because if there are any children matched then we have a valid paragraph.
let (remaining, post_blank) =
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
@ -61,8 +60,6 @@ where
remaining,
Paragraph {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,

View File

@ -1,4 +1,3 @@
use nom::combinator::consumed;
use nom::combinator::opt;
use nom::combinator::recognize;
use nom::combinator::verify;
@ -59,12 +58,12 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>(
many0(blank_line),
)))(input)?;
let (remaining, (contents, (mut children, _exit_contents))) = consumed(verify(
let (remaining, (mut children, _exit_contents)) = verify(
many_till(element_matcher, exit_matcher),
|(children, _exit_contents)| {
!children.is_empty() || comment_and_property_drawer_element.is_some()
},
))(remaining)?;
)(remaining)?;
if let Some((comment, property_drawer, _ws)) = comment_and_property_drawer_element {
children.insert(0, Element::PropertyDrawer(property_drawer));
@ -73,7 +72,7 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>(
}
}
let (remaining, post_blank) =
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
@ -81,8 +80,6 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>(
remaining,
Section {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
children,
},
))
@ -118,12 +115,12 @@ pub(crate) fn section<'b, 'g, 'r, 's>(
remaining = remain;
input = remain;
}
let (remaining, (contents, (mut children, _exit_contents))) = consumed(verify(
let (remaining, (mut children, _exit_contents)) = verify(
many_till(element_matcher, exit_matcher),
|(children, _exit_contents)| {
!children.is_empty() || property_drawer_element.is_some() || planning_element.is_some()
},
))(remaining)?;
)(remaining)?;
if let Some(ele) = property_drawer_element.map(Element::PropertyDrawer) {
children.insert(0, ele);
}
@ -131,7 +128,7 @@ pub(crate) fn section<'b, 'g, 'r, 's>(
children.insert(0, ele)
}
let (remaining, post_blank) =
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
@ -139,8 +136,6 @@ pub(crate) fn section<'b, 'g, 'r, 's>(
remaining,
Section {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
children,
},
))

View File

@ -1,6 +1,5 @@
use super::macros::to_ast_node;
use super::CenterBlock;
use super::PostBlank;
use super::QuoteBlock;
use super::SpecialBlock;
use super::StandardProperties;
@ -324,7 +323,7 @@ impl<'r, 's> StandardProperties<'s> for AstNode<'r, 's> {
}
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
match self {
AstNode::Document(inner) => inner.get_contents(),
AstNode::Heading(inner) => inner.get_contents(),
@ -387,7 +386,7 @@ impl<'r, 's> StandardProperties<'s> for AstNode<'r, 's> {
}
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
match self {
AstNode::Document(inner) => inner.get_post_blank(),
AstNode::Heading(inner) => inner.get_post_blank(),

View File

@ -1,10 +1,8 @@
use std::path::PathBuf;
use super::remove_trailing::RemoveTrailing;
use super::Element;
use super::NodeProperty;
use super::Object;
use super::PostBlank;
use super::StandardProperties;
use super::Timestamp;
@ -40,8 +38,6 @@ pub struct Heading<'s> {
#[derive(Debug)]
pub struct Section<'s> {
pub source: &'s str,
pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
pub children: Vec<Element<'s>>,
}
@ -62,36 +58,12 @@ impl<'s> StandardProperties<'s> for Document<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
let post_blank = self.get_post_blank();
let mut content_lines = self
.source
.split_inclusive('\n')
.remove_trailing(post_blank);
let first_line = content_lines.next();
let last_line = content_lines.last().or(first_line);
match (first_line, last_line) {
(None, None) => None,
(None, Some(_)) | (Some(_), None) => unreachable!(),
(Some(first_line), Some(last_line)) => {
let first_line_offset = first_line.as_ptr() as usize;
let last_line_offset = last_line.as_ptr() as usize + last_line.len();
let source_offset = self.source.as_ptr() as usize;
debug_assert!(super::lesser_element::is_slice_of(self.source, first_line));
debug_assert!(super::lesser_element::is_slice_of(self.source, last_line));
Some(
&self.source[(first_line_offset - source_offset)
..(last_line_offset - first_line_offset)],
)
}
}
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
self.into_iter()
.last()
.map(|child| child.get_post_blank())
.unwrap_or(0)
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -100,16 +72,12 @@ impl<'s> StandardProperties<'s> for Section<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
self.contents
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
self.post_blank
.map(|text| text.lines().count())
.unwrap_or(0)
.try_into()
.expect("Too much post-blank to fit into a PostBlank.")
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -118,40 +86,12 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
let first_child = self.children.first();
let last_child = self.children.last();
match (first_child, last_child) {
(None, None) => None,
(None, Some(_)) | (Some(_), None) => unreachable!(),
(Some(first_child), Some(last_child)) => {
let first_child_offset = first_child.get_source().as_ptr() as usize;
let last_child_offset = {
let last_child_source = last_child.get_source();
last_child_source.as_ptr() as usize + last_child_source.len()
};
let source_offset = self.source.as_ptr() as usize;
debug_assert!(super::lesser_element::is_slice_of(
self.source,
first_child.get_source()
));
debug_assert!(super::lesser_element::is_slice_of(
self.source,
last_child.get_source()
));
Some(
&self.source[(first_child_offset - source_offset)
..(last_child_offset - first_child_offset)],
)
}
}
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
self.children
.last()
.map(|child| child.get_post_blank())
.unwrap_or(0)
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -211,14 +151,14 @@ impl<'s> StandardProperties<'s> for DocumentElement<'s> {
}
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
match self {
DocumentElement::Heading(inner) => inner.get_contents(),
DocumentElement::Section(inner) => inner.get_contents(),
}
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
match self {
DocumentElement::Heading(inner) => inner.get_post_blank(),
DocumentElement::Section(inner) => inner.get_post_blank(),

View File

@ -20,7 +20,6 @@ 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;
@ -84,7 +83,7 @@ impl<'s> StandardProperties<'s> for Element<'s> {
}
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
match self {
Element::Paragraph(inner) => inner.get_contents(),
Element::PlainList(inner) => inner.get_contents(),
@ -113,7 +112,7 @@ impl<'s> StandardProperties<'s> for Element<'s> {
}
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
match self {
Element::Paragraph(inner) => inner.get_post_blank(),
Element::PlainList(inner) => inner.get_post_blank(),

View File

@ -4,7 +4,6 @@ use super::lesser_element::TableCell;
use super::AffiliatedKeywords;
use super::Keyword;
use super::Object;
use super::PostBlank;
use super::StandardProperties;
#[derive(Debug)]
@ -82,8 +81,6 @@ pub struct DynamicBlock<'s> {
#[derive(Debug)]
pub struct FootnoteDefinition<'s> {
pub source: &'s str,
pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
pub affiliated_keywords: AffiliatedKeywords<'s>,
pub label: &'s str,
pub children: Vec<Element<'s>>,
@ -135,11 +132,11 @@ impl<'s> StandardProperties<'s> for PlainList<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -149,11 +146,11 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -163,11 +160,11 @@ impl<'s> StandardProperties<'s> for CenterBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -177,11 +174,11 @@ impl<'s> StandardProperties<'s> for QuoteBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -191,11 +188,11 @@ impl<'s> StandardProperties<'s> for SpecialBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -205,11 +202,11 @@ impl<'s> StandardProperties<'s> for DynamicBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -219,16 +216,12 @@ impl<'s> StandardProperties<'s> for FootnoteDefinition<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
self.contents
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
self.post_blank
.map(|text| text.lines().count())
.unwrap_or(0)
.try_into()
.expect("Too much post-blank to fit into a PostBlank.")
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -237,11 +230,11 @@ impl<'s> StandardProperties<'s> for Drawer<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -251,11 +244,11 @@ impl<'s> StandardProperties<'s> for PropertyDrawer<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -265,11 +258,11 @@ impl<'s> StandardProperties<'s> for NodeProperty<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -279,11 +272,11 @@ impl<'s> StandardProperties<'s> for Table<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -293,11 +286,11 @@ impl<'s> StandardProperties<'s> for TableRow<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}

View File

@ -16,7 +16,6 @@ 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;
@ -25,8 +24,6 @@ use crate::error::Res;
#[derive(Debug)]
pub struct Paragraph<'s> {
pub source: &'s str,
pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
pub affiliated_keywords: AffiliatedKeywords<'s>,
pub children: Vec<Object<'s>>,
}
@ -191,8 +188,6 @@ impl<'s> Paragraph<'s> {
pub(crate) fn of_text(source: &'s str, body: &'s str) -> Self {
Paragraph {
source,
contents: None, // TODO
post_blank: None, // TODO
affiliated_keywords: AffiliatedKeywords::default(),
children: vec![Object::PlainText(PlainText { source: body })],
}
@ -204,16 +199,12 @@ impl<'s> StandardProperties<'s> for Paragraph<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
self.contents
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
self.post_blank
.map(|text| text.lines().count())
.unwrap_or(0)
.try_into()
.expect("Too much post-blank to fit into a PostBlank.")
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -222,11 +213,11 @@ impl<'s> StandardProperties<'s> for TableCell<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -236,11 +227,11 @@ impl<'s> StandardProperties<'s> for Comment<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -250,11 +241,11 @@ impl<'s> StandardProperties<'s> for VerseBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -263,11 +254,11 @@ impl<'s> StandardProperties<'s> for CommentBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -276,11 +267,11 @@ impl<'s> StandardProperties<'s> for ExampleBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -289,11 +280,11 @@ impl<'s> StandardProperties<'s> for ExportBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -302,11 +293,11 @@ impl<'s> StandardProperties<'s> for SrcBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -316,11 +307,11 @@ impl<'s> StandardProperties<'s> for Clock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -330,11 +321,11 @@ impl<'s> StandardProperties<'s> for DiarySexp<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -344,11 +335,11 @@ impl<'s> StandardProperties<'s> for Planning<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -358,11 +349,11 @@ impl<'s> StandardProperties<'s> for FixedWidthArea<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -372,11 +363,11 @@ impl<'s> StandardProperties<'s> for HorizontalRule<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -386,11 +377,11 @@ impl<'s> StandardProperties<'s> for Keyword<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -400,11 +391,11 @@ impl<'s> StandardProperties<'s> for BabelCall<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -414,11 +405,11 @@ impl<'s> StandardProperties<'s> for LatexEnvironment<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -610,7 +601,7 @@ fn content_line<'s>(input: &'s str) -> Res<&'s str, (Option<&'s str>, &'s str)>
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
/// Check if the child string slice is a slice of the parent string slice.
pub(crate) fn is_slice_of(parent: &str, child: &str) -> bool {
fn is_slice_of(parent: &str, child: &str) -> bool {
let parent_start = parent.as_ptr() as usize;
let parent_end = parent_start + parent.len();
let child_start = child.as_ptr() as usize;

View File

@ -6,7 +6,6 @@ mod greater_element;
mod lesser_element;
mod macros;
mod object;
mod remove_trailing;
mod standard_properties;
mod util;
pub use affiliated_keyword::AffiliatedKeyword;
@ -111,5 +110,4 @@ 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;

View File

@ -6,7 +6,6 @@ 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)]
@ -192,8 +191,6 @@ pub struct ExportSnippet<'s> {
#[derive(Debug)]
pub struct FootnoteReference<'s> {
pub source: &'s str,
pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
pub label: Option<&'s str>,
pub definition: Vec<Object<'s>>,
}
@ -522,11 +519,11 @@ impl<'s> StandardProperties<'s> for Bold<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -536,11 +533,11 @@ impl<'s> StandardProperties<'s> for Italic<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -550,11 +547,11 @@ impl<'s> StandardProperties<'s> for Underline<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -564,11 +561,11 @@ impl<'s> StandardProperties<'s> for StrikeThrough<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -578,11 +575,11 @@ impl<'s> StandardProperties<'s> for Code<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -592,11 +589,11 @@ impl<'s> StandardProperties<'s> for Verbatim<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -606,11 +603,11 @@ impl<'s> StandardProperties<'s> for RegularLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -620,11 +617,11 @@ impl<'s> StandardProperties<'s> for RadioLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -634,11 +631,11 @@ impl<'s> StandardProperties<'s> for RadioTarget<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -648,11 +645,11 @@ impl<'s> StandardProperties<'s> for PlainLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -662,11 +659,11 @@ impl<'s> StandardProperties<'s> for AngleLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -676,11 +673,11 @@ impl<'s> StandardProperties<'s> for OrgMacro<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -690,11 +687,11 @@ impl<'s> StandardProperties<'s> for Entity<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -704,11 +701,11 @@ impl<'s> StandardProperties<'s> for LatexFragment<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -718,11 +715,11 @@ impl<'s> StandardProperties<'s> for ExportSnippet<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -732,16 +729,12 @@ impl<'s> StandardProperties<'s> for FootnoteReference<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
self.contents
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
self.post_blank
.map(|text| text.chars().count())
.unwrap_or(0)
.try_into()
.expect("Too much post-blank to fit into a PostBlank.")
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -750,11 +743,11 @@ impl<'s> StandardProperties<'s> for Citation<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -764,11 +757,11 @@ impl<'s> StandardProperties<'s> for CitationReference<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -778,11 +771,11 @@ impl<'s> StandardProperties<'s> for InlineBabelCall<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -792,11 +785,11 @@ impl<'s> StandardProperties<'s> for InlineSourceBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -806,11 +799,11 @@ impl<'s> StandardProperties<'s> for LineBreak<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -820,11 +813,11 @@ impl<'s> StandardProperties<'s> for Target<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -834,11 +827,11 @@ impl<'s> StandardProperties<'s> for StatisticsCookie<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -848,11 +841,11 @@ impl<'s> StandardProperties<'s> for Subscript<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -862,11 +855,11 @@ impl<'s> StandardProperties<'s> for Superscript<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -876,11 +869,11 @@ impl<'s> StandardProperties<'s> for Timestamp<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -890,11 +883,11 @@ impl<'s> StandardProperties<'s> for PlainText<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
@ -1023,7 +1016,7 @@ impl<'s> StandardProperties<'s> for Object<'s> {
}
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
fn get_contents<'b>(&'b self) -> &'s str {
match self {
Object::Bold(inner) => inner.get_contents(),
Object::Italic(inner) => inner.get_contents(),
@ -1055,7 +1048,7 @@ impl<'s> StandardProperties<'s> for Object<'s> {
}
}
fn get_post_blank(&self) -> PostBlank {
fn get_post_blank<'b>(&'b self) -> &'s str {
match self {
Object::Bold(inner) => inner.get_post_blank(),
Object::Italic(inner) => inner.get_post_blank(),

View File

@ -1,56 +0,0 @@
pub(crate) trait RemoveTrailing: Iterator + Sized {
fn remove_trailing<R: Into<usize>>(self, amount_to_remove: R) -> RemoveTrailingIter<Self>;
}
impl<I> RemoveTrailing for I
where
I: Iterator,
{
fn remove_trailing<R: Into<usize>>(self, amount_to_remove: R) -> RemoveTrailingIter<Self> {
RemoveTrailingIter {
inner: self,
buffer: Vec::new(),
next_to_pop: 0,
amount_to_remove: amount_to_remove.into(),
}
}
}
pub(crate) struct RemoveTrailingIter<I: Iterator> {
inner: I,
buffer: Vec<I::Item>,
next_to_pop: usize,
amount_to_remove: usize,
}
impl<I: Iterator> Iterator for RemoveTrailingIter<I> {
type Item = I::Item;
fn next(&mut self) -> Option<Self::Item> {
if self.buffer.len() < self.amount_to_remove {
self.buffer.reserve_exact(self.amount_to_remove);
}
while self.buffer.len() < self.amount_to_remove {
if let Some(elem) = self.inner.next() {
self.buffer.push(elem);
} else {
// The inner was smaller than amount_to_remove, so never return anything.
return None;
}
}
let new_value = self.inner.next();
if self.amount_to_remove == 0 {
return new_value;
}
if let Some(new_value) = new_value {
let ret = std::mem::replace(&mut self.buffer[self.next_to_pop], new_value);
self.next_to_pop = (self.next_to_pop + 1) % self.amount_to_remove;
Some(ret)
} else {
// We have exactly the amount in the buffer than we wanted to cut off, so stop returning values.
None
}
}
}

View File

@ -8,12 +8,12 @@ pub trait StandardProperties<'s> {
/// Get the slice of the AST node's contents.
///
/// This corresponds to :contents-begin to :contents-end
fn get_contents<'b>(&'b self) -> Option<&'s str>;
fn get_contents<'b>(&'b self) -> &'s str;
/// Get the ast node's post-blank.
/// Get the slice of the AST node's post-blank text.
///
/// 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(&self) -> PostBlank;
/// This is optional whitespace following the node.
fn get_post_blank<'b>(&'b self) -> &'s str;
}
// 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,5 +61,3 @@ 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;