From 1f7c24545b812396e1dd61843ba3924432a275d4 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 15 Apr 2023 17:36:07 -0400 Subject: [PATCH] Initial structure for drawer. --- src/compare/diff.rs | 1 + src/parser/drawer.rs | 8 ++++++++ src/parser/element.rs | 12 ++++++++++++ src/parser/greater_element.rs | 7 +++++++ src/parser/mod.rs | 2 ++ 5 files changed, 30 insertions(+) create mode 100644 src/parser/drawer.rs diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 89f600a..9c32da9 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -218,6 +218,7 @@ fn compare_element<'s>( Element::GreaterBlock(obj) => compare_greater_block(source, emacs, obj), Element::FootnoteDefinition(obj) => compare_footnote_definition(source, emacs, obj), Element::Comment(obj) => compare_comment(source, emacs, obj), + Element::Drawer(obj) => todo!(), } } diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs new file mode 100644 index 0000000..1443521 --- /dev/null +++ b/src/parser/drawer.rs @@ -0,0 +1,8 @@ +use super::Context; +use crate::parser::error::Res; +use crate::parser::Drawer; + +#[tracing::instrument(ret, level = "debug")] +pub fn drawer<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Drawer<'s>> { + todo!() +} diff --git a/src/parser/element.rs b/src/parser/element.rs index cb7cf19..189d62d 100644 --- a/src/parser/element.rs +++ b/src/parser/element.rs @@ -1,4 +1,5 @@ use super::comment::comment; +use super::drawer::drawer; use super::error::Res; use super::footnote_definition::footnote_definition; use super::greater_block::greater_block; @@ -11,6 +12,7 @@ use super::paragraph::paragraph; use super::plain_list::plain_list; use super::source::Source; use super::Context; +use super::Drawer; use super::PlainListItem; use crate::parser::parser_with_context::parser_with_context; use nom::branch::alt; @@ -23,6 +25,7 @@ pub enum Element<'s> { GreaterBlock(GreaterBlock<'s>), FootnoteDefinition(FootnoteDefinition<'s>), Comment(Comment<'s>), + Drawer(Drawer<'s>), } impl<'s> Source<'s> for Element<'s> { @@ -33,6 +36,7 @@ impl<'s> Source<'s> for Element<'s> { Element::GreaterBlock(obj) => obj.source, Element::FootnoteDefinition(obj) => obj.source, Element::Comment(obj) => obj.source, + Element::Drawer(obj) => obj.source, } } } @@ -73,6 +77,12 @@ impl<'s> Source<'s> for Comment<'s> { } } +impl<'s> Source<'s> for Drawer<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + #[tracing::instrument(ret, level = "debug")] pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> { let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context); @@ -92,10 +102,12 @@ pub fn non_paragraph_element<'r, 's>( let greater_block_matcher = parser_with_context!(greater_block)(context); let footnote_definition_matcher = parser_with_context!(footnote_definition)(context); let comment_matcher = parser_with_context!(comment)(context); + let drawer_matcher = parser_with_context!(drawer)(context); alt(( map(plain_list_matcher, Element::PlainList), map(greater_block_matcher, Element::GreaterBlock), map(footnote_definition_matcher, Element::FootnoteDefinition), map(comment_matcher, Element::Comment), + map(drawer_matcher, Element::Drawer), ))(input) } diff --git a/src/parser/greater_element.rs b/src/parser/greater_element.rs index 119d03e..2d1f92a 100644 --- a/src/parser/greater_element.rs +++ b/src/parser/greater_element.rs @@ -28,3 +28,10 @@ pub struct FootnoteDefinition<'s> { pub label: &'s str, pub children: Vec>, } + +#[derive(Debug)] +pub struct Drawer<'s> { + pub source: &'s str, + pub label: &'s str, + pub children: Vec>, +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index c6dae3e..7b32ed3 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,5 +1,6 @@ mod comment; mod document; +mod drawer; mod element; mod error; mod footnote_definition; @@ -21,6 +22,7 @@ pub use document::DocumentElement; pub use document::Heading; pub use document::Section; pub use element::Element; +pub use greater_element::Drawer; pub use greater_element::FootnoteDefinition; pub use greater_element::GreaterBlock; pub use greater_element::PlainList;