Significantly reduce the use of closures in the object parsers.

This commit is contained in:
Tom Alexander 2023-10-16 14:23:53 -04:00
parent 26f1eae9a1
commit cfdf39d1fa
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 69 additions and 112 deletions

View File

@ -19,6 +19,7 @@ use crate::parser::inline_babel_call::inline_babel_call;
use crate::parser::inline_source_block::inline_source_block;
use crate::parser::latex_fragment::latex_fragment;
use crate::parser::line_break::line_break;
use crate::parser::macros::element;
use crate::parser::org_macro::org_macro;
use crate::parser::plain_link::plain_link;
use crate::parser::radio_link::radio_link;
@ -75,56 +76,38 @@ fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> {
let (remaining, object) = alt((
map(parser_with_context!(timestamp)(context), Object::Timestamp),
map(parser_with_context!(subscript)(context), Object::Subscript),
map(
parser_with_context!(superscript)(context),
Object::Superscript,
),
map(
parser_with_context!(statistics_cookie)(context),
Object::StatisticsCookie,
),
map(parser_with_context!(target)(context), Object::Target),
map(parser_with_context!(line_break)(context), Object::LineBreak),
map(
parser_with_context!(inline_source_block)(context),
Object::InlineSourceBlock,
),
map(
parser_with_context!(inline_babel_call)(context),
Object::InlineBabelCall,
),
map(parser_with_context!(citation)(context), Object::Citation),
map(
parser_with_context!(footnote_reference)(context),
Object::FootnoteReference,
),
map(
parser_with_context!(export_snippet)(context),
Object::ExportSnippet,
),
map(parser_with_context!(entity)(context), Object::Entity),
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))
element!(timestamp, context, input, Object::Timestamp);
element!(subscript, context, input, Object::Subscript);
element!(superscript, context, input, Object::Superscript);
element!(statistics_cookie, context, input, Object::StatisticsCookie);
element!(target, context, input, Object::Target);
element!(line_break, context, input, Object::LineBreak);
element!(
inline_source_block,
context,
input,
Object::InlineSourceBlock
);
element!(inline_babel_call, context, input, Object::InlineBabelCall);
element!(citation, context, input, Object::Citation);
element!(
footnote_reference,
context,
input,
Object::FootnoteReference
);
element!(export_snippet, context, input, Object::ExportSnippet);
element!(entity, context, input, Object::Entity);
element!(latex_fragment, context, input, Object::LatexFragment);
element!(radio_link, context, input, Object::RadioLink);
element!(radio_target, context, input, Object::RadioTarget);
element!(text_markup, context, input);
element!(regular_link, context, input, Object::RegularLink);
element!(plain_link, context, input, Object::PlainLink);
element!(angle_link, context, input, Object::AngleLink);
element!(org_macro, context, input, Object::OrgMacro);
Err(nom::Err::Error(CustomError::MyError(MyError("No object."))))
}
#[cfg_attr(
@ -135,20 +118,12 @@ fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> {
let (remaining, object) = alt((
map(parser_with_context!(subscript)(context), Object::Subscript),
map(
parser_with_context!(superscript)(context),
Object::Superscript,
),
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))
element!(subscript, context, input, Object::Subscript);
element!(superscript, context, input, Object::Superscript);
element!(entity, context, input, Object::Entity);
element!(latex_fragment, context, input, Object::LatexFragment);
element!(text_markup, context, input);
Err(nom::Err::Error(CustomError::MyError(MyError("No object."))))
}
#[cfg_attr(
@ -221,27 +196,18 @@ fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>(
input: OrgSource<'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 ]]
let (remaining, object) = alt((
map(
parser_with_context!(export_snippet)(context),
Object::ExportSnippet,
),
map(
parser_with_context!(statistics_cookie)(context),
Object::StatisticsCookie,
),
map(
parser_with_context!(inline_source_block)(context),
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))
element!(export_snippet, context, input, Object::ExportSnippet);
element!(statistics_cookie, context, input, Object::StatisticsCookie);
element!(
inline_source_block,
context,
input,
Object::InlineSourceBlock
);
element!(inline_babel_call, context, input, Object::InlineBabelCall);
element!(org_macro, context, input, Object::OrgMacro);
element!(minimal_set_object_sans_plain_text, context, input);
Err(nom::Err::Error(CustomError::MyError(MyError("No object."))))
}
#[cfg_attr(
@ -290,33 +256,24 @@ fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Object<'s>> {
let (remaining, object) = alt((
map(parser_with_context!(citation)(context), Object::Citation),
map(
parser_with_context!(export_snippet)(context),
Object::ExportSnippet,
),
map(
parser_with_context!(footnote_reference)(context),
Object::FootnoteReference,
),
map(parser_with_context!(radio_link)(context), Object::RadioLink),
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),
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))
element!(citation, context, input, Object::Citation);
element!(export_snippet, context, input, Object::ExportSnippet);
element!(
footnote_reference,
context,
input,
Object::FootnoteReference
);
element!(radio_link, context, input, Object::RadioLink);
element!(regular_link, context, input, Object::RegularLink);
element!(plain_link, context, input, Object::PlainLink);
element!(angle_link, context, input, Object::AngleLink);
element!(org_macro, context, input, Object::OrgMacro);
element!(radio_target, context, input, Object::RadioTarget);
element!(target, context, input, Object::Target);
element!(timestamp, context, input, Object::Timestamp);
element!(minimal_set_object_sans_plain_text, context, input);
Err(nom::Err::Error(CustomError::MyError(MyError("No object."))))
}
#[cfg_attr(