Compare commits

..

No commits in common. "9f1671658d057ec04d650e0c99b9b45dffbae3ab" and "26f1eae9a1f7585b37179bb0a07c4b8f5d06d3b6" have entirely different histories.

8 changed files with 209 additions and 226 deletions

View File

@ -1,12 +1,15 @@
use nom::bytes::complete::is_not; use nom::bytes::complete::is_not;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::multi::many0;
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 super::util::org_line_ending; use super::util::org_line_ending;
use crate::context::parser_with_context;
use crate::context::RefContext; use crate::context::RefContext;
use crate::error::Res; use crate::error::Res;
use crate::parser::util::get_consumed; use crate::parser::util::get_consumed;
@ -47,19 +50,12 @@ where
)) ))
} }
#[cfg_attr( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
feature = "tracing", pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's>(
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) context: RefContext<'b, 'g, 'r, 's>,
)]
pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's, AK>(
_affiliated_keywords: AK,
remaining: OrgSource<'s>,
_context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> ) -> Res<OrgSource<'s>, ()> {
where let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?;
AK: IntoIterator<Item = Keyword<'s>>, tuple((start_of_line, tag("%%(")))(input)?;
{
tuple((start_of_line, tag("%%(")))(remaining)?;
Ok((input, ())) Ok((input, ()))
} }

View File

@ -1,4 +1,4 @@
use nom::branch::alt;
use nom::multi::many0; use nom::multi::many0;
use super::babel_call::babel_call; use super::babel_call::babel_call;
@ -273,60 +273,23 @@ fn _detect_element<'b, 'g, 'r, 's>(
input: OrgSource<'s>, input: OrgSource<'s>,
can_be_paragraph: bool, can_be_paragraph: bool,
) -> Res<OrgSource<'s>, ()> { ) -> Res<OrgSource<'s>, ()> {
let (post_affiliated_keywords_input, affiliated_keywords) = // TODO: unify parsing of affiliated keywords like we did for the element parser.
many0(parser_with_context!(affiliated_keyword)(context))(input)?; if alt((
parser_with_context!(detect_plain_list)(context),
let mut affiliated_keywords = affiliated_keywords.into_iter(); parser_with_context!(detect_footnote_definition)(context),
parser_with_context!(detect_diary_sexp)(context),
ak_element!( detect_comment,
detect_plain_list, parser_with_context!(detect_fixed_width_area)(context),
&mut affiliated_keywords, parser_with_context!(detect_table)(context),
post_affiliated_keywords_input, ))(input)
context, .is_ok()
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
);
if let Ok((_, _)) = detect_comment(input) {
return Ok((input, ())); return Ok((input, ()));
} }
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
);
if _element(context, input, can_be_paragraph).is_ok() { if _element(context, input, can_be_paragraph).is_ok() {
return Ok((input, ())); return Ok((input, ()));
} }
return Err(nom::Err::Error(CustomError::MyError(MyError(
Err(nom::Err::Error(CustomError::MyError(MyError(
"No element detected.".into(), "No element detected.".into(),
)))) ))));
} }

View File

@ -10,6 +10,7 @@ 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 super::util::org_line_ending; use super::util::org_line_ending;
@ -88,24 +89,17 @@ fn fixed_width_area_line<'b, 'g, 'r, 's>(
Ok((remaining, value)) Ok((remaining, value))
} }
#[cfg_attr( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
feature = "tracing", pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's>(
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) context: RefContext<'b, 'g, 'r, 's>,
)]
pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's, AK>(
_affiliated_keywords: AK,
remaining: OrgSource<'s>,
_context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> ) -> Res<OrgSource<'s>, ()> {
where let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?;
AK: IntoIterator<Item = Keyword<'s>>,
{
tuple(( tuple((
start_of_line, start_of_line,
space0, space0,
tag(":"), tag(":"),
alt((tag(" "), org_line_ending)), alt((tag(" "), org_line_ending)),
))(remaining)?; ))(input)?;
Ok((input, ())) Ok((input, ()))
} }

View File

