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::org_source::OrgSource; 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: OrgSource<'s>, ) -> Res, 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: source.into(), entity_name: entity_name.into(), }, )) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( _context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // 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"), tag_no_case("ast"), tag_no_case("lt"), tag_no_case("gt"), )),))(input)?; Ok((remaining, proto)) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn entity_end<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let (remaining, _) = alt((eof, recognize(satisfy(|c| !c.is_alphabetic()))))(input)?; Ok((remaining, ())) }