Add PlainListItem to ast nodes.

This commit is contained in:
Tom Alexander 2023-09-27 18:21:42 -04:00
parent c5be75ee8d
commit d8c52568db
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 84 additions and 262 deletions

View File

@ -1,3 +1,4 @@
use super::macros::to_ast_node;
use crate::types::AngleLink;
use crate::types::BabelCall;
use crate::types::Bold;
@ -35,6 +36,7 @@ use crate::types::OrgMacro;
use crate::types::Paragraph;
use crate::types::PlainLink;
use crate::types::PlainList;
use crate::types::PlainListItem;
use crate::types::PlainText;
use crate::types::Planning;
use crate::types::PropertyDrawer;
@ -62,6 +64,7 @@ pub enum AstNode<'r, 's> {
// Elements
Paragraph(&'r Paragraph<'s>),
PlainList(&'r PlainList<'s>),
PlainListItem(&'r PlainListItem<'s>),
GreaterBlock(&'r GreaterBlock<'s>),
DynamicBlock(&'r DynamicBlock<'s>),
FootnoteDefinition(&'r FootnoteDefinition<'s>),
@ -184,263 +187,56 @@ impl<'r, 's> From<&'r Object<'s>> for AstNode<'r, 's> {
}
}
impl<'r, 's> From<&'r Document<'s>> for AstNode<'r, 's> {
fn from(value: &'r Document<'s>) -> Self {
AstNode::Document(value)
}
}
impl<'r, 's> From<&'r Heading<'s>> for AstNode<'r, 's> {
fn from(value: &'r Heading<'s>) -> Self {
AstNode::Heading(value)
}
}
impl<'r, 's> From<&'r Section<'s>> for AstNode<'r, 's> {
fn from(value: &'r Section<'s>) -> Self {
AstNode::Section(value)
}
}
impl<'r, 's> From<&'r Paragraph<'s>> for AstNode<'r, 's> {
fn from(value: &'r Paragraph<'s>) -> Self {
AstNode::Paragraph(value)
}
}
impl<'r, 's> From<&'r PlainList<'s>> for AstNode<'r, 's> {
fn from(value: &'r PlainList<'s>) -> Self {
AstNode::PlainList(value)
}
}
impl<'r, 's> From<&'r GreaterBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r GreaterBlock<'s>) -> Self {
AstNode::GreaterBlock(value)
}
}
impl<'r, 's> From<&'r DynamicBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r DynamicBlock<'s>) -> Self {
AstNode::DynamicBlock(value)
}
}
impl<'r, 's> From<&'r FootnoteDefinition<'s>> for AstNode<'r, 's> {
fn from(value: &'r FootnoteDefinition<'s>) -> Self {
AstNode::FootnoteDefinition(value)
}
}
impl<'r, 's> From<&'r Comment<'s>> for AstNode<'r, 's> {
fn from(value: &'r Comment<'s>) -> Self {
AstNode::Comment(value)
}
}
impl<'r, 's> From<&'r Drawer<'s>> for AstNode<'r, 's> {
fn from(value: &'r Drawer<'s>) -> Self {
AstNode::Drawer(value)
}
}
impl<'r, 's> From<&'r PropertyDrawer<'s>> for AstNode<'r, 's> {
fn from(value: &'r PropertyDrawer<'s>) -> Self {
AstNode::PropertyDrawer(value)
}
}
impl<'r, 's> From<&'r Table<'s>> for AstNode<'r, 's> {
fn from(value: &'r Table<'s>) -> Self {
AstNode::Table(value)
}
}
impl<'r, 's> From<&'r VerseBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r VerseBlock<'s>) -> Self {
AstNode::VerseBlock(value)
}
}
impl<'r, 's> From<&'r CommentBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r CommentBlock<'s>) -> Self {
AstNode::CommentBlock(value)
}
}
impl<'r, 's> From<&'r ExampleBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r ExampleBlock<'s>) -> Self {
AstNode::ExampleBlock(value)
}
}
impl<'r, 's> From<&'r ExportBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r ExportBlock<'s>) -> Self {
AstNode::ExportBlock(value)
}
}
impl<'r, 's> From<&'r SrcBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r SrcBlock<'s>) -> Self {
AstNode::SrcBlock(value)
}
}
impl<'r, 's> From<&'r Clock<'s>> for AstNode<'r, 's> {
fn from(value: &'r Clock<'s>) -> Self {
AstNode::Clock(value)
}
}
impl<'r, 's> From<&'r DiarySexp<'s>> for AstNode<'r, 's> {
fn from(value: &'r DiarySexp<'s>) -> Self {
AstNode::DiarySexp(value)
}
}
impl<'r, 's> From<&'r Planning<'s>> for AstNode<'r, 's> {
fn from(value: &'r Planning<'s>) -> Self {
AstNode::Planning(value)
}
}
impl<'r, 's> From<&'r FixedWidthArea<'s>> for AstNode<'r, 's> {
fn from(value: &'r FixedWidthArea<'s>) -> Self {
AstNode::FixedWidthArea(value)
}
}
impl<'r, 's> From<&'r HorizontalRule<'s>> for AstNode<'r, 's> {
fn from(value: &'r HorizontalRule<'s>) -> Self {
AstNode::HorizontalRule(value)
}
}
impl<'r, 's> From<&'r Keyword<'s>> for AstNode<'r, 's> {
fn from(value: &'r Keyword<'s>) -> Self {
AstNode::Keyword(value)
}
}
impl<'r, 's> From<&'r BabelCall<'s>> for AstNode<'r, 's> {
fn from(value: &'r BabelCall<'s>) -> Self {
AstNode::BabelCall(value)
}
}
impl<'r, 's> From<&'r LatexEnvironment<'s>> for AstNode<'r, 's> {
fn from(value: &'r LatexEnvironment<'s>) -> Self {
AstNode::LatexEnvironment(value)
}
}
impl<'r, 's> From<&'r Bold<'s>> for AstNode<'r, 's> {
fn from(value: &'r Bold<'s>) -> Self {
AstNode::Bold(value)
}
}
impl<'r, 's> From<&'r Italic<'s>> for AstNode<'r, 's> {
fn from(value: &'r Italic<'s>) -> Self {
AstNode::Italic(value)
}
}
impl<'r, 's> From<&'r Underline<'s>> for AstNode<'r, 's> {
fn from(value: &'r Underline<'s>) -> Self {
AstNode::Underline(value)
}
}
impl<'r, 's> From<&'r StrikeThrough<'s>> for AstNode<'r, 's> {
fn from(value: &'r StrikeThrough<'s>) -> Self {
AstNode::StrikeThrough(value)
}
}
impl<'r, 's> From<&'r Code<'s>> for AstNode<'r, 's> {
fn from(value: &'r Code<'s>) -> Self {
AstNode::Code(value)
}
}
impl<'r, 's> From<&'r Verbatim<'s>> for AstNode<'r, 's> {
fn from(value: &'r Verbatim<'s>) -> Self {
AstNode::Verbatim(value)
}
}
impl<'r, 's> From<&'r PlainText<'s>> for AstNode<'r, 's> {
fn from(value: &'r PlainText<'s>) -> Self {
AstNode::PlainText(value)
}
}
impl<'r, 's> From<&'r RegularLink<'s>> for AstNode<'r, 's> {
fn from(value: &'r RegularLink<'s>) -> Self {
AstNode::RegularLink(value)
}
}
impl<'r, 's> From<&'r RadioLink<'s>> for AstNode<'r, 's> {
fn from(value: &'r RadioLink<'s>) -> Self {
AstNode::RadioLink(value)
}
}
impl<'r, 's> From<&'r RadioTarget<'s>> for AstNode<'r, 's> {
fn from(value: &'r RadioTarget<'s>) -> Self {
AstNode::RadioTarget(value)
}
}
impl<'r, 's> From<&'r PlainLink<'s>> for AstNode<'r, 's> {
fn from(value: &'r PlainLink<'s>) -> Self {
AstNode::PlainLink(value)
}
}
impl<'r, 's> From<&'r AngleLink<'s>> for AstNode<'r, 's> {
fn from(value: &'r AngleLink<'s>) -> Self {
AstNode::AngleLink(value)
}
}
impl<'r, 's> From<&'r OrgMacro<'s>> for AstNode<'r, 's> {
fn from(value: &'r OrgMacro<'s>) -> Self {
AstNode::OrgMacro(value)
}
}
impl<'r, 's> From<&'r Entity<'s>> for AstNode<'r, 's> {
fn from(value: &'r Entity<'s>) -> Self {
AstNode::Entity(value)
}
}
impl<'r, 's> From<&'r LatexFragment<'s>> for AstNode<'r, 's> {
fn from(value: &'r LatexFragment<'s>) -> Self {
AstNode::LatexFragment(value)
}
}
impl<'r, 's> From<&'r ExportSnippet<'s>> for AstNode<'r, 's> {
fn from(value: &'r ExportSnippet<'s>) -> Self {
AstNode::ExportSnippet(value)
}
}
impl<'r, 's> From<&'r FootnoteReference<'s>> for AstNode<'r, 's> {
fn from(value: &'r FootnoteReference<'s>) -> Self {
AstNode::FootnoteReference(value)
}
}
impl<'r, 's> From<&'r Citation<'s>> for AstNode<'r, 's> {
fn from(value: &'r Citation<'s>) -> Self {
AstNode::Citation(value)
}
}
impl<'r, 's> From<&'r CitationReference<'s>> for AstNode<'r, 's> {
fn from(value: &'r CitationReference<'s>) -> Self {
AstNode::CitationReference(value)
}
}
impl<'r, 's> From<&'r InlineBabelCall<'s>> for AstNode<'r, 's> {
fn from(value: &'r InlineBabelCall<'s>) -> Self {
AstNode::InlineBabelCall(value)
}
}
impl<'r, 's> From<&'r InlineSourceBlock<'s>> for AstNode<'r, 's> {
fn from(value: &'r InlineSourceBlock<'s>) -> Self {
AstNode::InlineSourceBlock(value)
}
}
impl<'r, 's> From<&'r LineBreak<'s>> for AstNode<'r, 's> {
fn from(value: &'r LineBreak<'s>) -> Self {
AstNode::LineBreak(value)
}
}
impl<'r, 's> From<&'r Target<'s>> for AstNode<'r, 's> {
fn from(value: &'r Target<'s>) -> Self {
AstNode::Target(value)
}
}
impl<'r, 's> From<&'r StatisticsCookie<'s>> for AstNode<'r, 's> {
fn from(value: &'r StatisticsCookie<'s>) -> Self {
AstNode::StatisticsCookie(value)
}
}
impl<'r, 's> From<&'r Subscript<'s>> for AstNode<'r, 's> {
fn from(value: &'r Subscript<'s>) -> Self {
AstNode::Subscript(value)
}
}
impl<'r, 's> From<&'r Superscript<'s>> for AstNode<'r, 's> {
fn from(value: &'r Superscript<'s>) -> Self {
AstNode::Superscript(value)
}
}
impl<'r, 's> From<&'r Timestamp<'s>> for AstNode<'r, 's> {
fn from(value: &'r Timestamp<'s>) -> Self {
AstNode::Timestamp(value)
}
}
to_ast_node!(&'r Document<'s>, AstNode::Document);
to_ast_node!(&'r Heading<'s>, AstNode::Heading);
to_ast_node!(&'r Section<'s>, AstNode::Section);
to_ast_node!(&'r Paragraph<'s>, AstNode::Paragraph);
to_ast_node!(&'r PlainList<'s>, AstNode::PlainList);
to_ast_node!(&'r PlainListItem<'s>, AstNode::PlainListItem);
to_ast_node!(&'r GreaterBlock<'s>, AstNode::GreaterBlock);
to_ast_node!(&'r DynamicBlock<'s>, AstNode::DynamicBlock);
to_ast_node!(&'r FootnoteDefinition<'s>, AstNode::FootnoteDefinition);
to_ast_node!(&'r Comment<'s>, AstNode::Comment);
to_ast_node!(&'r Drawer<'s>, AstNode::Drawer);
to_ast_node!(&'r PropertyDrawer<'s>, AstNode::PropertyDrawer);
to_ast_node!(&'r Table<'s>, AstNode::Table);
to_ast_node!(&'r VerseBlock<'s>, AstNode::VerseBlock);
to_ast_node!(&'r CommentBlock<'s>, AstNode::CommentBlock);
to_ast_node!(&'r ExampleBlock<'s>, AstNode::ExampleBlock);
to_ast_node!(&'r ExportBlock<'s>, AstNode::ExportBlock);
to_ast_node!(&'r SrcBlock<'s>, AstNode::SrcBlock);
to_ast_node!(&'r Clock<'s>, AstNode::Clock);
to_ast_node!(&'r DiarySexp<'s>, AstNode::DiarySexp);
to_ast_node!(&'r Planning<'s>, AstNode::Planning);
to_ast_node!(&'r FixedWidthArea<'s>, AstNode::FixedWidthArea);
to_ast_node!(&'r HorizontalRule<'s>, AstNode::HorizontalRule);
to_ast_node!(&'r Keyword<'s>, AstNode::Keyword);
to_ast_node!(&'r BabelCall<'s>, AstNode::BabelCall);
to_ast_node!(&'r LatexEnvironment<'s>, AstNode::LatexEnvironment);
to_ast_node!(&'r Bold<'s>, AstNode::Bold);
to_ast_node!(&'r Italic<'s>, AstNode::Italic);
to_ast_node!(&'r Underline<'s>, AstNode::Underline);
to_ast_node!(&'r StrikeThrough<'s>, AstNode::StrikeThrough);
to_ast_node!(&'r Code<'s>, AstNode::Code);
to_ast_node!(&'r Verbatim<'s>, AstNode::Verbatim);
to_ast_node!(&'r PlainText<'s>, AstNode::PlainText);
to_ast_node!(&'r RegularLink<'s>, AstNode::RegularLink);
to_ast_node!(&'r RadioLink<'s>, AstNode::RadioLink);
to_ast_node!(&'r RadioTarget<'s>, AstNode::RadioTarget);
to_ast_node!(&'r PlainLink<'s>, AstNode::PlainLink);
to_ast_node!(&'r AngleLink<'s>, AstNode::AngleLink);
to_ast_node!(&'r OrgMacro<'s>, AstNode::OrgMacro);
to_ast_node!(&'r Entity<'s>, AstNode::Entity);
to_ast_node!(&'r LatexFragment<'s>, AstNode::LatexFragment);
to_ast_node!(&'r ExportSnippet<'s>, AstNode::ExportSnippet);
to_ast_node!(&'r FootnoteReference<'s>, AstNode::FootnoteReference);
to_ast_node!(&'r Citation<'s>, AstNode::Citation);
to_ast_node!(&'r CitationReference<'s>, AstNode::CitationReference);
to_ast_node!(&'r InlineBabelCall<'s>, AstNode::InlineBabelCall);
to_ast_node!(&'r InlineSourceBlock<'s>, AstNode::InlineSourceBlock);
to_ast_node!(&'r LineBreak<'s>, AstNode::LineBreak);
to_ast_node!(&'r Target<'s>, AstNode::Target);
to_ast_node!(&'r StatisticsCookie<'s>, AstNode::StatisticsCookie);
to_ast_node!(&'r Subscript<'s>, AstNode::Subscript);
to_ast_node!(&'r Superscript<'s>, AstNode::Superscript);
to_ast_node!(&'r Timestamp<'s>, AstNode::Timestamp);

