2023-04-21 22:11:06 -04:00
|
|
|
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;
|
2023-09-14 03:15:31 -04:00
|
|
|
use nom::combinator::recognize;
|
2023-04-21 22:11:06 -04:00
|
|
|
use nom::multi::many0;
|
|
|
|
use nom::sequence::preceded;
|
|
|
|
use nom::sequence::tuple;
|
|
|
|
|
2023-08-23 00:30:26 -04:00
|
|
|
use super::org_source::OrgSource;
|
2023-09-19 20:22:29 -04:00
|
|
|
use super::util::only_space1;
|
2023-09-14 03:15:31 -04:00
|
|
|
use super::util::org_line_ending;
|
2023-09-03 12:23:18 -04:00
|
|
|
use crate::context::parser_with_context;
|
|
|
|
use crate::context::RefContext;
|
2023-04-21 22:04:22 -04:00
|
|
|
use crate::error::Res;
|
2023-04-21 22:11:06 -04:00
|
|
|
use crate::parser::util::exit_matcher_parser;
|
|
|
|
use crate::parser::util::get_consumed;
|
|
|
|
use crate::parser::util::start_of_line;
|
2023-09-03 12:23:18 -04:00
|
|
|
use crate::types::FixedWidthArea;
|
2023-04-21 22:04:22 -04:00
|
|
|
|
2023-08-10 20:04:59 -04:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-09-11 13:13:28 -04:00
|
|
|
pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>(
|
2023-09-03 15:44:18 -04:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 00:30:26 -04:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, FixedWidthArea<'s>> {
|
2023-04-21 22:11:06 -04:00
|
|
|
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);
|
2023-08-23 00:30:26 -04:00
|
|
|
Ok((
|
|
|
|
remaining,
|
|
|
|
FixedWidthArea {
|
|
|
|
source: source.into(),
|
|
|
|
},
|
|
|
|
))
|
2023-04-21 22:11:06 -04:00
|
|
|
}
|
|
|
|
|
2023-08-10 20:04:59 -04:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-09-03 15:44:18 -04:00
|
|
|
fn fixed_width_area_line<'b, 'g, 'r, 's>(
|
|
|
|
_context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 00:30:26 -04:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
2023-08-24 19:29:00 -04:00
|
|
|
start_of_line(input)?;
|
2023-04-21 22:11:06 -04:00
|
|
|
let (remaining, _indent) = space0(input)?;
|
2023-09-14 03:15:31 -04:00
|
|
|
let (remaining, _) = tuple((
|
2023-04-21 22:11:06 -04:00
|
|
|
tag(":"),
|
2023-09-19 20:22:29 -04:00
|
|
|
alt((recognize(tuple((only_space1, is_not("\r\n")))), space0)),
|
2023-09-14 03:15:31 -04:00
|
|
|
org_line_ending,
|
2023-04-21 22:11:06 -04:00
|
|
|
))(remaining)?;
|
|
|
|
let source = get_consumed(input, remaining);
|
|
|
|
Ok((remaining, source))
|
2023-04-21 22:04:22 -04:00
|
|
|
}
|
2023-09-11 12:28:15 -04:00
|
|
|
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-09-11 13:13:28 -04:00
|
|
|
pub(crate) fn detect_fixed_width_area<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
2023-09-11 12:28:15 -04:00
|
|
|
tuple((
|
|
|
|
start_of_line,
|
|
|
|
space0,
|
|
|
|
tag(":"),
|
|
|
|
alt((tag(" "), line_ending, eof)),
|
|
|
|
))(input)?;
|
|
|
|
Ok((input, ()))
|
|
|
|
}
|