@ -12,6 +12,7 @@ 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::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::include_input; use super::util::include_input;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
@ -124,7 +125,7 @@ fn footnote_definition_end<'b, 'g, 'r, 's>(
let (remaining, source) = alt(( let (remaining, source) = alt((
recognize(tuple(( recognize(tuple((
parser_with_context!(maybe_consume_trailing_whitespace)(context), parser_with_context!(maybe_consume_trailing_whitespace)(context),
|i| detect_footnote_definition(std::iter::empty(), i, context, i), parser_with_context!(detect_footnote_definition)(context),
))), ))),
recognize(tuple(( recognize(tuple((
start_of_line, start_of_line,
@ -137,20 +138,13 @@ fn footnote_definition_end<'b, 'g, 'r, 's>(
Ok((remaining, source)) Ok((remaining, source))
} }
#[cfg_attr( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
feature = "tracing", pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's>(
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) context: RefContext<'b, 'g, 'r, 's>,
)]
pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's, AK>(
_affiliated_keywords: AK,
remaining: OrgSource<'s>,
_context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> ) -> Res<OrgSource<'s>, ()> {
where let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?;
AK: IntoIterator<Item = Keyword<'s>>, tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(input)?;
{
tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(remaining)?;
Ok((input, ())) Ok((input, ()))
} }

View File

@ -1,6 +1,6 @@
/// Parse an element that has affiliated keywords. /// Parse an element that has affiliated keywords.
macro_rules! ak_element { macro_rules! ak_element {
($parser:expr, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr, $wrapper: expr) => { ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr, $wrapper: expr) => {
if let Ok((remaining, ele)) = $parser( if let Ok((remaining, ele)) = $parser(
$affiliated_keywords, $affiliated_keywords,
$post_affiliated_keywords_input, $post_affiliated_keywords_input,
@ -10,7 +10,7 @@ macro_rules! ak_element {
return Ok((remaining, $wrapper(ele))); return Ok((remaining, $wrapper(ele)));
} }
}; };
($parser:expr, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr) => { ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr) => {
if let Ok((remaining, ele)) = $parser( if let Ok((remaining, ele)) = $parser(
$affiliated_keywords, $affiliated_keywords,
$post_affiliated_keywords_input, $post_affiliated_keywords_input,
@ -25,12 +25,12 @@ macro_rules! ak_element {
pub(crate) use ak_element; pub(crate) use ak_element;
macro_rules! element { macro_rules! element {
($parser:expr, $context: expr, $input: expr, $wrapper: expr) => { ($parser:ident, $context: expr, $input: expr, $wrapper: expr) => {
if let Ok((remaining, ele)) = $parser($context, $input) { if let Ok((remaining, ele)) = $parser($context, $input) {
return Ok((remaining, $wrapper(ele))); return Ok((remaining, $wrapper(ele)));
} }
}; };
($parser:expr, $context: expr, $input: expr) => { ($parser:ident, $context: expr, $input: expr) => {
if let Ok((remaining, ele)) = $parser($context, $input) { if let Ok((remaining, ele)) = $parser($context, $input) {
return Ok((remaining, ele)); return Ok((remaining, ele));
} }

View File

@ -1,7 +1,11 @@
use nom::branch::alt;
use nom::combinator::map;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::plain_text::plain_text; use super::plain_text::plain_text;
use super::regular_link::regular_link; use super::regular_link::regular_link;
use super::subscript_and_superscript::detect_subscript_or_superscript; use super::subscript_and_superscript::detect_subscript_or_superscript;
use crate::context::parser_with_context;
use crate::context::RefContext; use crate::context::RefContext;
use crate::error::CustomError; use crate::error::CustomError;
use crate::error::MyError; use crate::error::MyError;
@ -15,7 +19,6 @@ use crate::parser::inline_babel_call::inline_babel_call;
use crate::parser::inline_source_block::inline_source_block; use crate::parser::inline_source_block::inline_source_block;
use crate::parser::latex_fragment::latex_fragment; use crate::parser::latex_fragment::latex_fragment;
use crate::parser::line_break::line_break; use crate::parser::line_break::line_break;
use crate::parser::macros::element;
use crate::parser::org_macro::org_macro; use crate::parser::org_macro::org_macro;
use crate::parser::plain_link::plain_link; use crate::parser::plain_link::plain_link;
use crate::parser::radio_link::radio_link; use crate::parser::radio_link::radio_link;
@ -36,14 +39,14 @@ pub(crate) fn standard_set_object<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
element!(standard_set_object_sans_plain_text, context, input); let (remaining, object) = alt((
element!( parser_with_context!(standard_set_object_sans_plain_text)(context),
plain_text(detect_standard_set_object_sans_plain_text), map(
context, parser_with_context!(plain_text(detect_standard_set_object_sans_plain_text))(context),
input, Object::PlainText,
Object::PlainText ),
); ))(input)?;
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(
@ -54,14 +57,14 @@ pub(crate) fn minimal_set_object<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
element!(minimal_set_object_sans_plain_text, context, input); let (remaining, object) = alt((
element!( parser_with_context!(minimal_set_object_sans_plain_text)(context),
plain_text(detect_minimal_set_object_sans_plain_text), map(
context, parser_with_context!(plain_text(detect_minimal_set_object_sans_plain_text))(context),
input, Object::PlainText,
Object::PlainText ),
); ))(input)?;
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(
@ -72,38 +75,56 @@ fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
element!(timestamp, context, input, Object::Timestamp); let (remaining, object) = alt((
element!(subscript, context, input, Object::Subscript); map(parser_with_context!(timestamp)(context), Object::Timestamp),
element!(superscript, context, input, Object::Superscript); map(parser_with_context!(subscript)(context), Object::Subscript),
element!(statistics_cookie, context, input, Object::StatisticsCookie); map(
element!(target, context, input, Object::Target); parser_with_context!(superscript)(context),
element!(line_break, context, input, Object::LineBreak); Object::Superscript,
element!( ),
inline_source_block, map(
context, parser_with_context!(statistics_cookie)(context),
input, Object::StatisticsCookie,
Object::InlineSourceBlock ),
); map(parser_with_context!(target)(context), Object::Target),
element!(inline_babel_call, context, input, Object::InlineBabelCall); map(parser_with_context!(line_break)(context), Object::LineBreak),
element!(citation, context, input, Object::Citation); map(
element!( parser_with_context!(inline_source_block)(context),
footnote_reference, Object::InlineSourceBlock,
context, ),
input, map(
Object::FootnoteReference parser_with_context!(inline_babel_call)(context),
); Object::InlineBabelCall,
element!(export_snippet, context, input, Object::ExportSnippet); ),
element!(entity, context, input, Object::Entity); map(parser_with_context!(citation)(context), Object::Citation),
element!(latex_fragment, context, input, Object::LatexFragment); map(
element!(radio_link, context, input, Object::RadioLink); parser_with_context!(footnote_reference)(context),
element!(radio_target, context, input, Object::RadioTarget); Object::FootnoteReference,
element!(text_markup, context, input); ),
element!(regular_link, context, input, Object::RegularLink); map(
element!(plain_link, context, input, Object::PlainLink); parser_with_context!(export_snippet)(context),
element!(angle_link, context, input, Object::AngleLink); Object::ExportSnippet,
element!(org_macro, context, input, Object::OrgMacro); ),
map(parser_with_context!(entity)(context), Object::Entity),
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) map(
parser_with_context!(latex_fragment)(context),
Object::LatexFragment,
),
map(parser_with_context!(radio_link)(context), Object::RadioLink),
map(
parser_with_context!(radio_target)(context),
Object::RadioTarget,
),
parser_with_context!(text_markup)(context),
map(
parser_with_context!(regular_link)(context),
Object::RegularLink,
),
map(parser_with_context!(plain_link)(context), Object::PlainLink),
map(parser_with_context!(angle_link)(context), Object::AngleLink),
map(parser_with_context!(org_macro)(context), Object::OrgMacro),
))(input)?;
Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(
@ -114,12 +135,20 @@ fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
element!(subscript, context, input, Object::Subscript); let (remaining, object) = alt((
element!(superscript, context, input, Object::Superscript); map(parser_with_context!(subscript)(context), Object::Subscript),
element!(entity, context, input, Object::Entity); map(
element!(latex_fragment, context, input, Object::LatexFragment); parser_with_context!(superscript)(context),
element!(text_markup, context, input); Object::Superscript,
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) ),
map(parser_with_context!(entity)(context), Object::Entity),
map(
parser_with_context!(latex_fragment)(context),
Object::LatexFragment,
),
parser_with_context!(text_markup)(context),
))(input)?;
Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(
@ -171,18 +200,16 @@ pub(crate) fn regular_link_description_set_object<'b, 'g, 'r, 's>(
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
// TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
element!( let (remaining, object) = alt((
regular_link_description_set_object_sans_plain_text, parser_with_context!(regular_link_description_set_object_sans_plain_text)(context),
context, map(
input parser_with_context!(plain_text(
); detect_regular_link_description_set_object_sans_plain_text
element!( ))(context),
plain_text(detect_regular_link_description_set_object_sans_plain_text), Object::PlainText,
context, ),
input, ))(input)?;
Object::PlainText Ok((remaining, object))
);
Err(nom::Err::Error(CustomError::MyError(MyError("No object."))))
} }
#[cfg_attr( #[cfg_attr(
@ -194,18 +221,27 @@ fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>(
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
// TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
element!(export_snippet, context, input, Object::ExportSnippet); let (remaining, object) = alt((
element!(statistics_cookie, context, input, Object::StatisticsCookie); map(
element!( parser_with_context!(export_snippet)(context),
inline_source_block, Object::ExportSnippet,
context, ),
input, map(
Object::InlineSourceBlock parser_with_context!(statistics_cookie)(context),
); Object::StatisticsCookie,
element!(inline_babel_call, context, input, Object::InlineBabelCall); ),
element!(org_macro, context, input, Object::OrgMacro); map(
element!(minimal_set_object_sans_plain_text, context, input); parser_with_context!(inline_source_block)(context),
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) Object::InlineSourceBlock,
),
map(
parser_with_context!(inline_babel_call)(context),
Object::InlineBabelCall,
),
map(parser_with_context!(org_macro)(context), Object::OrgMacro),
parser_with_context!(minimal_set_object_sans_plain_text)(context),
))(input)?;
Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(
@ -236,14 +272,14 @@ pub(crate) fn table_cell_set_object<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
element!(table_cell_set_object_sans_plain_text, context, input); let (remaining, object) = alt((
element!( parser_with_context!(table_cell_set_object_sans_plain_text)(context),
plain_text(detect_table_cell_set_object_sans_plain_text), map(
context, parser_with_context!(plain_text(detect_table_cell_set_object_sans_plain_text))(context),
input, Object::PlainText,
Object::PlainText ),
); ))(input)?;
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(
@ -254,24 +290,33 @@ fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> { ) -> Res<OrgSource<'s>, Object<'s>> {
element!(citation, context, input, Object::Citation); let (remaining, object) = alt((
element!(export_snippet, context, input, Object::ExportSnippet); map(parser_with_context!(citation)(context), Object::Citation),
element!( map(
footnote_reference, parser_with_context!(export_snippet)(context),
context, Object::ExportSnippet,
input, ),
Object::FootnoteReference map(
); parser_with_context!(footnote_reference)(context),
element!(radio_link, context, input, Object::RadioLink); Object::FootnoteReference,
element!(regular_link, context, input, Object::RegularLink); ),
element!(plain_link, context, input, Object::PlainLink); map(parser_with_context!(radio_link)(context), Object::RadioLink),
element!(angle_link, context, input, Object::AngleLink); map(
element!(org_macro, context, input, Object::OrgMacro); parser_with_context!(regular_link)(context),
element!(radio_target, context, input, Object::RadioTarget); Object::RegularLink,
element!(target, context, input, Object::Target); ),
element!(timestamp, context, input, Object::Timestamp); map(parser_with_context!(plain_link)(context), Object::PlainLink),
element!(minimal_set_object_sans_plain_text, context, input); map(parser_with_context!(angle_link)(context), Object::AngleLink),
Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) map(parser_with_context!(org_macro)(context), Object::OrgMacro),
map(
parser_with_context!(radio_target)(context),
Object::RadioTarget,
),
map(parser_with_context!(target)(context), Object::Target),
map(parser_with_context!(timestamp)(context), Object::Timestamp),
parser_with_context!(minimal_set_object_sans_plain_text)(context),
))(input)?;
Ok((remaining, object))
} }
#[cfg_attr( #[cfg_attr(

View File

@ -20,6 +20,7 @@ use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords; use super::affiliated_keyword::parse_affiliated_keywords;
use super::element_parser::element; use super::element_parser::element;
use super::keyword::affiliated_keyword;
use super::object_parser::standard_set_object; use super::object_parser::standard_set_object;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::include_input; use super::util::include_input;
@ -52,17 +53,13 @@ use crate::types::PlainListType;
#[cfg_attr( #[cfg_attr(
feature = "tracing", feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context, _affiliated_keywords)) tracing::instrument(ret, level = "debug", skip(context))
)] )]
pub(crate) fn detect_plain_list<'b, 'g, 'r, 's, AK>( pub(crate) fn detect_plain_list<'b, 'g, 'r, 's>(
_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>, ()> ) -> Res<OrgSource<'s>, ()> {
where let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?;
AK: IntoIterator<Item = Keyword<'s>>,
{
if verify( if verify(
tuple(( tuple((
start_of_line, start_of_line,
@ -73,7 +70,7 @@ where
|(_start, (indent_level, _), (_bullet_type, bull), _after_whitespace)| { |(_start, (indent_level, _), (_bullet_type, bull), _after_whitespace)| {
!Into::<&str>::into(bull).starts_with("*") || *indent_level > 0 !Into::<&str>::into(bull).starts_with("*") || *indent_level > 0
}, },
)(remaining) )(input)
.is_ok() .is_ok()
{ {
return Ok((input, ())); return Ok((input, ()));
@ -733,7 +730,7 @@ dolar"#,
let global_settings = GlobalSettings::default(); let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context)); let initial_context = Context::new(&global_settings, List::new(&initial_context));
let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); let result = detect_plain_list(&initial_context, input);
assert!(result.is_ok()); assert!(result.is_ok());
} }
@ -743,7 +740,7 @@ dolar"#,
let global_settings = GlobalSettings::default(); let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context)); let initial_context = Context::new(&global_settings, List::new(&initial_context));
let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); let result = detect_plain_list(&initial_context, input);
assert!(result.is_ok()); assert!(result.is_ok());
} }
@ -753,7 +750,7 @@ dolar"#,
let global_settings = GlobalSettings::default(); let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context)); let initial_context = Context::new(&global_settings, List::new(&initial_context));
let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); let result = detect_plain_list(&initial_context, input);
// Since there is no whitespace after the '+' this is a paragraph, not a plain list. // Since there is no whitespace after the '+' this is a paragraph, not a plain list.
assert!(result.is_err()); assert!(result.is_err());
} }
@ -764,7 +761,7 @@ dolar"#,
let global_settings = GlobalSettings::default(); let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context)); let initial_context = Context::new(&global_settings, List::new(&initial_context));
let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); let result = detect_plain_list(&initial_context, input);
assert!(result.is_ok()); assert!(result.is_ok());
} }
} }

View File

@ -14,6 +14,7 @@ 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::keyword::affiliated_keyword;
use super::keyword::table_formula_keyword; use super::keyword::table_formula_keyword;
use super::object_parser::table_cell_set_object; use super::object_parser::table_cell_set_object;
use super::org_source::OrgSource; use super::org_source::OrgSource;
@ -91,20 +92,13 @@ where
)) ))
} }
#[cfg_attr( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
feature = "tracing", pub(crate) fn detect_table<'b, 'g, 'r, 's>(
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) context: RefContext<'b, 'g, 'r, 's>,
)]
pub(crate) fn detect_table<'b, 'g, 'r, 's, AK>(
_affiliated_keywords: AK,
remaining: OrgSource<'s>,
_context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> ) -> Res<OrgSource<'s>, ()> {
where let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?;
AK: IntoIterator<Item = Keyword<'s>>, tuple((start_of_line, space0, tag("|")))(input)?;
{
tuple((start_of_line, space0, tag("|")))(remaining)?;
Ok((input, ())) Ok((input, ()))
} }