use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; use nom::character::complete::satisfy; use nom::character::complete::space0; use nom::combinator::eof; use nom::combinator::peek; use nom::combinator::recognize; use super::Context; use crate::error::Res; use crate::parser::object::Entity; use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::get_consumed; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn entity<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Entity<'s>> { let (remaining, _) = tag("\\")(input)?; let (remaining, entity_name) = name(context, remaining)?; let (remaining, _) = alt(( tag("{}"), peek(recognize(parser_with_context!(entity_end)(context))), ))(remaining)?; let (remaining, _) = space0(remaining)?; let source = get_consumed(input, remaining); Ok(( remaining, Entity { source, entity_name, }, )) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { // TODO: This should be defined by org-entities and optionally org-entities-user // TODO: Add the rest of the entities, this is a very incomplete list let (remaining, proto) = alt((alt((tag_no_case("delta"), tag_no_case("pi"))),))(input)?; Ok((remaining, proto)) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn entity_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> { let (remaining, _) = alt((eof, recognize(satisfy(|c| !c.is_alphabetic()))))(input)?; Ok((remaining, ())) }