Finish property drawer parser but node property is unstarted.

This commit is contained in:
Tom Alexander 2023-04-19 17:15:00 -04:00
parent 2137b08e42
commit f7f29e7a56
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 36 additions and 27 deletions

View File

@ -0,0 +1,3 @@
:PROPERTIES:
:END:

View File

@ -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)
}

View File

@ -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<NodeProperty<'s>>,
}
#[derive(Debug)]
pub struct NodeProperty<'s> {
pub source: &'s str,
pub indentation: usize,
pub bullet: &'s str,
pub children: Vec<Element<'s>>,
}

View File

@ -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!()
}