Port dynamic block.
This commit is contained in:
parent
d1223dcdb7
commit
9ccdcaac24
@ -18,7 +18,6 @@ use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||
use super::keyword::affiliated_keyword;
|
||||
use super::org_source::OrgSource;
|
||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::context::parser_with_context;
|
||||
@ -37,6 +36,7 @@ use crate::parser::util::immediate_in_section;
|
||||
use crate::parser::util::start_of_line;
|
||||
use crate::types::DynamicBlock;
|
||||
use crate::types::Element;
|
||||
use crate::types::Keyword;
|
||||
use crate::types::Paragraph;
|
||||
use crate::types::SetSource;
|
||||
|
||||
@ -44,16 +44,20 @@ use crate::types::SetSource;
|
||||
feature = "tracing",
|
||||
tracing::instrument(ret, level = "debug", skip(context))
|
||||
)]
|
||||
pub(crate) fn dynamic_block<'b, 'g, 'r, 's>(
|
||||
pub(crate) fn dynamic_block<'b, 'g, 'r, 's, AK>(
|
||||
affiliated_keywords: AK,
|
||||
remaining: OrgSource<'s>,
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, DynamicBlock<'s>> {
|
||||
) -> Res<OrgSource<'s>, DynamicBlock<'s>>
|
||||
where
|
||||
AK: IntoIterator<Item = Keyword<'s>>,
|
||||
{
|
||||
if immediate_in_section(context, "dynamic block") {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Cannot nest objects of the same element".into(),
|
||||
))));
|
||||
}
|
||||
let (remaining, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
|
||||
start_of_line(remaining)?;
|
||||
let (remaining, _leading_whitespace) = space0(remaining)?;
|
||||
|
@ -1,9 +1,7 @@
|
||||
use nom::branch::alt;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::multi::many0;
|
||||
use nom::sequence::tuple;
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::span;
|
||||
|
||||
@ -82,7 +80,15 @@ fn _element<'b, 'g, 'r, 's>(
|
||||
input
|
||||
);
|
||||
|
||||
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
|
||||
ak_element!(
|
||||
dynamic_block,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input,
|
||||
Element::DynamicBlock
|
||||
);
|
||||
|
||||
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);
|
||||
@ -100,14 +106,13 @@ fn _element<'b, 'g, 'r, 's>(
|
||||
let babel_keyword_matcher = parser_with_context!(babel_call)(context);
|
||||
let latex_environment_matcher = parser_with_context!(latex_environment)(context);
|
||||
|
||||
let (mut remaining, mut maybe_element) = {
|
||||
let (remaining, maybe_element) = {
|
||||
#[cfg(feature = "tracing")]
|
||||
let span = span!(tracing::Level::DEBUG, "Main element block");
|
||||
#[cfg(feature = "tracing")]
|
||||
let _enter = span.enter();
|
||||
|
||||
opt(alt((
|
||||
map(dynamic_block_matcher, Element::DynamicBlock),
|
||||
map(footnote_definition_matcher, Element::FootnoteDefinition),
|
||||
map(comment_matcher, Element::Comment),
|
||||
map(drawer_matcher, Element::Drawer),
|
||||
@ -127,25 +132,27 @@ fn _element<'b, 'g, 'r, 's>(
|
||||
)))(input)?
|
||||
};
|
||||
|
||||
// Paragraph with affiliated keyword
|
||||
ak_element!(
|
||||
paragraph,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input,
|
||||
Element::Paragraph
|
||||
);
|
||||
if can_be_paragraph {
|
||||
// Paragraph with affiliated keyword
|
||||
ak_element!(
|
||||
paragraph,
|
||||
&mut affiliated_keywords,
|
||||
post_affiliated_keywords_input,
|
||||
context,
|
||||
input,
|
||||
Element::Paragraph
|
||||
);
|
||||
|
||||
// Paragraph without affiliated keyword
|
||||
ak_element!(
|
||||
paragraph,
|
||||
std::iter::empty(),
|
||||
input,
|
||||
context,
|
||||
input,
|
||||
Element::Paragraph
|
||||
);
|
||||
// Paragraph without affiliated keyword
|
||||
ak_element!(
|
||||
paragraph,
|
||||
std::iter::empty(),
|
||||
input,
|
||||
context,
|
||||
input,
|
||||
Element::Paragraph
|
||||
);
|
||||
}
|
||||
|
||||
if maybe_element.is_none() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
|
@ -2,14 +2,12 @@ use nom::branch::alt;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many1;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||
use super::element_parser::detect_element;
|
||||
use super::keyword::affiliated_keyword;
|
||||
use super::org_source::OrgSource;
|
||||
use super::util::blank_line;
|
||||
use super::util::get_consumed;
|
||||
|
Loading…
x
Reference in New Issue
Block a user