From 3fe56e9aa33ae4bdc8257127ae5587f3493d1b33 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 23 Sep 2023 17:40:53 -0400 Subject: [PATCH] Implement StandardProperties for all the AST nodes and restrict the Source trait to this crate. Currently this is a copy of the Source trait but it will grow to more functions. The Source trait is restricted to this crate in anticipation of its removal in favor of StandardProperties. --- src/types/document.rs | 28 ++++++ src/types/greater_element.rs | 61 +++++++++++++ src/types/lesser_element.rs | 87 +++++++++++++++++++ src/types/mod.rs | 2 +- src/types/object.rs | 163 +++++++++++++++++++++++++++++++++++ src/types/source.rs | 2 +- 6 files changed, 341 insertions(+), 2 deletions(-) diff --git a/src/types/document.rs b/src/types/document.rs index 1acc468..8139fac 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -1,6 +1,7 @@ use super::Element; use super::Object; use super::Source; +use super::StandardProperties; pub type PriorityCookie = u8; pub type HeadlineLevel = u16; @@ -69,3 +70,30 @@ impl<'s> Source<'s> for Heading<'s> { self.source } } + +impl<'s> StandardProperties<'s> for Document<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for DocumentElement<'s> { + fn get_source(&'s self) -> &'s str { + match self { + DocumentElement::Heading(obj) => obj.source, + DocumentElement::Section(obj) => obj.source, + } + } +} + +impl<'s> StandardProperties<'s> for Section<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Heading<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index dfbd904..f794041 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -3,6 +3,7 @@ use super::lesser_element::TableCell; use super::Keyword; use super::Object; use super::Source; +use super::StandardProperties; #[derive(Debug)] pub struct PlainList<'s> { @@ -144,3 +145,63 @@ impl<'s> Source<'s> for TableRow<'s> { self.source } } + +impl<'s> StandardProperties<'s> for PlainList<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for PlainListItem<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for GreaterBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for DynamicBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for FootnoteDefinition<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Drawer<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for PropertyDrawer<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for NodeProperty<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Table<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for TableRow<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index e627a8c..bacdb71 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -1,6 +1,7 @@ use super::object::Object; use super::PlainText; use super::Source; +use super::StandardProperties; #[derive(Debug)] pub struct Paragraph<'s> { @@ -192,3 +193,89 @@ impl<'s> Source<'s> for LatexEnvironment<'s> { self.source } } + +impl<'s> StandardProperties<'s> for Paragraph<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for TableCell<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Comment<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for VerseBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} +impl<'s> StandardProperties<'s> for CommentBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} +impl<'s> StandardProperties<'s> for ExampleBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} +impl<'s> StandardProperties<'s> for ExportBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} +impl<'s> StandardProperties<'s> for SrcBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Clock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for DiarySexp<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Planning<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for FixedWidthArea<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for HorizontalRule<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Keyword<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for LatexEnvironment<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 5aaf398..4af73bf 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -69,5 +69,5 @@ pub use object::Timestamp; pub use object::Underline; pub use object::Verbatim; pub(crate) use source::SetSource; -pub use source::Source; +pub(crate) use source::Source; pub use standard_properties::StandardProperties; diff --git a/src/types/object.rs b/src/types/object.rs index 7e5da11..e4e0265 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -1,4 +1,5 @@ use super::Source; +use super::StandardProperties; #[derive(Debug, PartialEq)] pub enum Object<'s> { @@ -380,3 +381,165 @@ impl<'s> Source<'s> for PlainText<'s> { self.source } } + +impl<'s> StandardProperties<'s> for Bold<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Italic<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Underline<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for StrikeThrough<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Code<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Verbatim<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for RegularLink<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for RadioLink<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for RadioTarget<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for PlainLink<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for AngleLink<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for OrgMacro<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Entity<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for LatexFragment<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for ExportSnippet<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for FootnoteReference<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Citation<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for CitationReference<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for InlineBabelCall<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for InlineSourceBlock<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for LineBreak<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Target<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for StatisticsCookie<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Subscript<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Superscript<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for Timestamp<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> StandardProperties<'s> for PlainText<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/types/source.rs b/src/types/source.rs index cd3945e..ca7c602 100644 --- a/src/types/source.rs +++ b/src/types/source.rs @@ -1,4 +1,4 @@ -pub trait Source<'s> { +pub(crate) trait Source<'s> { fn get_source(&'s self) -> &'s str; } pub(crate) trait SetSource<'s> {