View File

@ -11,6 +11,9 @@ use crate::types::Element;
use crate::types::Heading;
use crate::types::Italic;
use crate::types::Object;
use crate::types::Paragraph;
use crate::types::PlainList;
use crate::types::PlainListItem;
use crate::types::PlainText;
use crate::types::RadioLink;
use crate::types::RegularLink;
@ -30,8 +33,8 @@ pub enum AstNodeIter<'r, 's> {
Heading(HeadingIter<'r, 's>),
Section(SectionIter<'r, 's>),
// Elements
// Paragraph(ParagraphIter<'r, 's>),
// PlainList(PlainListIter<'r, 's>),
Paragraph(ParagraphIter<'r, 's>),
PlainList(PlainListIter<'r, 's>),
// GreaterBlock(GreaterBlockIter<'r, 's>),
// DynamicBlock(DynamicBlockIter<'r, 's>),
// FootnoteDefinition(FootnoteDefinitionIter<'r, 's>),
@ -141,6 +144,16 @@ impl<'r, 's> IntoIterator for &'r Heading<'s> {
}
children_iter!(Section<'s>, SectionIter, std::slice::Iter<'r, Element<'s>>);
children_iter!(
Paragraph<'s>,
ParagraphIter,
std::slice::Iter<'r, Object<'s>>
);
children_iter!(
PlainList<'s>,
PlainListIter,
std::slice::Iter<'r, PlainListItem<'s>>
);
children_iter!(Bold<'s>, BoldIter, std::slice::Iter<'r, Object<'s>>);
children_iter!(Italic<'s>, ItalicIter, std::slice::Iter<'r, Object<'s>>);
children_iter!(

View File

@ -1,3 +1,16 @@
/// Write the implementation of From<> to convert a borrow of the type to an AstNode
macro_rules! to_ast_node {
($inp:ty, $enum:expr) => {
impl<'r, 's> From<$inp> for AstNode<'r, 's> {
fn from(value: $inp) -> Self {
$enum(value)
}
}
};
}
pub(crate) use to_ast_node;
/// Create iterators for ast nodes where it only has to iterate over children
macro_rules! children_iter {
($astnodetype:ty, $itertype:ident, $innertype:ty) => {