Compare commits

...

5 Commits

Author SHA1 Message Date
Tom Alexander
33f4614d28
Make get_rust_byte_offsets more generic so it can be used for contents.
Some checks failed
clippy Build clippy has failed
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded
2023-10-31 21:59:58 -04:00
Tom Alexander
6c197c376a
Add todo implementations of the new standard property functions. 2023-10-31 21:49:33 -04:00
Tom Alexander
bcf1b49db2
Remove the GetStandardProperties trait.
This was using dynamic dispatch to deal with enums to avoid the repetitive typing.
2023-10-31 21:26:00 -04:00
Tom Alexander
49f6e70a19
Use RPIT to get static dispatch GetStandardProperties. 2023-10-31 21:20:46 -04:00
Tom Alexander
31fb815681
Add a function for getting the post blank. 2023-10-31 21:20:46 -04:00
18 changed files with 916 additions and 237 deletions

View File

@ -57,7 +57,6 @@ use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference;
use crate::types::FootnoteReferenceType;
use crate::types::GetStandardProperties;
use crate::types::Heading;
use crate::types::HorizontalRule;
use crate::types::Hour;
@ -413,7 +412,7 @@ pub(crate) fn compare_ast_node<'b, 's>(
name: rust.get_elisp_fact().get_elisp_name(),
message: Some(e.to_string()),
children: Vec::new(),
rust_source: rust.get_standard_properties().get_source(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into()
@ -1576,7 +1575,7 @@ fn compare_example_block<'b, 's>(
[],
(
EmacsField::Required(":value"),
|r| Some(r.get_contents()),
|r| Some(r.get_value()),
compare_property_quoted_string
),
(
@ -1654,7 +1653,7 @@ fn compare_export_block<'b, 's>(
),
(
EmacsField::Required(":value"),
|r| Some(r.get_contents()),
|r| Some(r.get_value()),
compare_property_quoted_string
)
) {
@ -1702,7 +1701,7 @@ fn compare_src_block<'b, 's>(
),
(
EmacsField::Required(":value"),
|r| Some(r.get_contents()),
|r| Some(r.get_value()),
compare_property_quoted_string
),
(

View File

@ -15,7 +15,6 @@ use crate::compare::sexp::unquote;
use crate::types::AffiliatedKeywordValue;
use crate::types::AstNode;
use crate::types::GetAffiliatedKeywords;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
/// Check if the child string slice is a slice of the parent string slice.
@ -30,32 +29,28 @@ fn is_slice_of(parent: &str, child: &str) -> bool {
/// Get the byte offset into source that the rust object exists at.
///
/// These offsets are zero-based unlike the elisp ones.
fn get_rust_byte_offsets<'b, 's, S: StandardProperties<'s> + ?Sized>(
original_document: &'s str,
rust_ast_node: &'b S,
) -> (usize, usize) {
let rust_object_source = rust_ast_node.get_source();
debug_assert!(is_slice_of(original_document, rust_object_source));
let offset = rust_object_source.as_ptr() as usize - original_document.as_ptr() as usize;
let end = offset + rust_object_source.len();
fn get_rust_byte_offsets<'b, 's>(original_document: &'s str, subset: &'b str) -> (usize, usize) {
debug_assert!(is_slice_of(original_document, subset));
let offset = subset.as_ptr() as usize - original_document.as_ptr() as usize;
let end = offset + subset.len();
(offset, end)
}
pub(crate) fn compare_standard_properties<
'b,
's,
S: GetStandardProperties<'s> + GetElispFact<'s> + ?Sized,
S: StandardProperties<'s> + GetElispFact<'s> + ?Sized,
>(
original_document: &'s str,
emacs: &'b Token<'s>,
rust: &'b S,
) -> Result<(), Box<dyn std::error::Error>> {
assert_name(emacs, rust.get_elisp_fact().get_elisp_name())?;
assert_bounds(original_document, emacs, rust.get_standard_properties())?;
assert_bounds(original_document, emacs, rust)?;
Ok(())
}
pub(crate) fn assert_name<S: AsRef<str>>(
fn assert_name<S: AsRef<str>>(
emacs: &Token<'_>,
name: S,
) -> Result<(), Box<dyn std::error::Error>> {
@ -78,7 +73,7 @@ pub(crate) fn assert_name<S: AsRef<str>>(
/// Assert that the character ranges defined by upstream org-mode's :standard-properties match the slices in Organic's StandardProperties.
///
/// This does **not** handle plain text because plain text is a special case.
pub(crate) fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
original_document: &'s str,
emacs: &'b Token<'s>,
rust: &'b S,
@ -90,7 +85,7 @@ pub(crate) fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
.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); // 0-based
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

View File

@ -211,7 +211,6 @@ mod tests {
use crate::context::List;
use crate::parser::element_parser::element;
use crate::types::Element;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
#[test]
@ -227,10 +226,7 @@ mod tests {
_ => panic!("Should be a paragraph!"),
};
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(
first_paragraph.get_standard_properties().get_source(),
"[cite:@foo]"
);
assert_eq!(first_paragraph.get_source(), "[cite:@foo]");
assert_eq!(first_paragraph.children.len(), 1);
match first_paragraph

View File

@ -160,7 +160,7 @@ mod tests {
use crate::context::Context;
use crate::context::GlobalSettings;
use crate::context::List;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
#[test]
fn two_paragraphs() {
@ -181,17 +181,13 @@ line footnote.",
footnote_definition_matcher(remaining).expect("Parse second footnote_definition.");
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(
first_footnote_definition
.get_standard_properties()
.get_source(),
first_footnote_definition.get_source(),
"[fn:1] A footnote.
"
);
assert_eq!(
second_footnote_definition
.get_standard_properties()
.get_source(),
second_footnote_definition.get_source(),
"[fn:2] A multi-
line footnote."
@ -216,9 +212,7 @@ not in the footnote.",
footnote_definition_matcher(input).expect("Parse first footnote_definition");
assert_eq!(Into::<&str>::into(remaining), "not in the footnote.");
assert_eq!(
first_footnote_definition
.get_standard_properties()
.get_source(),
first_footnote_definition.get_source(),
"[fn:2] A multi-
line footnote.

View File

@ -236,7 +236,7 @@ where
retain_labels,
use_labels,
label_format,
contents: Into::<&str>::into(contents),
value: Into::<&str>::into(contents),
},
))
}
@ -292,7 +292,7 @@ where
),
export_type: export_type.map(Into::<&str>::into),
data: parameters.map(Into::<&str>::into),
contents: Into::<&str>::into(contents),
value: Into::<&str>::into(contents),
},
))
}
@ -371,7 +371,7 @@ where
retain_labels,
use_labels,
label_format,
contents: Into::<&str>::into(contents),
value: Into::<&str>::into(contents),
},
))
}

