use nom::bytes::complete::tag; use nom::character::complete::anychar; use nom::combinator::peek; use nom::combinator::recognize; use nom::multi::many_till; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; use crate::context::ContextElement; use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::Res; use crate::parser::plain_link::protocol; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::AngleLink; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn angle_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, AngleLink<'s>> { let (remaining, _) = tag("<")(input)?; let (remaining, proto) = protocol(context, remaining)?; let (remaining, _separator) = tag(":")(remaining)?; let (remaining, path) = path_angle(context, remaining)?; let (remaining, _) = tag(">")(remaining)?; let (remaining, _trailing_whitespace) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; let source = get_consumed(input, remaining); Ok(( remaining, AngleLink { source: source.into(), link_type: proto.into(), path: path.into(), }, )) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_angle<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma, exit_matcher: &path_angle_end, }); let parser_context = context.with_additional_node(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let (remaining, path) = recognize(many_till(anychar, peek(exit_matcher)))(input)?; Ok((remaining, path)) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_angle_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag(">")(input) }