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