View File

@ -96,7 +96,7 @@ mod tests {
use crate::context::List;
use crate::parser::element_parser::element;
use crate::parser::org_source::OrgSource;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
#[test]
fn two_paragraphs() {
@ -109,13 +109,7 @@ mod tests {
let (remaining, second_paragraph) =
paragraph_matcher(remaining).expect("Parse second paragraph.");
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(
first_paragraph.get_standard_properties().get_source(),
"foo bar baz\n\n"
);
assert_eq!(
second_paragraph.get_standard_properties().get_source(),
"lorem ipsum"
);
assert_eq!(first_paragraph.get_source(), "foo bar baz\n\n");
assert_eq!(second_paragraph.get_source(), "lorem ipsum");
}
}

View File

@ -629,7 +629,7 @@ mod tests {
use crate::context::Context;
use crate::context::GlobalSettings;
use crate::context::List;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
#[test]
fn plain_list_item_empty() {
@ -640,7 +640,7 @@ mod tests {
let plain_list_item_matcher = bind_context!(plain_list_item, &initial_context);
let (remaining, (_, result)) = plain_list_item_matcher(input).unwrap();
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(result.get_standard_properties().get_source(), "1.");
assert_eq!(result.get_source(), "1.");
}
#[test]
@ -652,7 +652,7 @@ mod tests {
let plain_list_item_matcher = bind_context!(plain_list_item, &initial_context);
let (remaining, (_, result)) = plain_list_item_matcher(input).unwrap();
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(result.get_standard_properties().get_source(), "1. foo");
assert_eq!(result.get_source(), "1. foo");
}
#[test]
@ -664,7 +664,7 @@ mod tests {
let (remaining, result) =
plain_list(std::iter::empty(), input, &initial_context, input).unwrap();
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(result.get_standard_properties().get_source(), "1.");
assert_eq!(result.get_source(), "1.");
}
#[test]
@ -676,7 +676,7 @@ mod tests {
let (remaining, result) =
plain_list(std::iter::empty(), input, &initial_context, input).unwrap();
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(result.get_standard_properties().get_source(), "1. foo");
assert_eq!(result.get_source(), "1. foo");
}
#[test]
@ -721,7 +721,7 @@ mod tests {
plain_list_matcher(input).expect("Should parse the plain list successfully.");
assert_eq!(Into::<&str>::into(remaining), " ipsum\n");
assert_eq!(
result.get_standard_properties().get_source(),
result.get_source(),
r#"1. foo
2. bar
baz
@ -749,7 +749,7 @@ baz"#,
plain_list_matcher(input).expect("Should parse the plain list successfully.");
assert_eq!(Into::<&str>::into(remaining), "baz");
assert_eq!(
result.get_standard_properties().get_source(),
result.get_source(),
r#"1. foo
1. bar
@ -782,7 +782,7 @@ dolar"#,
plain_list_matcher(input).expect("Should parse the plain list successfully.");
assert_eq!(Into::<&str>::into(remaining), "dolar");
assert_eq!(
result.get_standard_properties().get_source(),
result.get_source(),
r#"1. foo
bar

View File

@ -143,7 +143,7 @@ mod tests {
use crate::context::GlobalSettings;
use crate::context::List;
use crate::parser::object_parser::detect_standard_set_object_sans_plain_text;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
#[test]
fn plain_text_simple() {
@ -160,9 +160,6 @@ mod tests {
)(input)
.unwrap();
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(
result.get_standard_properties().get_source(),
Into::<&str>::into(input)
);
assert_eq!(result.get_source(), Into::<&str>::into(input));
}
}

View File

@ -175,8 +175,8 @@ mod tests {
use crate::parser::element_parser::element;
use crate::types::Bold;
use crate::types::Element;
use crate::types::GetStandardProperties;
use crate::types::PlainText;
use crate::types::StandardProperties;
#[test]
fn plain_text_radio_target() -> Result<(), Box<dyn std::error::Error>> {
@ -195,10 +195,7 @@ mod tests {
_ => panic!("Should be a paragraph!"),
};
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(
first_paragraph.get_standard_properties().get_source(),
"foo bar baz"
);
assert_eq!(first_paragraph.get_source(), "foo bar baz");
assert_eq!(first_paragraph.children.len(), 3);
match first_paragraph
.children
@ -206,7 +203,7 @@ mod tests {
.expect("Len already asserted to be 3.")
{
Object::RadioLink(inner) => {
assert_eq!(inner.get_standard_properties().get_source(), "bar ");
assert_eq!(inner.get_source(), "bar ");
assert_eq!(inner.path, "bar");
assert_eq!(inner.children.len(), 1);
let child = inner
@ -214,7 +211,7 @@ mod tests {
.first()
.expect("Length already asserted to be 1.");
assert!(matches!(child, Object::PlainText(_)));
assert_eq!(child.get_standard_properties().get_source(), "bar");
assert_eq!(child.get_source(), "bar");
}
_ => {
return Err("Child should be a radio link.".into());
@ -244,10 +241,7 @@ mod tests {
_ => panic!("Should be a paragraph!"),
};
assert_eq!(Into::<&str>::into(remaining), "");
assert_eq!(
first_paragraph.get_standard_properties().get_source(),
"foo *bar* baz"
);
assert_eq!(first_paragraph.get_source(), "foo *bar* baz");
assert_eq!(first_paragraph.children.len(), 3);
match first_paragraph
.children
@ -255,7 +249,7 @@ mod tests {
.expect("Len already asserted to be 3.")
{
Object::RadioLink(inner) => {
assert_eq!(inner.get_standard_properties().get_source(), "*bar* ");
assert_eq!(inner.get_source(), "*bar* ");
assert_eq!(inner.path, "*bar* ");
assert_eq!(inner.children.len(), 1);
let child = inner
@ -263,7 +257,7 @@ mod tests {
.first()
.expect("Length already asserted to be 1.");
assert!(matches!(child, Object::Bold(_)));
assert_eq!(child.get_standard_properties().get_source(), "*bar* ");
assert_eq!(child.get_source(), "*bar* ");
}
_ => {
return Err("Child should be a radio link.".into());

View File

@ -2,6 +2,7 @@ use super::macros::to_ast_node;
use super::CenterBlock;
use super::QuoteBlock;
use super::SpecialBlock;
use super::StandardProperties;
use crate::types::AngleLink;
use crate::types::BabelCall;
use crate::types::Bold;
@ -24,7 +25,6 @@ use crate::types::ExportSnippet;
use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference;
use crate::types::GetStandardProperties;
use crate::types::Heading;
use crate::types::HorizontalRule;
use crate::types::InlineBabelCall;
@ -259,67 +259,193 @@ to_ast_node!(&'r Superscript<'s>, AstNode::Superscript);
to_ast_node!(&'r TableCell<'s>, AstNode::TableCell);
to_ast_node!(&'r Timestamp<'s>, AstNode::Timestamp);
impl<'r, 's> GetStandardProperties<'s> for AstNode<'r, 's> {
fn get_standard_properties<'b>(&'b self) -> &'b dyn crate::types::StandardProperties<'s> {
impl<'r, 's> StandardProperties<'s> for AstNode<'r, 's> {
fn get_source<'b>(&'b self) -> &'s str {
match self {
AstNode::Document(inner) => *inner,
AstNode::Heading(inner) => *inner,
AstNode::Section(inner) => *inner,
AstNode::Paragraph(inner) => *inner,
AstNode::PlainList(inner) => *inner,
AstNode::PlainListItem(inner) => *inner,
AstNode::CenterBlock(inner) => *inner,
AstNode::QuoteBlock(inner) => *inner,
AstNode::SpecialBlock(inner) => *inner,
AstNode::DynamicBlock(inner) => *inner,
AstNode::FootnoteDefinition(inner) => *inner,
AstNode::Comment(inner) => *inner,
AstNode::Drawer(inner) => *inner,
AstNode::PropertyDrawer(inner) => *inner,
AstNode::NodeProperty(inner) => *inner,
AstNode::Table(inner) => *inner,
AstNode::TableRow(inner) => *inner,
AstNode::VerseBlock(inner) => *inner,
AstNode::CommentBlock(inner) => *inner,
AstNode::ExampleBlock(inner) => *inner,
AstNode::ExportBlock(inner) => *inner,
AstNode::SrcBlock(inner) => *inner,
AstNode::Clock(inner) => *inner,
AstNode::DiarySexp(inner) => *inner,
AstNode::Planning(inner) => *inner,
AstNode::FixedWidthArea(inner) => *inner,
AstNode::HorizontalRule(inner) => *inner,
AstNode::Keyword(inner) => *inner,
AstNode::BabelCall(inner) => *inner,
AstNode::LatexEnvironment(inner) => *inner,
AstNode::Bold(inner) => *inner,
AstNode::Italic(inner) => *inner,
AstNode::Underline(inner) => *inner,
AstNode::StrikeThrough(inner) => *inner,
AstNode::Code(inner) => *inner,
AstNode::Verbatim(inner) => *inner,
AstNode::PlainText(inner) => *inner,
AstNode::RegularLink(inner) => *inner,
AstNode::RadioLink(inner) => *inner,
AstNode::RadioTarget(inner) => *inner,
AstNode::PlainLink(inner) => *inner,
AstNode::AngleLink(inner) => *inner,
AstNode::OrgMacro(inner) => *inner,
AstNode::Entity(inner) => *inner,
AstNode::LatexFragment(inner) => *inner,
AstNode::ExportSnippet(inner) => *inner,
AstNode::FootnoteReference(inner) => *inner,
AstNode::Citation(inner) => *inner,
AstNode::CitationReference(inner) => *inner,
AstNode::InlineBabelCall(inner) => *inner,
AstNode::InlineSourceBlock(inner) => *inner,
AstNode::LineBreak(inner) => *inner,
AstNode::Target(inner) => *inner,
AstNode::StatisticsCookie(inner) => *inner,
AstNode::Subscript(inner) => *inner,
AstNode::Superscript(inner) => *inner,
AstNode::TableCell(inner) => *inner,
AstNode::Timestamp(inner) => *inner,
AstNode::Document(inner) => inner.get_source(),
AstNode::Heading(inner) => inner.get_source(),
AstNode::Section(inner) => inner.get_source(),
AstNode::Paragraph(inner) => inner.get_source(),
AstNode::PlainList(inner) => inner.get_source(),
AstNode::PlainListItem(inner) => inner.get_source(),
AstNode::CenterBlock(inner) => inner.get_source(),
AstNode::QuoteBlock(inner) => inner.get_source(),
AstNode::SpecialBlock(inner) => inner.get_source(),
AstNode::DynamicBlock(inner) => inner.get_source(),
AstNode::FootnoteDefinition(inner) => inner.get_source(),
AstNode::Comment(inner) => inner.get_source(),
AstNode::Drawer(inner) => inner.get_source(),
AstNode::PropertyDrawer(inner) => inner.get_source(),
AstNode::NodeProperty(inner) => inner.get_source(),
AstNode::Table(inner) => inner.get_source(),
AstNode::TableRow(inner) => inner.get_source(),
AstNode::VerseBlock(inner) => inner.get_source(),
AstNode::CommentBlock(inner) => inner.get_source(),
AstNode::ExampleBlock(inner) => inner.get_source(),
AstNode::ExportBlock(inner) => inner.get_source(),
AstNode::SrcBlock(inner) => inner.get_source(),
AstNode::Clock(inner) => inner.get_source(),
AstNode::DiarySexp(inner) => inner.get_source(),
AstNode::Planning(inner) => inner.get_source(),
AstNode::FixedWidthArea(inner) => inner.get_source(),
AstNode::HorizontalRule(inner) => inner.get_source(),
AstNode::Keyword(inner) => inner.get_source(),
AstNode::BabelCall(inner) => inner.get_source(),
AstNode::LatexEnvironment(inner) => inner.get_source(),
AstNode::Bold(inner) => inner.get_source(),
AstNode::Italic(inner) => inner.get_source(),
AstNode::Underline(inner) => inner.get_source(),
AstNode::StrikeThrough(inner) => inner.get_source(),
AstNode::Code(inner) => inner.get_source(),
AstNode::Verbatim(inner) => inner.get_source(),
AstNode::PlainText(inner) => inner.get_source(),
AstNode::RegularLink(inner) => inner.get_source(),
AstNode::RadioLink(inner) => inner.get_source(),
AstNode::RadioTarget(inner) => inner.get_source(),
AstNode::PlainLink(inner) => inner.get_source(),
AstNode::AngleLink(inner) => inner.get_source(),
AstNode::OrgMacro(inner) => inner.get_source(),
AstNode::Entity(inner) => inner.get_source(),
AstNode::LatexFragment(inner) => inner.get_source(),
AstNode::ExportSnippet(inner) => inner.get_source(),
AstNode::FootnoteReference(inner) => inner.get_source(),
AstNode::Citation(inner) => inner.get_source(),
AstNode::CitationReference(inner) => inner.get_source(),
AstNode::InlineBabelCall(inner) => inner.get_source(),
AstNode::InlineSourceBlock(inner) => inner.get_source(),
AstNode::LineBreak(inner) => inner.get_source(),
AstNode::Target(inner) => inner.get_source(),
AstNode::StatisticsCookie(inner) => inner.get_source(),
AstNode::Subscript(inner) => inner.get_source(),
AstNode::Superscript(inner) => inner.get_source(),
AstNode::TableCell(inner) => inner.get_source(),
AstNode::Timestamp(inner) => inner.get_source(),
}
}
fn get_contents(&'s self) -> &'s str {
match self {
AstNode::Document(inner) => inner.get_contents(),
AstNode::Heading(inner) => inner.get_contents(),
AstNode::Section(inner) => inner.get_contents(),
AstNode::Paragraph(inner) => inner.get_contents(),
AstNode::PlainList(inner) => inner.get_contents(),
AstNode::PlainListItem(inner) => inner.get_contents(),
AstNode::CenterBlock(inner) => inner.get_contents(),
AstNode::QuoteBlock(inner) => inner.get_contents(),
AstNode::SpecialBlock(inner) => inner.get_contents(),
AstNode::DynamicBlock(inner) => inner.get_contents(),
AstNode::FootnoteDefinition(inner) => inner.get_contents(),
AstNode::Comment(inner) => inner.get_contents(),
AstNode::Drawer(inner) => inner.get_contents(),
AstNode::PropertyDrawer(inner) => inner.get_contents(),
AstNode::NodeProperty(inner) => inner.get_contents(),
AstNode::Table(inner) => inner.get_contents(),
AstNode::TableRow(inner) => inner.get_contents(),
AstNode::VerseBlock(inner) => inner.get_contents(),
AstNode::CommentBlock(inner) => inner.get_contents(),
AstNode::ExampleBlock(inner) => inner.get_contents(),
AstNode::ExportBlock(inner) => inner.get_contents(),
AstNode::SrcBlock(inner) => inner.get_contents(),
AstNode::Clock(inner) => inner.get_contents(),
AstNode::DiarySexp(inner) => inner.get_contents(),
AstNode::Planning(inner) => inner.get_contents(),
AstNode::FixedWidthArea(inner) => inner.get_contents(),
AstNode::HorizontalRule(inner) => inner.get_contents(),
AstNode::Keyword(inner) => inner.get_contents(),
AstNode::BabelCall(inner) => inner.get_contents(),
AstNode::LatexEnvironment(inner) => inner.get_contents(),
AstNode::Bold(inner) => inner.get_contents(),
AstNode::Italic(inner) => inner.get_contents(),
AstNode::Underline(inner) => inner.get_contents(),
AstNode::StrikeThrough(inner) => inner.get_contents(),
AstNode::Code(inner) => inner.get_contents(),
AstNode::Verbatim(inner) => inner.get_contents(),
AstNode::PlainText(inner) => inner.get_contents(),
AstNode::RegularLink(inner) => inner.get_contents(),
AstNode::RadioLink(inner) => inner.get_contents(),
AstNode::RadioTarget(inner) => inner.get_contents(),
AstNode::PlainLink(inner) => inner.get_contents(),
AstNode::AngleLink(inner) => inner.get_contents(),
AstNode::OrgMacro(inner) => inner.get_contents(),
AstNode::Entity(inner) => inner.get_contents(),
AstNode::LatexFragment(inner) => inner.get_contents(),
AstNode::ExportSnippet(inner) => inner.get_contents(),
AstNode::FootnoteReference(inner) => inner.get_contents(),
AstNode::Citation(inner) => inner.get_contents(),
AstNode::CitationReference(inner) => inner.get_contents(),
AstNode::InlineBabelCall(inner) => inner.get_contents(),
AstNode::InlineSourceBlock(inner) => inner.get_contents(),
AstNode::LineBreak(inner) => inner.get_contents(),
AstNode::Target(inner) => inner.get_contents(),
AstNode::StatisticsCookie(inner) => inner.get_contents(),
AstNode::Subscript(inner) => inner.get_contents(),
AstNode::Superscript(inner) => inner.get_contents(),
AstNode::TableCell(inner) => inner.get_contents(),
AstNode::Timestamp(inner) => inner.get_contents(),
}
}
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(),
AstNode::Section(inner) => inner.get_post_blank(),
AstNode::Paragraph(inner) => inner.get_post_blank(),
AstNode::PlainList(inner) => inner.get_post_blank(),
AstNode::PlainListItem(inner) => inner.get_post_blank(),
AstNode::CenterBlock(inner) => inner.get_post_blank(),
AstNode::QuoteBlock(inner) => inner.get_post_blank(),
AstNode::SpecialBlock(inner) => inner.get_post_blank(),
AstNode::DynamicBlock(inner) => inner.get_post_blank(),
AstNode::FootnoteDefinition(inner) => inner.get_post_blank(),
AstNode::Comment(inner) => inner.get_post_blank(),
AstNode::Drawer(inner) => inner.get_post_blank(),
AstNode::PropertyDrawer(inner) => inner.get_post_blank(),
AstNode::NodeProperty(inner) => inner.get_post_blank(),
AstNode::Table(inner) => inner.get_post_blank(),
AstNode::TableRow(inner) => inner.get_post_blank(),
AstNode::VerseBlock(inner) => inner.get_post_blank(),
AstNode::CommentBlock(inner) => inner.get_post_blank(),
AstNode::ExampleBlock(inner) => inner.get_post_blank(),
AstNode::ExportBlock(inner) => inner.get_post_blank(),
AstNode::SrcBlock(inner) => inner.get_post_blank(),
AstNode::Clock(inner) => inner.get_post_blank(),
AstNode::DiarySexp(inner) => inner.get_post_blank(),
AstNode::Planning(inner) => inner.get_post_blank(),
AstNode::FixedWidthArea(inner) => inner.get_post_blank(),
AstNode::HorizontalRule(inner) => inner.get_post_blank(),
AstNode::Keyword(inner) => inner.get_post_blank(),
AstNode::BabelCall(inner) => inner.get_post_blank(),
AstNode::LatexEnvironment(inner) => inner.get_post_blank(),
AstNode::Bold(inner) => inner.get_post_blank(),
AstNode::Italic(inner) => inner.get_post_blank(),
AstNode::Underline(inner) => inner.get_post_blank(),
AstNode::StrikeThrough(inner) => inner.get_post_blank(),
AstNode::Code(inner) => inner.get_post_blank(),
AstNode::Verbatim(inner) => inner.get_post_blank(),
AstNode::PlainText(inner) => inner.get_post_blank(),
AstNode::RegularLink(inner) => inner.get_post_blank(),
AstNode::RadioLink(inner) => inner.get_post_blank(),
AstNode::RadioTarget(inner) => inner.get_post_blank(),
AstNode::PlainLink(inner) => inner.get_post_blank(),
AstNode::AngleLink(inner) => inner.get_post_blank(),
AstNode::OrgMacro(inner) => inner.get_post_blank(),
AstNode::Entity(inner) => inner.get_post_blank(),
AstNode::LatexFragment(inner) => inner.get_post_blank(),
AstNode::ExportSnippet(inner) => inner.get_post_blank(),
AstNode::FootnoteReference(inner) => inner.get_post_blank(),
AstNode::Citation(inner) => inner.get_post_blank(),
AstNode::CitationReference(inner) => inner.get_post_blank(),
AstNode::InlineBabelCall(inner) => inner.get_post_blank(),
AstNode::InlineSourceBlock(inner) => inner.get_post_blank(),
AstNode::LineBreak(inner) => inner.get_post_blank(),
AstNode::Target(inner) => inner.get_post_blank(),
AstNode::StatisticsCookie(inner) => inner.get_post_blank(),
AstNode::Subscript(inner) => inner.get_post_blank(),
AstNode::Superscript(inner) => inner.get_post_blank(),
AstNode::TableCell(inner) => inner.get_post_blank(),
AstNode::Timestamp(inner) => inner.get_post_blank(),
}
}
}

View File

@ -1,7 +1,6 @@
use std::path::PathBuf;
use super::Element;
use super::GetStandardProperties;
use super::NodeProperty;
use super::Object;
use super::StandardProperties;
@ -54,41 +53,52 @@ pub enum TodoKeywordType {
Done,
}
impl<'s> GetStandardProperties<'s> for DocumentElement<'s> {
fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s> {
match self {
DocumentElement::Heading(inner) => inner,
DocumentElement::Section(inner) => inner,
}
}
}
impl<'s> StandardProperties<'s> for Document<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Section<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Heading<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> Heading<'s> {
pub fn get_raw_value(&self) -> String {
// TODO: I think this could just return a string slice instead of an owned string.
let title_source: String = self
.title
.iter()
.map(|obj| obj.get_standard_properties().get_source())
.collect();
let title_source: String = self.title.iter().map(|obj| obj.get_source()).collect();
title_source
}
@ -132,3 +142,26 @@ impl<'s> Document<'s> {
.flat_map(|property_drawer| property_drawer.children.iter())
}
}
impl<'s> StandardProperties<'s> for DocumentElement<'s> {
fn get_source<'b>(&'b self) -> &'s str {
match self {
DocumentElement::Heading(inner) => inner.get_source(),
DocumentElement::Section(inner) => inner.get_source(),
}
}
fn get_contents(&'s self) -> &'s str {
match self {
DocumentElement::Heading(inner) => inner.get_contents(),
DocumentElement::Section(inner) => inner.get_contents(),
}
}
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::GetStandardProperties;
use super::QuoteBlock;
use super::SpecialBlock;
use super::StandardProperties;
@ -54,33 +53,91 @@ pub enum Element<'s> {
LatexEnvironment(LatexEnvironment<'s>),
}
impl<'s> GetStandardProperties<'s> for Element<'s> {
fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s> {
impl<'s> StandardProperties<'s> for Element<'s> {
fn get_source<'b>(&'b self) -> &'s str {
match self {
Element::Paragraph(inner) => inner,
Element::PlainList(inner) => inner,
Element::CenterBlock(inner) => inner,
Element::QuoteBlock(inner) => inner,
Element::SpecialBlock(inner) => inner,
Element::DynamicBlock(inner) => inner,
Element::FootnoteDefinition(inner) => inner,
Element::Comment(inner) => inner,
Element::Drawer(inner) => inner,
Element::PropertyDrawer(inner) => inner,
Element::Table(inner) => inner,
Element::VerseBlock(inner) => inner,
Element::CommentBlock(inner) => inner,
Element::ExampleBlock(inner) => inner,
Element::ExportBlock(inner) => inner,
Element::SrcBlock(inner) => inner,
Element::Clock(inner) => inner,
Element::DiarySexp(inner) => inner,
Element::Planning(inner) => inner,
Element::FixedWidthArea(inner) => inner,
Element::HorizontalRule(inner) => inner,
Element::Keyword(inner) => inner,
Element::BabelCall(inner) => inner,
Element::LatexEnvironment(inner) => inner,
Element::Paragraph(inner) => inner.get_source(),
Element::PlainList(inner) => inner.get_source(),
Element::CenterBlock(inner) => inner.get_source(),
Element::QuoteBlock(inner) => inner.get_source(),
Element::SpecialBlock(inner) => inner.get_source(),
Element::DynamicBlock(inner) => inner.get_source(),
Element::FootnoteDefinition(inner) => inner.get_source(),
Element::Comment(inner) => inner.get_source(),
Element::Drawer(inner) => inner.get_source(),
Element::PropertyDrawer(inner) => inner.get_source(),
Element::Table(inner) => inner.get_source(),
Element::VerseBlock(inner) => inner.get_source(),
Element::CommentBlock(inner) => inner.get_source(),
Element::ExampleBlock(inner) => inner.get_source(),
Element::ExportBlock(inner) => inner.get_source(),
Element::SrcBlock(inner) => inner.get_source(),
Element::Clock(inner) => inner.get_source(),
Element::DiarySexp(inner) => inner.get_source(),
Element::Planning(inner) => inner.get_source(),
Element::FixedWidthArea(inner) => inner.get_source(),
Element::HorizontalRule(inner) => inner.get_source(),
Element::Keyword(inner) => inner.get_source(),
Element::BabelCall(inner) => inner.get_source(),
Element::LatexEnvironment(inner) => inner.get_source(),
}
}
fn get_contents(&'s self) -> &'s str {
match self {
Element::Paragraph(inner) => inner.get_contents(),
Element::PlainList(inner) => inner.get_contents(),
Element::CenterBlock(inner) => inner.get_contents(),
Element::QuoteBlock(inner) => inner.get_contents(),
Element::SpecialBlock(inner) => inner.get_contents(),
Element::DynamicBlock(inner) => inner.get_contents(),
Element::FootnoteDefinition(inner) => inner.get_contents(),
Element::Comment(inner) => inner.get_contents(),
Element::Drawer(inner) => inner.get_contents(),
Element::PropertyDrawer(inner) => inner.get_contents(),
Element::Table(inner) => inner.get_contents(),
Element::VerseBlock(inner) => inner.get_contents(),
Element::CommentBlock(inner) => inner.get_contents(),
Element::ExampleBlock(inner) => inner.get_contents(),
Element::ExportBlock(inner) => inner.get_contents(),
Element::SrcBlock(inner) => inner.get_contents(),
Element::Clock(inner) => inner.get_contents(),
Element::DiarySexp(inner) => inner.get_contents(),
Element::Planning(inner) => inner.get_contents(),
Element::FixedWidthArea(inner) => inner.get_contents(),
Element::HorizontalRule(inner) => inner.get_contents(),
Element::Keyword(inner) => inner.get_contents(),
Element::BabelCall(inner) => inner.get_contents(),
Element::LatexEnvironment(inner) => inner.get_contents(),
}
}
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(),
Element::CenterBlock(inner) => inner.get_post_blank(),
Element::QuoteBlock(inner) => inner.get_post_blank(),
Element::SpecialBlock(inner) => inner.get_post_blank(),
Element::DynamicBlock(inner) => inner.get_post_blank(),
Element::FootnoteDefinition(inner) => inner.get_post_blank(),
Element::Comment(inner) => inner.get_post_blank(),
Element::Drawer(inner) => inner.get_post_blank(),
Element::PropertyDrawer(inner) => inner.get_post_blank(),
Element::Table(inner) => inner.get_post_blank(),
Element::VerseBlock(inner) => inner.get_post_blank(),
Element::CommentBlock(inner) => inner.get_post_blank(),
Element::ExampleBlock(inner) => inner.get_post_blank(),
Element::ExportBlock(inner) => inner.get_post_blank(),
Element::SrcBlock(inner) => inner.get_post_blank(),
Element::Clock(inner) => inner.get_post_blank(),
Element::DiarySexp(inner) => inner.get_post_blank(),
Element::Planning(inner) => inner.get_post_blank(),
Element::FixedWidthArea(inner) => inner.get_post_blank(),
Element::HorizontalRule(inner) => inner.get_post_blank(),
Element::Keyword(inner) => inner.get_post_blank(),
Element::BabelCall(inner) => inner.get_post_blank(),
Element::LatexEnvironment(inner) => inner.get_post_blank(),
}
}
}

View File

@ -1,12 +0,0 @@
use super::StandardProperties;
pub trait GetStandardProperties<'s> {
// TODO: Can I eliminate this dynamic dispatch, perhaps using nominal generic structs? Low prioritiy since this is not used during parsing.
fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s>;
}
impl<'s, I: StandardProperties<'s>> GetStandardProperties<'s> for I {
fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s> {
self
}
}

View File

@ -131,72 +131,168 @@ impl<'s> StandardProperties<'s> for PlainList<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for PlainListItem<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for CenterBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for QuoteBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for SpecialBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for DynamicBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for FootnoteDefinition<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Drawer<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for PropertyDrawer<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for NodeProperty<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Table<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for TableRow<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> PlainListItem<'s> {

View File

@ -75,7 +75,7 @@ pub struct ExampleBlock<'s> {
pub retain_labels: RetainLabels,
pub use_labels: bool,
pub label_format: Option<&'s str>,
pub contents: &'s str,
pub value: &'s str,
}
#[derive(Debug)]
@ -84,7 +84,7 @@ pub struct ExportBlock<'s> {
pub affiliated_keywords: AffiliatedKeywords<'s>,
pub export_type: Option<&'s str>,
pub data: Option<&'s str>,
pub contents: &'s str,
pub value: &'s str,
}
#[derive(Debug)]
@ -99,7 +99,7 @@ pub struct SrcBlock<'s> {
pub retain_labels: RetainLabels,
pub use_labels: bool,
pub label_format: Option<&'s str>,
pub contents: &'s str,
pub value: &'s str,
}
#[derive(Debug)]
@ -198,92 +198,220 @@ impl<'s> StandardProperties<'s> for Paragraph<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for TableCell<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Comment<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for VerseBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for CommentBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for ExampleBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for ExportBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for SrcBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Clock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for DiarySexp<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Planning<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for FixedWidthArea<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for HorizontalRule<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Keyword<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for BabelCall<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for LatexEnvironment<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> Comment<'s> {
@ -312,8 +440,8 @@ impl<'s> FixedWidthArea<'s> {
impl<'s> ExampleBlock<'s> {
/// Gets the contents of the lesser block, handling the escaping of lines with leading commas.
pub fn get_contents(&self) -> Cow<'s, str> {
lesser_block_content(self.contents).expect("This parser should never fail.")
pub fn get_value(&self) -> Cow<'s, str> {
lesser_block_content(self.value).expect("This parser should never fail.")
}
}
@ -326,15 +454,15 @@ impl<'s> ExportBlock<'s> {
}
/// Gets the contents of the lesser block, handling the escaping of lines with leading commas.
pub fn get_contents(&self) -> Cow<'s, str> {
lesser_block_content(self.contents).expect("This parser should never fail.")
pub fn get_value(&self) -> Cow<'s, str> {
lesser_block_content(self.value).expect("This parser should never fail.")
}
}
impl<'s> SrcBlock<'s> {
/// Gets the contents of the lesser block, handling the escaping of lines with leading commas.
pub fn get_contents(&self) -> Cow<'s, str> {
lesser_block_content(self.contents).expect("This parser should never fail.")
pub fn get_value(&self) -> Cow<'s, str> {
lesser_block_content(self.value).expect("This parser should never fail.")
}
}

