use super::Document; use super::Element; use super::Heading; use super::Object; use super::PlainListItem; use super::Section; use super::TableCell; use super::TableRow; use crate::parser::DocumentElement; pub enum Token<'r, 's> { Document(&'r Document<'s>), Heading(&'r Heading<'s>), Section(&'r Section<'s>), Object(&'r Object<'s>), Element(&'r Element<'s>), PlainListItem(&'r PlainListItem<'s>), TableRow(&'r TableRow<'s>), TableCell(&'r TableCell<'s>), } impl<'r, 's> Token<'r, 's> { pub fn iter_tokens(&self) -> Box> + '_> { match self { Token::Document(document) => Box::new( document .zeroth_section .iter() .map(Token::Section) .chain(document.children.iter().map(Token::Heading)), ), Token::Heading(heading) => Box::new(heading.title.iter().map(Token::Object).chain( heading.children.iter().map(|de| match de { DocumentElement::Heading(ref obj) => Token::Heading(obj), DocumentElement::Section(ref obj) => Token::Section(obj), }), )), Token::Section(section) => Box::new(section.children.iter().map(Token::Element)), Token::Object(obj) => match obj { Object::Bold(_) => todo!(), Object::Italic(_) => todo!(), Object::Underline(_) => todo!(), Object::StrikeThrough(_) => todo!(), Object::Code(_) => todo!(), Object::Verbatim(_) => todo!(), Object::PlainText(_) => todo!(), Object::RegularLink(_) => todo!(), Object::RadioLink(_) => todo!(), Object::RadioTarget(_) => todo!(), Object::PlainLink(_) => todo!(), Object::AngleLink(_) => todo!(), Object::OrgMacro(_) => todo!(), }, Token::Element(elem) => match elem { Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)), Element::PlainList(inner) => { Box::new(inner.children.iter().map(Token::PlainListItem)) } Element::GreaterBlock(inner) => Box::new(inner.children.iter().map(Token::Element)), Element::DynamicBlock(inner) => Box::new(inner.children.iter().map(Token::Element)), Element::FootnoteDefinition(inner) => { Box::new(inner.children.iter().map(Token::Element)) } Element::Comment(_) => Box::new(std::iter::empty()), Element::Drawer(inner) => Box::new(inner.children.iter().map(Token::Element)), Element::PropertyDrawer(_) => Box::new(std::iter::empty()), Element::Table(inner) => Box::new(inner.children.iter().map(Token::TableRow)), Element::VerseBlock(inner) => Box::new(inner.children.iter().map(Token::Object)), Element::CommentBlock(_) => Box::new(std::iter::empty()), Element::ExampleBlock(_) => Box::new(std::iter::empty()), Element::ExportBlock(_) => Box::new(std::iter::empty()), Element::SrcBlock(_) => Box::new(std::iter::empty()), Element::Clock(_) => Box::new(std::iter::empty()), Element::DiarySexp(_) => Box::new(std::iter::empty()), Element::Planning(_) => Box::new(std::iter::empty()), Element::FixedWidthArea(_) => Box::new(std::iter::empty()), Element::HorizontalRule(_) => Box::new(std::iter::empty()), Element::Keyword(_) => Box::new(std::iter::empty()), Element::LatexEnvironment(_) => Box::new(std::iter::empty()), }, Token::PlainListItem(elem) => Box::new(elem.children.iter().map(Token::Element)), Token::TableRow(elem) => Box::new(elem.children.iter().map(Token::TableCell)), Token::TableCell(elem) => Box::new(elem.children.iter().map(Token::Object)), } } }