diff --git a/org_mode_samples/property_drawer/empty.org b/org_mode_samples/property_drawer/empty.org new file mode 100644 index 0000000..d86fd5b --- /dev/null +++ b/org_mode_samples/property_drawer/empty.org @@ -0,0 +1,3 @@ +:PROPERTIES: + +:END: diff --git a/src/parser/element.rs b/src/parser/element.rs index e3a2c4e..2938884 100644 --- a/src/parser/element.rs +++ b/src/parser/element.rs @@ -13,6 +13,7 @@ use super::lesser_element::Comment; use super::lesser_element::Paragraph; use super::paragraph::paragraph; use super::plain_list::plain_list; +use super::property_drawer::property_drawer; use super::source::Source; use super::Context; use super::Drawer; @@ -122,6 +123,7 @@ pub fn non_paragraph_element<'r, 's>( let dynamic_block_matcher = parser_with_context!(dynamic_block)(context); let footnote_definition_matcher = parser_with_context!(footnote_definition)(context); let comment_matcher = parser_with_context!(comment)(context); + let property_drawer_matcher = parser_with_context!(property_drawer)(context); let drawer_matcher = parser_with_context!(drawer)(context); alt(( map(plain_list_matcher, Element::PlainList), @@ -129,6 +131,7 @@ pub fn non_paragraph_element<'r, 's>( map(dynamic_block_matcher, Element::DynamicBlock), map(footnote_definition_matcher, Element::FootnoteDefinition), map(comment_matcher, Element::Comment), + map(property_drawer_matcher, Element::PropertyDrawer), map(drawer_matcher, Element::Drawer), ))(input) } diff --git a/src/parser/greater_element.rs b/src/parser/greater_element.rs index c40d85c..172056a 100644 --- a/src/parser/greater_element.rs +++ b/src/parser/greater_element.rs @@ -47,6 +47,13 @@ pub struct Drawer<'s> { #[derive(Debug)] pub struct PropertyDrawer<'s> { pub source: &'s str, - pub name: &'s str, + pub children: Vec>, +} + +#[derive(Debug)] +pub struct NodeProperty<'s> { + pub source: &'s str, + pub indentation: usize, + pub bullet: &'s str, pub children: Vec>, } diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index c17eabd..a106e4b 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -5,6 +5,7 @@ use nom::character::complete::line_ending; use nom::character::complete::space0; use nom::combinator::eof; use nom::combinator::recognize; +use nom::multi::many_till; use nom::sequence::tuple; use super::Context; @@ -12,11 +13,15 @@ use crate::parser::error::CustomError; use crate::parser::error::MyError; use crate::parser::error::Res; use crate::parser::exiting::ExitClass; +use crate::parser::greater_element::NodeProperty; use crate::parser::greater_element::PropertyDrawer; use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_with_context::parser_with_context; +use crate::parser::util::exit_matcher_parser; +use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; +use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::parser::util::start_of_line; #[tracing::instrument(ret, level = "debug")] @@ -48,34 +53,17 @@ pub fn property_drawer<'r, 's>( exit_matcher: &property_drawer_end, })); - // let element_matcher = parser_with_context!(element)(&parser_context); - // let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); - // let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) { - // Ok((remaining, (whitespace, (_children, _exit_contents)))) => ( - // remaining, - // vec![Element::Paragraph(Paragraph::of_text(whitespace))], - // ), - // Err(_) => { - // let (remaining, (children, _exit_contents)) = - // many_till(element_matcher, exit_matcher)(remaining)?; - // (remaining, children) - // } - // }; - // let (remaining, _end) = drawer_end(&parser_context, remaining)?; + let element_matcher = parser_with_context!(node_property)(&parser_context); + let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); + let (remaining, (children, _exit_contents)) = + many_till(element_matcher, exit_matcher)(remaining)?; + let (remaining, _end) = property_drawer_end(&parser_context, remaining)?; - // let (remaining, _trailing_ws) = - // maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; - // let source = get_consumed(input, remaining); + let (remaining, _trailing_ws) = + maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; + let source = get_consumed(input, remaining); - // Ok(( - // remaining, - // Drawer { - // source, - // name: drawer_name, - // children, - // }, - // )) - todo!() + Ok((remaining, PropertyDrawer { source, children })) } #[tracing::instrument(ret, level = "debug")] @@ -88,3 +76,11 @@ fn property_drawer_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res< alt((line_ending, eof)), )))(input) } + +#[tracing::instrument(ret, level = "debug")] +pub fn node_property<'r, 's>( + context: Context<'r, 's>, + input: &'s str, +) -> Res<&'s str, NodeProperty<'s>> { + todo!() +}