View File

@ -2,7 +2,6 @@ mod affiliated_keyword;
mod ast_node;
mod document;
mod element;
mod get_standard_properties;
mod greater_element;
mod lesser_element;
mod macros;
@ -22,7 +21,6 @@ pub use document::PriorityCookie;
pub use document::Section;
pub use document::TodoKeywordType;
pub use element::Element;
pub use get_standard_properties::GetStandardProperties;
pub use greater_element::CenterBlock;
pub use greater_element::CheckboxType;
pub use greater_element::Drawer;

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::GetStandardProperties;
use super::StandardProperties;
#[derive(Debug)]
@ -515,200 +514,382 @@ pub struct WarningDelay {
pub unit: TimeUnit,
}
impl<'s> GetStandardProperties<'s> for Object<'s> {
fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s> {
match self {
Object::Bold(inner) => inner,
Object::Italic(inner) => inner,
Object::Underline(inner) => inner,
Object::StrikeThrough(inner) => inner,
Object::Code(inner) => inner,
Object::Verbatim(inner) => inner,
Object::PlainText(inner) => inner,
Object::RegularLink(inner) => inner,
Object::RadioLink(inner) => inner,
Object::RadioTarget(inner) => inner,
Object::PlainLink(inner) => inner,
Object::AngleLink(inner) => inner,
Object::OrgMacro(inner) => inner,
Object::Entity(inner) => inner,
Object::LatexFragment(inner) => inner,
Object::ExportSnippet(inner) => inner,
Object::FootnoteReference(inner) => inner,
Object::Citation(inner) => inner,
Object::CitationReference(inner) => inner,
Object::InlineBabelCall(inner) => inner,
Object::InlineSourceBlock(inner) => inner,
Object::LineBreak(inner) => inner,
Object::Target(inner) => inner,
Object::StatisticsCookie(inner) => inner,
Object::Subscript(inner) => inner,
Object::Superscript(inner) => inner,
Object::Timestamp(inner) => inner,
}
}
}
impl<'s> StandardProperties<'s> for Bold<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Italic<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Underline<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for StrikeThrough<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Code<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Verbatim<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for RegularLink<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for RadioLink<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for RadioTarget<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for PlainLink<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for AngleLink<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for OrgMacro<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Entity<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for LatexFragment<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for ExportSnippet<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for FootnoteReference<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Citation<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for CitationReference<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for InlineBabelCall<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for InlineSourceBlock<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for LineBreak<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Target<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for StatisticsCookie<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Subscript<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Superscript<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for Timestamp<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> StandardProperties<'s> for PlainText<'s> {
fn get_source<'b>(&'b self) -> &'s str {
self.source
}
fn get_contents(&'s self) -> &'s str {
todo!()
}
fn get_post_blank<'b>(&'b self) -> &'s str {
todo!()
}
}
impl<'s> Timestamp<'s> {
@ -801,3 +982,101 @@ impl<'s> FootnoteReference<'s> {
}
}
}
impl<'s> StandardProperties<'s> for Object<'s> {
fn get_source<'b>(&'b self) -> &'s str {
match self {
Object::Bold(inner) => inner.get_source(),
Object::Italic(inner) => inner.get_source(),
Object::Underline(inner) => inner.get_source(),
Object::StrikeThrough(inner) => inner.get_source(),
Object::Code(inner) => inner.get_source(),
Object::Verbatim(inner) => inner.get_source(),
Object::PlainText(inner) => inner.get_source(),
Object::RegularLink(inner) => inner.get_source(),
Object::RadioLink(inner) => inner.get_source(),
Object::RadioTarget(inner) => inner.get_source(),
Object::PlainLink(inner) => inner.get_source(),
Object::AngleLink(inner) => inner.get_source(),
Object::OrgMacro(inner) => inner.get_source(),
Object::Entity(inner) => inner.get_source(),
Object::LatexFragment(inner) => inner.get_source(),
Object::ExportSnippet(inner) => inner.get_source(),
Object::FootnoteReference(inner) => inner.get_source(),
Object::Citation(inner) => inner.get_source(),
Object::CitationReference(inner) => inner.get_source(),
Object::InlineBabelCall(inner) => inner.get_source(),
Object::InlineSourceBlock(inner) => inner.get_source(),
Object::LineBreak(inner) => inner.get_source(),
Object::Target(inner) => inner.get_source(),
Object::StatisticsCookie(inner) => inner.get_source(),
Object::Subscript(inner) => inner.get_source(),
Object::Superscript(inner) => inner.get_source(),
Object::Timestamp(inner) => inner.get_source(),
}
}
fn get_contents(&'s self) -> &'s str {
match self {
Object::Bold(inner) => inner.get_contents(),
Object::Italic(inner) => inner.get_contents(),
Object::Underline(inner) => inner.get_contents(),
Object::StrikeThrough(inner) => inner.get_contents(),
Object::Code(inner) => inner.get_contents(),
Object::Verbatim(inner) => inner.get_contents(),
Object::PlainText(inner) => inner.get_contents(),
Object::RegularLink(inner) => inner.get_contents(),
Object::RadioLink(inner) => inner.get_contents(),
Object::RadioTarget(inner) => inner.get_contents(),
Object::PlainLink(inner) => inner.get_contents(),
Object::AngleLink(inner) => inner.get_contents(),
Object::OrgMacro(inner) => inner.get_contents(),
Object::Entity(inner) => inner.get_contents(),
Object::LatexFragment(inner) => inner.get_contents(),
Object::ExportSnippet(inner) => inner.get_contents(),
Object::FootnoteReference(inner) => inner.get_contents(),
Object::Citation(inner) => inner.get_contents(),
Object::CitationReference(inner) => inner.get_contents(),
Object::InlineBabelCall(inner) => inner.get_contents(),
Object::InlineSourceBlock(inner) => inner.get_contents(),
Object::LineBreak(inner) => inner.get_contents(),
Object::Target(inner) => inner.get_contents(),
Object::StatisticsCookie(inner) => inner.get_contents(),
Object::Subscript(inner) => inner.get_contents(),
Object::Superscript(inner) => inner.get_contents(),
Object::Timestamp(inner) => inner.get_contents(),
}
}
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(),
Object::Underline(inner) => inner.get_post_blank(),
Object::StrikeThrough(inner) => inner.get_post_blank(),
Object::Code(inner) => inner.get_post_blank(),
Object::Verbatim(inner) => inner.get_post_blank(),
Object::PlainText(inner) => inner.get_post_blank(),
Object::RegularLink(inner) => inner.get_post_blank(),
Object::RadioLink(inner) => inner.get_post_blank(),
Object::RadioTarget(inner) => inner.get_post_blank(),
Object::PlainLink(inner) => inner.get_post_blank(),
Object::AngleLink(inner) => inner.get_post_blank(),
Object::OrgMacro(inner) => inner.get_post_blank(),
Object::Entity(inner) => inner.get_post_blank(),
Object::LatexFragment(inner) => inner.get_post_blank(),
Object::ExportSnippet(inner) => inner.get_post_blank(),
Object::FootnoteReference(inner) => inner.get_post_blank(),
Object::Citation(inner) => inner.get_post_blank(),
Object::CitationReference(inner) => inner.get_post_blank(),
Object::InlineBabelCall(inner) => inner.get_post_blank(),
Object::InlineSourceBlock(inner) => inner.get_post_blank(),
Object::LineBreak(inner) => inner.get_post_blank(),
Object::Target(inner) => inner.get_post_blank(),
Object::StatisticsCookie(inner) => inner.get_post_blank(),
Object::Subscript(inner) => inner.get_post_blank(),
Object::Superscript(inner) => inner.get_post_blank(),
Object::Timestamp(inner) => inner.get_post_blank(),
}
}
}

View File

@ -5,10 +5,15 @@ pub trait StandardProperties<'s> {
/// This corresponds to :begin to :end in upstream org-mode's standard properties.
fn get_source<'b>(&'b self) -> &'s str;
// Get the slice of the AST node's contents.
//
// This corresponds to :contents-begin to :contents-end
// fn get_contents(&'s self) -> &'s str;
/// Get the slice of the AST node's contents.
///
/// This corresponds to :contents-begin to :contents-end
fn get_contents(&'s self) -> &'s str;
/// Get the slice of the AST node's post-blank text.
///
/// 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.