organic/src/parser/object_parser.rs
2023-04-22 20:48:01 -04:00

48 lines
1.7 KiB
Rust

use nom::branch::alt;
use nom::combinator::map;
use nom::combinator::not;
use super::parser_with_context::parser_with_context;
use super::plain_text::plain_text;
use super::Context;
use crate::error::Res;
use crate::parser::object::Object;
use crate::parser::text_markup::text_markup;
#[tracing::instrument(ret, level = "debug")]
pub fn standard_set_object<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
// TODO: add entities, LaTeX fragments, export snippets, footnote references, citations (NOT citation references), inline babel calls, inline source blocks, line breaks, links, macros, targets and radio targets, statistics cookies, subscript and superscript, timestamps, and text markup.
not(|i| context.check_exit_matcher(i))(input)?;
alt((
parser_with_context!(text_markup)(context),
map(parser_with_context!(plain_text)(context), Object::PlainText),
))(input)
}
#[tracing::instrument(ret, level = "debug")]
pub fn minimal_set_object<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
// TODO: add text markup, entities, LaTeX fragments, superscripts and subscripts
not(|i| context.check_exit_matcher(i))(input)?;
alt((
parser_with_context!(text_markup)(context),
map(parser_with_context!(plain_text)(context), Object::PlainText),
))(input)
}
#[tracing::instrument(ret, level = "debug")]
pub fn any_object_except_plain_text<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
// Used for exit matchers so this does not check exit matcher condition.
alt((parser_with_context!(text_markup)(context),))(input)
}