use nom::branch::alt; use nom::bytes::complete::is_not; use nom::bytes::complete::tag; use nom::character::complete::line_ending; use nom::character::complete::space0; use nom::combinator::eof; use nom::combinator::not; use nom::combinator::recognize; use nom::multi::many0; use nom::sequence::preceded; use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::only_space1; use super::util::org_line_ending; use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::types::FixedWidthArea; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FixedWidthArea<'s>> { let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context); let exit_matcher = parser_with_context!(exit_matcher_parser)(context); let (remaining, _first_line) = fixed_width_area_line_matcher(input)?; let (remaining, _remaining_lines) = many0(preceded(not(exit_matcher), fixed_width_area_line_matcher))(remaining)?; let source = get_consumed(input, remaining); Ok(( remaining, FixedWidthArea { source: source.into(), }, )) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn fixed_width_area_line<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; let (remaining, _indent) = space0(input)?; let (remaining, _) = tuple(( tag(":"), alt((recognize(tuple((only_space1, is_not("\r\n")))), space0)), org_line_ending, ))(remaining)?; let source = get_consumed(input, remaining); Ok((remaining, source)) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn detect_fixed_width_area<'s>(input: OrgSource<'s>) -> Res, ()> { tuple(( start_of_line, space0, tag(":"), alt((tag(" "), line_ending, eof)), ))(input)?; Ok((input, ())) }