2023-09-27 15:38:33 -04:00
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
2023-09-27 15:07:26 -04:00
|
|
|
use super::ast_node::AstNode;
|
2023-09-27 15:38:33 -04:00
|
|
|
use super::macros::simple_iter;
|
2023-09-27 15:17:56 -04:00
|
|
|
use crate::types::Bold;
|
2023-09-27 15:38:33 -04:00
|
|
|
use crate::types::Code;
|
2023-09-27 15:28:43 -04:00
|
|
|
use crate::types::Italic;
|
2023-09-27 13:48:17 -04:00
|
|
|
use crate::types::Object;
|
2023-09-27 15:38:33 -04:00
|
|
|
use crate::types::StrikeThrough;
|
|
|
|
use crate::types::Underline;
|
2023-09-27 13:48:17 -04:00
|
|
|
|
2023-09-27 15:07:26 -04:00
|
|
|
pub enum AstNodeIter<'r, 's> {
|
2023-09-27 14:24:08 -04:00
|
|
|
// Document Nodes
|
2023-09-27 15:07:26 -04:00
|
|
|
// Document(DocumentIter<'r, 's>),
|
|
|
|
// Heading(HeadingIter<'r, 's>),
|
|
|
|
// Section(SectionIter<'r, 's>),
|
2023-09-27 14:24:08 -04:00
|
|
|
// Elements
|
2023-09-27 15:07:26 -04:00
|
|
|
// Paragraph(ParagraphIter<'r, 's>),
|
|
|
|
// PlainList(PlainListIter<'r, 's>),
|
|
|
|
// GreaterBlock(GreaterBlockIter<'r, 's>),
|
|
|
|
// DynamicBlock(DynamicBlockIter<'r, 's>),
|
|
|
|
// FootnoteDefinition(FootnoteDefinitionIter<'r, 's>),
|
|
|
|
// Comment(CommentIter<'r, 's>),
|
|
|
|
// Drawer(DrawerIter<'r, 's>),
|
|
|
|
// PropertyDrawer(PropertyDrawerIter<'r, 's>),
|
|
|
|
// Table(TableIter<'r, 's>),
|
|
|
|
// VerseBlock(VerseBlockIter<'r, 's>),
|
|
|
|
// CommentBlock(CommentBlockIter<'r, 's>),
|
|
|
|
// ExampleBlock(ExampleBlockIter<'r, 's>),
|
|
|
|
// ExportBlock(ExportBlockIter<'r, 's>),
|
|
|
|
// SrcBlock(SrcBlockIter<'r, 's>),
|
|
|
|
// Clock(ClockIter<'r, 's>),
|
|
|
|
// DiarySexp(DiarySexpIter<'r, 's>),
|
|
|
|
// Planning(PlanningIter<'r, 's>),
|
|
|
|
// FixedWidthArea(FixedWidthAreaIter<'r, 's>),
|
|
|
|
// HorizontalRule(HorizontalRuleIter<'r, 's>),
|
|
|
|
// Keyword(KeywordIter<'r, 's>),
|
|
|
|
// BabelCall(BabelCallIter<'r, 's>),
|
|
|
|
// LatexEnvironment(LatexEnvironmentIter<'r, 's>),
|
2023-09-27 14:24:08 -04:00
|
|
|
// Objects
|
2023-09-27 15:07:26 -04:00
|
|
|
Bold(BoldIter<'r, 's>),
|
2023-09-27 15:28:43 -04:00
|
|
|
Italic(ItalicIter<'r, 's>),
|
2023-09-27 15:38:33 -04:00
|
|
|
Underline(UnderlineIter<'r, 's>),
|
|
|
|
StrikeThrough(StrikeThroughIter<'r, 's>),
|
|
|
|
Code(CodeIter<'r, 's>),
|
2023-09-27 15:07:26 -04:00
|
|
|
// Verbatim(VerbatimIter<'r, 's>),
|
|
|
|
// PlainText(PlainTextIter<'r, 's>),
|
|
|
|
// RegularLink(RegularLinkIter<'r, 's>),
|
|
|
|
// RadioLink(RadioLinkIter<'r, 's>),
|
|
|
|
// RadioTarget(RadioTargetIter<'r, 's>),
|
|
|
|
// PlainLink(PlainLinkIter<'r, 's>),
|
|
|
|
// AngleLink(AngleLinkIter<'r, 's>),
|
|
|
|
// OrgMacro(OrgMacroIter<'r, 's>),
|
|
|
|
// Entity(EntityIter<'r, 's>),
|
|
|
|
// LatexFragment(LatexFragmentIter<'r, 's>),
|
|
|
|
// ExportSnippet(ExportSnippetIter<'r, 's>),
|
|
|
|
// FootnoteReference(FootnoteReferenceIter<'r, 's>),
|
|
|
|
// Citation(CitationIter<'r, 's>),
|
|
|
|
// CitationReference(CitationReferenceIter<'r, 's>),
|
|
|
|
// InlineBabelCall(InlineBabelCallIter<'r, 's>),
|
|
|
|
// InlineSourceBlock(InlineSourceBlockIter<'r, 's>),
|
|
|
|
// LineBreak(LineBreakIter<'r, 's>),
|
|
|
|
// Target(TargetIter<'r, 's>),
|
|
|
|
// StatisticsCookie(StatisticsCookieIter<'r, 's>),
|
|
|
|
// Subscript(SubscriptIter<'r, 's>),
|
|
|
|
// Superscript(SuperscriptIter<'r, 's>),
|
|
|
|
// Timestamp(TimestampIter<'r, 's>),
|
2023-09-27 14:24:08 -04:00
|
|
|
}
|
|
|
|
|
2023-09-27 15:07:26 -04:00
|
|
|
pub struct BoldIter<'r, 's> {
|
|
|
|
next: std::slice::Iter<'r, Object<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'r, 's> Iterator for BoldIter<'r, 's> {
|
|
|
|
type Item = AstNode<'r, 's>;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
2023-09-27 15:17:56 -04:00
|
|
|
self.next.next().map(Into::<AstNode>::into)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'r, 's> IntoIterator for &'r Bold<'s> {
|
|
|
|
type Item = AstNode<'r, 's>;
|
|
|
|
|
|
|
|
type IntoIter = BoldIter<'r, 's>;
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
BoldIter {
|
|
|
|
next: self.children.iter(),
|
|
|
|
}
|
2023-09-27 15:07:26 -04:00
|
|
|
}
|
2023-09-27 13:48:17 -04:00
|
|
|
}
|
2023-09-27 15:28:43 -04:00
|
|
|
|
2023-09-27 15:38:33 -04:00
|
|
|
simple_iter!(Italic<'s>, ItalicIter, std::slice::Iter<'r, Object<'s>>);
|
|
|
|
simple_iter!(
|
|
|
|
Underline<'s>,
|
|
|
|
UnderlineIter,
|
|
|
|
std::slice::Iter<'r, Object<'s>>
|
|
|
|
);
|
|
|
|
simple_iter!(
|
|
|
|
StrikeThrough<'s>,
|
|
|
|
StrikeThroughIter,
|
|
|
|
std::slice::Iter<'r, Object<'s>>
|
|
|
|
);
|
2023-09-27 15:28:43 -04:00
|
|
|
|
2023-09-27 15:38:33 -04:00
|
|
|
pub struct CodeIter<'r, 's> {
|
|
|
|
phantom: PhantomData<&'r Code<'s>>,
|
|
|
|
}
|
2023-09-27 15:28:43 -04:00
|
|
|
|
2023-09-27 15:38:33 -04:00
|
|
|
impl<'r, 's> Iterator for CodeIter<'r, 's> {
|
|
|
|
type Item = AstNode<'r, 's>;
|
2023-09-27 15:28:43 -04:00
|
|
|
|
2023-09-27 15:38:33 -04:00
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'r, 's> IntoIterator for &'r Code<'s> {
|
|
|
|
type Item = AstNode<'r, 's>;
|
2023-09-27 15:28:43 -04:00
|
|
|
|
2023-09-27 15:38:33 -04:00
|
|
|
type IntoIter = CodeIter<'r, 's>;
|
2023-09-27 15:28:43 -04:00
|
|
|
|
2023-09-27 15:38:33 -04:00
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
CodeIter {
|
|
|
|
phantom: PhantomData,
|
2023-09-27 15:28:43 -04:00
|
|
|
}
|
2023-09-27 15:38:33 -04:00
|
|
|
}
|
2023-09-27 15:28:43 -04:00
|
|
|
}
|