2023-10-05 16:27:36 -04:00
|
|
|
use super::babel_call::babel_call;
|
2023-04-21 19:02:16 -04:00
|
|
|
use super::clock::clock;
|
2023-04-21 16:10:56 -04:00
|
|
|
use super::comment::comment;
|
2023-09-11 12:28:15 -04:00
|
|
|
use super::comment::detect_comment;
|
|
|
|
use super::diary_sexp::detect_diary_sexp;
|
2023-04-21 20:22:31 -04:00
|
|
|
use super::diary_sexp::diary_sexp;
|
2023-04-21 16:10:56 -04:00
|
|
|
use super::drawer::drawer;
|
|
|
|
use super::dynamic_block::dynamic_block;
|
2023-09-11 12:28:15 -04:00
|
|
|
use super::fixed_width_area::detect_fixed_width_area;
|
2023-04-21 22:04:22 -04:00
|
|
|
use super::fixed_width_area::fixed_width_area;
|
2023-09-11 12:28:15 -04:00
|
|
|
use super::footnote_definition::detect_footnote_definition;
|
2023-04-21 16:10:56 -04:00
|
|
|
use super::footnote_definition::footnote_definition;
|
|
|
|
use super::greater_block::greater_block;
|
2023-04-21 22:23:59 -04:00
|
|
|
use super::horizontal_rule::horizontal_rule;
|
2023-04-21 22:33:10 -04:00
|
|
|
use super::keyword::keyword;
|
2023-04-22 16:56:36 -04:00
|
|
|
use super::latex_environment::latex_environment;
|
2023-04-21 17:40:49 -04:00
|
|
|
use super::lesser_block::comment_block;
|
|
|
|
use super::lesser_block::example_block;
|
|
|
|
use super::lesser_block::export_block;
|
|
|
|
use super::lesser_block::src_block;
|
|
|
|
use super::lesser_block::verse_block;
|
2023-08-23 00:30:26 -04:00
|
|
|
use super::org_source::OrgSource;
|
2023-04-21 16:10:56 -04:00
|
|
|
use super::paragraph::paragraph;
|
2023-08-25 00:48:34 -04:00
|
|
|
use super::plain_list::detect_plain_list;
|
2023-04-21 16:10:56 -04:00
|
|
|
use super::plain_list::plain_list;
|
2023-09-11 12:28:15 -04:00
|
|
|
use super::table::detect_table;
|
2023-09-03 12:23:18 -04:00
|
|
|
use crate::context::RefContext;
|
2023-08-25 00:48:34 -04:00
|
|
|
use crate::error::CustomError;
|
2023-04-21 18:36:01 -04:00
|
|
|
use crate::error::Res;
|
2023-10-17 13:32:01 -04:00
|
|
|
#[cfg(feature = "event_count")]
|
|
|
|
use crate::event_count::record_event;
|
|
|
|
#[cfg(feature = "event_count")]
|
|
|
|
use crate::event_count::EventType;
|
2023-10-17 11:10:18 -04:00
|
|
|
use crate::parser::affiliated_keyword::affiliated_keywords;
|
2023-10-18 11:57:39 -04:00
|
|
|
use crate::parser::bullshitium::bullshitium;
|
|
|
|
use crate::parser::bullshitium::detect_bullshitium;
|
2023-10-12 16:06:59 -04:00
|
|
|
use crate::parser::macros::ak_element;
|
2023-10-12 16:52:49 -04:00
|
|
|
use crate::parser::macros::element;
|
2023-04-21 16:10:56 -04:00
|
|
|
use crate::parser::table::org_mode_table;
|
2023-09-03 12:23:18 -04:00
|
|
|
use crate::types::Element;
|
2023-04-21 16:10:56 -04:00
|
|
|
|
2023-09-11 13:13:28 -04:00
|
|
|
pub(crate) const fn element(
|
2023-04-22 00:55:31 -04:00
|
|
|
can_be_paragraph: bool,
|
2023-09-03 15:44:18 -04:00
|
|
|
) -> impl for<'b, 'g, 'r, 's> Fn(
|
|
|
|
RefContext<'b, 'g, 'r, 's>,
|
|
|
|
OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Element<'s>> {
|
2023-09-03 12:23:18 -04:00
|
|
|
move |context, input: OrgSource<'_>| _element(context, input, can_be_paragraph)
|
2023-04-22 19:15:29 -04:00
|
|
|
}
|
|
|
|
|
2023-10-09 19:52:32 -04:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-03 15:44:18 -04:00
|
|
|
fn _element<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 00:30:26 -04:00
|
|
|
input: OrgSource<'s>,
|
2023-04-22 19:15:29 -04:00
|
|
|
can_be_paragraph: bool,
|
2023-08-23 00:30:26 -04:00
|
|
|
) -> Res<OrgSource<'s>, Element<'s>> {
|
2023-10-17 13:32:01 -04:00
|
|
|
#[cfg(feature = "event_count")]
|
|
|
|
record_event(EventType::ElementStart, input);
|
2023-10-18 18:28:24 -04:00
|
|
|
let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?;
|
2023-10-12 15:47:06 -04:00
|
|
|
|
2023-10-12 16:06:59 -04:00
|
|
|
let mut affiliated_keywords = affiliated_keywords.into_iter();
|
|
|
|
|
|
|
|
ak_element!(
|
2023-10-12 16:09:35 -04:00
|
|
|
plain_list,
|
2023-10-12 16:06:59 -04:00
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::PlainList
|
|
|
|
);
|
|
|
|
|
2023-10-12 16:27:57 -04:00
|
|
|
ak_element!(
|
|
|
|
greater_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input
|
|
|
|
);
|
|
|
|
|
2023-10-12 16:46:15 -04:00
|
|
|
ak_element!(
|
|
|
|
dynamic_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::DynamicBlock
|
|
|
|
);
|
|
|
|
|
2023-10-12 16:48:50 -04:00
|
|
|
ak_element!(
|
|
|
|
footnote_definition,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::FootnoteDefinition
|
|
|
|
);
|
|
|
|
|
2023-10-12 16:52:49 -04:00
|
|
|
element!(comment, context, input, Element::Comment);
|
|
|
|
|
2023-10-12 17:12:55 -04:00
|
|
|
ak_element!(
|
|
|
|
drawer,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::Drawer
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
org_mode_table,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::Table
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
verse_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::VerseBlock
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
comment_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::CommentBlock
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
example_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::ExampleBlock
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
export_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::ExportBlock
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
src_block,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::SrcBlock
|
|
|
|
);
|
|
|
|
|
|
|
|
element!(clock, context, input, Element::Clock);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
diary_sexp,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::DiarySexp
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
fixed_width_area,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::FixedWidthArea
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
horizontal_rule,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::HorizontalRule
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
latex_environment,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::LatexEnvironment
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
babel_call,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::BabelCall
|
|
|
|
);
|
|
|
|
|
2023-10-12 17:23:54 -04:00
|
|
|
// Keyword with affiliated keywords
|
2023-10-12 17:12:55 -04:00
|
|
|
ak_element!(
|
|
|
|
keyword,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::Keyword
|
|
|
|
);
|
2023-10-04 22:47:13 -04:00
|
|
|
|
2023-10-12 16:46:15 -04:00
|
|
|
if can_be_paragraph {
|
|
|
|
// Paragraph with affiliated keyword
|
|
|
|
ak_element!(
|
|
|
|
paragraph,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::Paragraph
|
|
|
|
);
|
2023-10-12 17:32:29 -04:00
|
|
|
}
|
2023-10-04 22:47:13 -04:00
|
|
|
|
2023-10-12 17:32:29 -04:00
|
|
|
// Keyword without affiliated keywords
|
|
|
|
ak_element!(
|
|
|
|
keyword,
|
|
|
|
std::iter::empty(),
|
|
|
|
input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::Keyword
|
|
|
|
);
|
|
|
|
|
|
|
|
if can_be_paragraph {
|
2023-10-18 11:57:39 -04:00
|
|
|
// Fake paragraphs
|
|
|
|
element!(bullshitium, context, input, Element::Paragraph);
|
|
|
|
|
2023-10-12 16:46:15 -04:00
|
|
|
// Paragraph without affiliated keyword
|
|
|
|
ak_element!(
|
|
|
|
paragraph,
|
|
|
|
std::iter::empty(),
|
|
|
|
input,
|
|
|
|
context,
|
|
|
|
input,
|
|
|
|
Element::Paragraph
|
|
|
|
);
|
|
|
|
}
|
2023-10-04 22:47:13 -04:00
|
|
|
|
2023-10-17 10:09:37 -04:00
|
|
|
Err(nom::Err::Error(CustomError::Static("No element.")))
|
2023-04-21 16:10:56 -04:00
|
|
|
}
|
2023-08-25 00:48:34 -04:00
|
|
|
|
2023-09-11 13:13:28 -04:00
|
|
|
pub(crate) const fn detect_element(
|
2023-08-25 00:48:34 -04:00
|
|
|
can_be_paragraph: bool,
|
2023-09-03 15:44:18 -04:00
|
|
|
) -> impl for<'b, 'g, 'r, 's> Fn(RefContext<'b, 'g, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, ()>
|
|
|
|
{
|
2023-09-03 12:23:18 -04:00
|
|
|
move |context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph)
|
2023-08-25 00:48:34 -04:00
|
|
|
}
|
|
|
|
|
2023-10-09 19:52:32 -04:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-03 15:44:18 -04:00
|
|
|
fn _detect_element<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-25 00:48:34 -04:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
can_be_paragraph: bool,
|
|
|
|
) -> Res<OrgSource<'s>, ()> {
|
2023-10-18 18:28:24 -04:00
|
|
|
let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?;
|
2023-10-16 14:55:40 -04:00
|
|
|
|
|
|
|
let mut affiliated_keywords = affiliated_keywords.into_iter();
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
detect_plain_list,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
detect_footnote_definition,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
detect_diary_sexp,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input
|
|
|
|
);
|
|
|
|
|
2023-10-16 18:29:21 -04:00
|
|
|
element!(detect_comment, input);
|
2023-10-16 14:55:40 -04:00
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
detect_fixed_width_area,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input
|
|
|
|
);
|
|
|
|
|
|
|
|
ak_element!(
|
|
|
|
detect_table,
|
|
|
|
&mut affiliated_keywords,
|
|
|
|
post_affiliated_keywords_input,
|
|
|
|
context,
|
|
|
|
input
|
|
|
|
);
|
|
|
|
|
2023-10-18 11:57:39 -04:00
|
|
|
// Fake paragraphs
|
|
|
|
if !can_be_paragraph {
|
|
|
|
element!(detect_bullshitium, context, input);
|
|
|
|
}
|
|
|
|
|
2023-08-25 00:48:34 -04:00
|
|
|
if _element(context, input, can_be_paragraph).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
2023-10-16 14:55:40 -04:00
|
|
|
|
2023-10-17 10:09:37 -04:00
|
|
|
Err(nom::Err::Error(CustomError::Static("No element detected.")))
|
2023-08-25 00:48:34 -04:00
|
|
|
}
|