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::character::complete::space1;
|
|
|
|
use nom::combinator::eof;
|
|
|
|
use nom::combinator::not;
|
|
|
|
use nom::combinator::opt;
|
|
|
|
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-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-04-21 22:04:22 -04:00
|
|
|
use crate::parser::FixedWidthArea;
|
|
|
|
|
2023-08-10 20:04:59 -04:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-04-21 22:04:22 -04:00
|
|
|
pub fn fixed_width_area<'r, 's>(
|
2023-09-02 22:45:46 -04:00
|
|
|
context: RefContext<'_, '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-04-21 22:11:06 -04:00
|
|
|
fn fixed_width_area_line<'r, 's>(
|
2023-09-02 22:45:46 -04:00
|
|
|
_context: RefContext<'_, '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)?;
|
|
|
|
let (remaining, (_hash, _leading_whitespace_and_content, _line_ending)) = tuple((
|
|
|
|
tag(":"),
|
|
|
|
opt(tuple((space1, is_not("\r\n")))),
|
|
|
|
alt((line_ending, eof)),
|
|
|
|
))(remaining)?;
|
|
|
|
let source = get_consumed(input, remaining);
|
|
|
|
Ok((remaining, source))
|
2023-04-21 22:04:22 -04:00
|
|
|
}
|