2023-04-22 22:54:19 +00:00
|
|
|
use nom::branch::alt;
|
2023-04-21 20:07:38 +00:00
|
|
|
use nom::combinator::map;
|
|
|
|
|
2023-08-23 04:30:26 +00:00
|
|
|
use super::org_source::OrgSource;
|
2023-04-21 20:07:38 +00:00
|
|
|
use super::plain_text::plain_text;
|
2023-04-23 20:53:02 +00:00
|
|
|
use super::regular_link::regular_link;
|
2023-09-07 06:59:08 +00:00
|
|
|
use super::subscript_and_superscript::detect_subscript_or_superscript;
|
2023-09-03 16:07:51 +00:00
|
|
|
use crate::context::parser_with_context;
|
|
|
|
use crate::context::RefContext;
|
2023-09-07 06:59:08 +00:00
|
|
|
use crate::error::CustomError;
|
|
|
|
use crate::error::MyError;
|
2023-04-23 00:02:51 +00:00
|
|
|
use crate::error::Res;
|
2023-07-14 02:42:42 +00:00
|
|
|
use crate::parser::angle_link::angle_link;
|
2023-07-21 22:19:39 +00:00
|
|
|
use crate::parser::citation::citation;
|
2023-07-19 00:05:39 +00:00
|
|
|
use crate::parser::entity::entity;
|
2023-07-19 04:37:51 +00:00
|
|
|
use crate::parser::export_snippet::export_snippet;
|
2023-07-19 22:56:46 +00:00
|
|
|
use crate::parser::footnote_reference::footnote_reference;
|
2023-07-22 01:38:32 +00:00
|
|
|
use crate::parser::inline_babel_call::inline_babel_call;
|
2023-07-22 02:29:04 +00:00
|
|
|
use crate::parser::inline_source_block::inline_source_block;
|
2023-07-19 00:51:06 +00:00
|
|
|
use crate::parser::latex_fragment::latex_fragment;
|
2023-07-22 04:00:53 +00:00
|
|
|
use crate::parser::line_break::line_break;
|
2023-07-14 04:28:56 +00:00
|
|
|
use crate::parser::org_macro::org_macro;
|
2023-07-13 22:18:07 +00:00
|
|
|
use crate::parser::plain_link::plain_link;
|
2023-04-24 22:55:15 +00:00
|
|
|
use crate::parser::radio_link::radio_link;
|
|
|
|
use crate::parser::radio_link::radio_target;
|
2023-07-22 06:08:42 +00:00
|
|
|
use crate::parser::statistics_cookie::statistics_cookie;
|
2023-07-24 18:19:19 +00:00
|
|
|
use crate::parser::subscript_and_superscript::subscript;
|
|
|
|
use crate::parser::subscript_and_superscript::superscript;
|
2023-07-22 05:40:14 +00:00
|
|
|
use crate::parser::target::target;
|
2023-04-23 00:02:51 +00:00
|
|
|
use crate::parser::text_markup::text_markup;
|
2023-07-24 21:34:07 +00:00
|
|
|
use crate::parser::timestamp::timestamp;
|
2023-09-03 16:07:51 +00:00
|
|
|
use crate::types::Object;
|
2023-04-21 20:07:38 +00:00
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
pub(crate) fn standard_set_object<'b, 'g, 'r, 's>(
|
2023-09-03 19:44:18 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
2023-09-08 21:45:49 +00:00
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
|
|
|
let (remaining, object) = alt((
|
|
|
|
parser_with_context!(standard_set_object_sans_plain_text)(context),
|
|
|
|
map(
|
|
|
|
parser_with_context!(plain_text(detect_standard_set_object_sans_plain_text))(context),
|
|
|
|
Object::PlainText,
|
|
|
|
),
|
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
pub(crate) fn minimal_set_object<'b, 'g, 'r, 's>(
|
2023-09-08 21:45:49 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
|
|
|
let (remaining, object) = alt((
|
|
|
|
parser_with_context!(minimal_set_object_sans_plain_text)(context),
|
|
|
|
map(
|
|
|
|
parser_with_context!(plain_text(detect_minimal_set_object_sans_plain_text))(context),
|
|
|
|
Object::PlainText,
|
|
|
|
),
|
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-08 21:45:49 +00:00
|
|
|
fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
2023-08-23 04:30:26 +00:00
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
2023-08-29 17:45:35 +00:00
|
|
|
let (remaining, object) = alt((
|
2023-07-24 21:34:07 +00:00
|
|
|
map(parser_with_context!(timestamp)(context), Object::Timestamp),
|
2023-07-24 18:19:19 +00:00
|
|
|
map(parser_with_context!(subscript)(context), Object::Subscript),
|
|
|
|
map(
|
|
|
|
parser_with_context!(superscript)(context),
|
|
|
|
Object::Superscript,
|
|
|
|
),
|
2023-07-22 06:08:42 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(statistics_cookie)(context),
|
|
|
|
Object::StatisticsCookie,
|
|
|
|
),
|
2023-07-22 05:40:14 +00:00
|
|
|
map(parser_with_context!(target)(context), Object::Target),
|
2023-07-22 04:00:53 +00:00
|
|
|
map(parser_with_context!(line_break)(context), Object::LineBreak),
|
2023-07-22 02:29:04 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(inline_source_block)(context),
|
|
|
|
Object::InlineSourceBlock,
|
|
|
|
),
|
2023-07-22 01:38:32 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(inline_babel_call)(context),
|
|
|
|
Object::InlineBabelCall,
|
|
|
|
),
|
2023-07-21 22:52:02 +00:00
|
|
|
map(parser_with_context!(citation)(context), Object::Citation),
|
2023-07-19 22:56:46 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(footnote_reference)(context),
|
|
|
|
Object::FootnoteReference,
|
|
|
|
),
|
2023-07-19 04:37:51 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(export_snippet)(context),
|
|
|
|
Object::ExportSnippet,
|
|
|
|
),
|
2023-07-19 00:05:39 +00:00
|
|
|
map(parser_with_context!(entity)(context), Object::Entity),
|
2023-07-19 00:51:06 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(latex_fragment)(context),
|
|
|
|
Object::LatexFragment,
|
|
|
|
),
|
2023-04-24 22:55:15 +00:00
|
|
|
map(parser_with_context!(radio_link)(context), Object::RadioLink),
|
|
|
|
map(
|
|
|
|
parser_with_context!(radio_target)(context),
|
|
|
|
Object::RadioTarget,
|
|
|
|
),
|
2023-04-23 00:48:01 +00:00
|
|
|
parser_with_context!(text_markup)(context),
|
2023-04-23 20:53:02 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(regular_link)(context),
|
|
|
|
Object::RegularLink,
|
|
|
|
),
|
2023-07-13 22:18:07 +00:00
|
|
|
map(parser_with_context!(plain_link)(context), Object::PlainLink),
|
2023-07-14 02:42:42 +00:00
|
|
|
map(parser_with_context!(angle_link)(context), Object::AngleLink),
|
2023-07-14 03:26:51 +00:00
|
|
|
map(parser_with_context!(org_macro)(context), Object::OrgMacro),
|
2023-08-29 17:45:35 +00:00
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
2023-04-21 20:07:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-08 21:45:49 +00:00
|
|
|
fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
2023-09-03 19:44:18 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
2023-08-29 17:45:35 +00:00
|
|
|
let (remaining, object) = alt((
|
2023-07-24 18:19:19 +00:00
|
|
|
map(parser_with_context!(subscript)(context), Object::Subscript),
|
|
|
|
map(
|
|
|
|
parser_with_context!(superscript)(context),
|
|
|
|
Object::Superscript,
|
|
|
|
),
|
2023-07-19 00:05:39 +00:00
|
|
|
map(parser_with_context!(entity)(context), Object::Entity),
|
2023-07-19 00:51:06 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(latex_fragment)(context),
|
|
|
|
Object::LatexFragment,
|
|
|
|
),
|
2023-04-23 00:48:01 +00:00
|
|
|
parser_with_context!(text_markup)(context),
|
2023-08-29 17:45:35 +00:00
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
2023-04-21 20:07:38 +00:00
|
|
|
}
|
2023-04-22 23:46:27 +00:00
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
pub(crate) fn detect_standard_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
2023-09-08 21:45:49 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, ()> {
|
|
|
|
if detect_subscript_or_superscript(input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
if standard_set_object_sans_plain_text(context, input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
|
|
"No object detected.".into(),
|
|
|
|
))));
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-08 21:45:49 +00:00
|
|
|
fn detect_minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, ()> {
|
|
|
|
if detect_subscript_or_superscript(input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
if minimal_set_object_sans_plain_text(context, input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
|
|
"No object detected.".into(),
|
|
|
|
))));
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
pub(crate) fn regular_link_description_set_object<'b, 'g, 'r, 's>(
|
2023-09-03 19:44:18 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
2023-09-08 21:45:49 +00:00
|
|
|
// TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
|
2023-08-29 17:45:35 +00:00
|
|
|
let (remaining, object) = alt((
|
2023-09-08 21:45:49 +00:00
|
|
|
parser_with_context!(regular_link_description_set_object_sans_plain_text)(context),
|
2023-07-24 18:19:19 +00:00
|
|
|
map(
|
2023-09-08 21:45:49 +00:00
|
|
|
parser_with_context!(plain_text(
|
|
|
|
detect_regular_link_description_set_object_sans_plain_text
|
|
|
|
))(context),
|
|
|
|
Object::PlainText,
|
|
|
|
),
|
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-08 21:45:49 +00:00
|
|
|
fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'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,
|
2023-07-24 18:19:19 +00:00
|
|
|
),
|
2023-07-22 06:08:42 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(statistics_cookie)(context),
|
|
|
|
Object::StatisticsCookie,
|
|
|
|
),
|
2023-07-22 02:29:04 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(inline_source_block)(context),
|
|
|
|
Object::InlineSourceBlock,
|
|
|
|
),
|
2023-07-22 01:38:32 +00:00
|
|
|
map(
|
|
|
|
parser_with_context!(inline_babel_call)(context),
|
|
|
|
Object::InlineBabelCall,
|
|
|
|
),
|
2023-07-14 03:26:51 +00:00
|
|
|
map(parser_with_context!(org_macro)(context), Object::OrgMacro),
|
2023-09-08 21:45:49 +00:00
|
|
|
parser_with_context!(minimal_set_object_sans_plain_text)(context),
|
2023-08-29 17:45:35 +00:00
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
2023-04-23 20:53:02 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
fn detect_regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
2023-09-07 06:59:08 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, ()> {
|
|
|
|
if detect_subscript_or_superscript(input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
2023-09-08 21:45:49 +00:00
|
|
|
if regular_link_description_set_object_sans_plain_text(context, input).is_ok() {
|
2023-09-07 06:59:08 +00:00
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
|
|
"No object detected.".into(),
|
|
|
|
))));
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
pub(crate) fn table_cell_set_object<'b, 'g, 'r, 's>(
|
2023-09-03 19:44:18 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
2023-08-29 17:45:35 +00:00
|
|
|
let (remaining, object) = alt((
|
2023-09-08 21:45:49 +00:00
|
|
|
parser_with_context!(table_cell_set_object_sans_plain_text)(context),
|
2023-07-24 21:34:07 +00:00
|
|
|
map(
|
2023-09-08 21:45:49 +00:00
|
|
|
parser_with_context!(plain_text(detect_table_cell_set_object_sans_plain_text))(context),
|
|
|
|
Object::PlainText,
|
2023-07-24 21:34:07 +00:00
|
|
|
),
|
2023-08-29 17:45:35 +00:00
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
2023-04-22 23:46:27 +00:00
|
|
|
}
|
2023-08-25 08:35:54 +00:00
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
2023-09-03 19:44:18 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-25 08:35:54 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Object<'s>> {
|
2023-08-29 17:45:35 +00:00
|
|
|
let (remaining, object) = alt((
|
2023-08-25 08:35:54 +00:00
|
|
|
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),
|
2023-09-08 21:45:49 +00:00
|
|
|
parser_with_context!(minimal_set_object_sans_plain_text)(context),
|
2023-08-29 17:45:35 +00:00
|
|
|
))(input)?;
|
|
|
|
Ok((remaining, object))
|
2023-08-25 08:35:54 +00:00
|
|
|
}
|
2023-09-08 21:45:49 +00:00
|
|
|
|
2023-10-09 23:52:32 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
|
|
|
tracing::instrument(ret, level = "debug", skip(context))
|
|
|
|
)]
|
2023-09-11 17:13:28 +00:00
|
|
|
fn detect_table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>(
|
2023-09-08 21:45:49 +00:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, ()> {
|
|
|
|
if detect_subscript_or_superscript(input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
if table_cell_set_object_sans_plain_text(context, input).is_ok() {
|
|
|
|
return Ok((input, ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
|
|
"No object detected.".into(),
|
|
|
|
))));
|
|
|
|
}
|