2023-04-21 22:11:06 -04:00
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::bytes::complete::tag;
|
2023-10-05 03:58:42 -04:00
|
|
|
use nom::character::complete::anychar;
|
2023-04-21 22:11:06 -04:00
|
|
|
use nom::character::complete::space0;
|
2023-12-15 12:45:51 -05:00
|
|
|
use nom::combinator::map;
|
2023-04-21 22:11:06 -04:00
|
|
|
use nom::combinator::not;
|
2023-12-15 12:45:51 -05:00
|
|
|
use nom::combinator::peek;
|
2023-09-14 03:15:31 -04:00
|
|
|
use nom::combinator::recognize;
|
2023-04-21 22:11:06 -04:00
|
|
|
use nom::multi::many0;
|
2023-10-05 03:58:42 -04:00
|
|
|
use nom::multi::many_till;
|
2023-04-21 22:11:06 -04:00
|
|
|
use nom::sequence::preceded;
|
|
|
|
use nom::sequence::tuple;
|
2023-12-15 12:45:51 -05:00
|
|
|
use nom::InputTake;
|
2023-04-21 22:11:06 -04:00
|
|
|
|
2023-10-11 14:44:25 -04:00
|
|
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
2023-08-23 00:30:26 -04:00
|
|
|
use super::org_source::OrgSource;
|
2023-12-15 12:45:51 -05:00
|
|
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting_mid_line;
|
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-10-12 17:12:55 -04:00
|
|
|
use crate::types::Keyword;
|
2023-04-21 22:04:22 -04:00
|
|
|
|
2023-10-09 18:00:48 -04:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
2023-10-14 19:02:35 -04:00
|
|
|
tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords))
|
2023-10-09 18:00:48 -04:00
|
|
|
)]
|
2023-10-12 17:12:55 -04:00
|
|
|
pub(crate) fn fixed_width_area<'b, 'g, 'r, 's, AK>(
|
|
|
|
affiliated_keywords: AK,
|
|
|
|
remaining: OrgSource<'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>,
|
2023-10-12 17:12:55 -04:00
|
|
|
) -> Res<OrgSource<'s>, FixedWidthArea<'s>>
|
|
|
|
where
|
|
|
|
AK: IntoIterator<Item = Keyword<'s>>,
|
|
|
|
{
|
2023-04-21 22:11:06 -04:00
|
|
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
2023-12-15 12:45:51 -05:00
|
|
|
let (remaining, first_line) = fixed_width_area_line(remaining)?;
|
|
|
|
let (remaining, remaining_lines) = many0(preceded(
|
|
|
|
not(tuple((org_line_ending, exit_matcher))),
|
|
|
|
map(
|
|
|
|
tuple((org_line_ending, fixed_width_area_line)),
|
|
|
|
|(_line_ending, line_contents)| line_contents,
|
|
|
|
),
|
|
|
|
))(remaining)?;
|
2023-04-21 22:11:06 -04:00
|
|
|
|
2023-12-15 12:29:46 -05:00
|
|
|
let (remaining, post_blank) =
|
2023-12-15 12:45:51 -05:00
|
|
|
maybe_consume_trailing_whitespace_if_not_exiting_mid_line(context, remaining)?;
|
2023-04-21 22:11:06 -04:00
|
|
|
let source = get_consumed(input, remaining);
|
2023-10-05 03:58:42 -04:00
|
|
|
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
|
2023-12-15 12:45:51 -05:00
|
|
|
value.push(Into::<&str>::into(first_line));
|
|
|
|
value.extend(remaining_lines.into_iter().map(Into::<&str>::into));
|
2023-08-23 00:30:26 -04:00
|
|
|
Ok((
|
|
|
|
remaining,
|
|
|
|
FixedWidthArea {
|
|
|
|
source: source.into(),
|
2023-10-11 14:44:25 -04:00
|
|
|
affiliated_keywords: parse_affiliated_keywords(
|
|
|
|
context.get_global_settings(),
|
|
|
|
affiliated_keywords,
|
|
|
|
),
|
2023-10-05 03:58:42 -04:00
|
|
|
value,
|
2023-12-15 12:29:46 -05:00
|
|
|
post_blank: post_blank.map(Into::<&str>::into),
|
2023-08-23 00:30:26 -04:00
|
|
|
},
|
|
|
|
))
|
2023-04-21 22:11:06 -04:00
|
|
|
}
|
|
|
|
|
2023-12-15 12:45:51 -05:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
|
|
fn fixed_width_area_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
2023-08-24 19:29:00 -04:00
|
|
|
start_of_line(input)?;
|
2023-10-05 03:58:42 -04:00
|
|
|
let (remaining, _) = tuple((space0, tag(":")))(input)?;
|
2023-12-15 12:45:51 -05:00
|
|
|
if let Ok((remain, _line_break)) = org_line_ending(remaining) {
|
|
|
|
return Ok((remain, remaining.take(0)));
|
2023-10-05 03:58:42 -04:00
|
|
|
}
|
|
|
|
let (remaining, _) = tag(" ")(remaining)?;
|
2023-12-15 12:45:51 -05:00
|
|
|
let (remaining, value) = recognize(many_till(anychar, peek(org_line_ending)))(remaining)?;
|
2023-10-05 03:58:42 -04:00
|
|
|
Ok((remaining, value))
|
2023-04-21 22:04:22 -04:00
|
|
|
}
|
2023-09-11 12:28:15 -04:00
|
|
|
|
2023-10-16 14:55:40 -04:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
2023-10-16 15:03:23 -04:00
|
|
|
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords))
|
2023-10-16 14:55:40 -04:00
|
|
|
)]
|
|
|
|
pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's, AK>(
|
2023-10-16 15:03:23 -04:00
|
|
|
_affiliated_keywords: AK,
|
2023-10-16 14:55:40 -04:00
|
|
|
remaining: OrgSource<'s>,
|
2023-10-16 15:03:23 -04:00
|
|
|
_context: RefContext<'b, 'g, 'r, 's>,
|
2023-10-15 14:22:01 -04:00
|
|
|
input: OrgSource<'s>,
|
2023-10-16 14:55:40 -04:00
|
|
|
) -> Res<OrgSource<'s>, ()>
|
|
|
|
where
|
|
|
|
AK: IntoIterator<Item = Keyword<'s>>,
|
|
|
|
{
|
2023-09-11 12:28:15 -04:00
|
|
|
tuple((
|
|
|
|
start_of_line,
|
|
|
|
space0,
|
|
|
|
tag(":"),
|
2023-10-05 03:58:42 -04:00
|
|
|
alt((tag(" "), org_line_ending)),
|
2023-10-16 14:55:40 -04:00
|
|
|
))(remaining)?;
|
2023-09-11 12:28:15 -04:00
|
|
|
Ok((input, ()))
|
|
|
|
}
|