diff --git a/src/parser/planning.rs b/src/parser/planning.rs index e616adf..7f0b0bf 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -1,8 +1,42 @@ +use nom::branch::alt; +use nom::bytes::complete::is_not; +use nom::bytes::complete::tag; +use nom::bytes::complete::tag_no_case; +use nom::character::complete::line_ending; +use nom::character::complete::space0; +use nom::character::complete::space1; +use nom::combinator::eof; +use nom::multi::separated_list1; +use nom::sequence::tuple; + use super::Context; use crate::error::Res; use crate::parser::lesser_element::Planning; +use crate::parser::util::get_consumed; +use crate::parser::util::start_of_line; #[tracing::instrument(ret, level = "debug")] pub fn planning<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Planning<'s>> { - todo!() + start_of_line(context, input)?; + let (remaining, _leading_whitespace) = space0(input)?; + let (remaining, _planning_parameters) = separated_list1(space1, planning_parameter)(remaining)?; + let (remaining, _trailing_ws) = tuple((space0, alt((line_ending, eof))))(remaining)?; + + let source = get_consumed(input, remaining); + + Ok((remaining, Planning { source })) +} + +#[tracing::instrument(ret, level = "debug")] +fn planning_parameter<'s>(input: &'s str) -> Res<&'s str, &'s str> { + let (remaining, _planning_type) = alt(( + tag_no_case("DEADLINE"), + tag_no_case("SCHEDULED"), + tag_no_case("CLOSED"), + ))(input)?; + let (remaining, _gap) = tuple((tag(":"), space1))(remaining)?; + // TODO: Make this invoke the real timestamp parser. + let (remaining, _timestamp) = tuple((tag("<"), is_not("\r\n>"), tag(">")))(remaining)?; + let source = get_consumed(input, remaining); + Ok((remaining, source)) }