Separate out the element parsers.

This commit is contained in:
Tom Alexander 2023-04-21 16:10:56 -04:00
parent 54b02f4e74
commit d780981baf
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
10 changed files with 55 additions and 54 deletions

View File

@ -1,5 +1,5 @@
use crate::parser::comment::comment;
use crate::parser::element::element;
use crate::parser::element_parser::element;
use crate::parser::exiting::ExitClass;
use crate::parser::object_parser::standard_set_object;
use crate::parser::parser_context::ContextElement;

View File

@ -11,7 +11,7 @@ use nom::multi::many_till;
use nom::sequence::tuple;
use super::Context;
use crate::parser::element::element;
use crate::parser::element_parser::element;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::error::Res;

View File

@ -1,6 +1,6 @@
use super::error::Res;
use super::Context;
use crate::parser::element::element;
use crate::parser::element_parser::element;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::exiting::ExitClass;

View File

@ -1,9 +1,3 @@
use super::comment::comment;
use super::drawer::drawer;
use super::dynamic_block::dynamic_block;
use super::error::Res;
use super::footnote_definition::footnote_definition;
use super::greater_block::greater_block;
use super::greater_element::DynamicBlock;
use super::greater_element::FootnoteDefinition;
use super::greater_element::GreaterBlock;
@ -14,17 +8,9 @@ use super::greater_element::TableRow;
use super::lesser_element::Comment;
use super::lesser_element::Paragraph;
use super::lesser_element::TableCell;
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 crate::parser::table;
use crate::parser::table::org_mode_table;
use nom::branch::alt;
use nom::combinator::map;
#[derive(Debug)]
pub enum Element<'s> {
@ -126,36 +112,3 @@ impl<'s> Source<'s> for TableCell<'s> {
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);
let paragraph_matcher = parser_with_context!(paragraph)(context);
alt((
non_paragraph_matcher,
map(paragraph_matcher, Element::Paragraph),
))(input)
}
pub fn non_paragraph_element<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Element<'s>> {
let plain_list_matcher = parser_with_context!(plain_list)(context);
let greater_block_matcher = parser_with_context!(greater_block)(context);
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 drawer_matcher = parser_with_context!(drawer)(context);
let table_matcher = parser_with_context!(org_mode_table)(context);
alt((
map(plain_list_matcher, Element::PlainList),
map(greater_block_matcher, Element::GreaterBlock),
map(dynamic_block_matcher, Element::DynamicBlock),
map(footnote_definition_matcher, Element::FootnoteDefinition),
map(comment_matcher, Element::Comment),
map(drawer_matcher, Element::Drawer),
map(table_matcher, Element::Table),
))(input)
}

View File

@ -0,0 +1,47 @@
use super::comment::comment;
use super::drawer::drawer;
use super::dynamic_block::dynamic_block;
use super::element::Element;
use super::error::Res;
use super::footnote_definition::footnote_definition;
use super::greater_block::greater_block;
use super::paragraph::paragraph;
use super::plain_list::plain_list;
use super::Context;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::table::org_mode_table;
use nom::branch::alt;
use nom::combinator::map;
#[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);
let paragraph_matcher = parser_with_context!(paragraph)(context);
alt((
non_paragraph_matcher,
map(paragraph_matcher, Element::Paragraph),
))(input)
}
pub fn non_paragraph_element<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Element<'s>> {
let plain_list_matcher = parser_with_context!(plain_list)(context);
let greater_block_matcher = parser_with_context!(greater_block)(context);
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 drawer_matcher = parser_with_context!(drawer)(context);
let table_matcher = parser_with_context!(org_mode_table)(context);
alt((
map(plain_list_matcher, Element::PlainList),
map(greater_block_matcher, Element::GreaterBlock),
map(dynamic_block_matcher, Element::DynamicBlock),
map(footnote_definition_matcher, Element::FootnoteDefinition),
map(comment_matcher, Element::Comment),
map(drawer_matcher, Element::Drawer),
map(table_matcher, Element::Table),
))(input)
}

View File

@ -1,7 +1,7 @@
use super::error::Res;
use super::util::WORD_CONSTITUENT_CHARACTERS;
use super::Context;
use crate::parser::element::element;
use crate::parser::element_parser::element;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::exiting::ExitClass;

View File

@ -1,6 +1,6 @@
use super::error::Res;
use super::Context;
use crate::parser::element::element;
use crate::parser::element_parser::element;
use crate::parser::error::CustomError;
use crate::parser::error::MyError;
use crate::parser::exiting::ExitClass;

View File

@ -3,6 +3,7 @@ mod document;
mod drawer;
mod dynamic_block;
mod element;
mod element_parser;
mod error;
mod exiting;
mod footnote_definition;

View File

@ -15,7 +15,7 @@ use crate::parser::util::exit_matcher_parser;
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::parser::util::start_of_line;
use super::element::non_paragraph_element;
use super::element_parser::non_paragraph_element;
use super::error::Res;
use super::lesser_element::Paragraph;
use super::util::blank_line;

View File

@ -7,7 +7,7 @@ use super::parser_with_context::parser_with_context;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::non_whitespace_character;
use super::Context;
use crate::parser::element::element;
use crate::parser::element_parser::element;
use crate::parser::exiting::ExitClass;
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ExitMatcherNode;