From a947ab095550164db4ab8d14ad85c2d91cfba40b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 21 Apr 2023 19:14:41 -0400 Subject: [PATCH] First stab at clock parser. --- src/parser/clock.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/parser/clock.rs b/src/parser/clock.rs index a3d94c82..5b71e01a 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -1,8 +1,44 @@ +use nom::branch::alt; +use nom::bytes::complete::tag_no_case; +use nom::character::complete::space0; +use nom::character::complete::space1; + use super::Context; use crate::error::Res; +use crate::parser::parser_with_context::parser_with_context; +use crate::parser::util::get_consumed; +use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; +use crate::parser::util::start_of_line; use crate::parser::Clock; #[tracing::instrument(ret, level = "debug")] pub fn clock<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Clock<'s>> { + start_of_line(context, input)?; + let (remaining, _leading_whitespace) = space0(input)?; + let (remaining, _clock) = tag_no_case("clock:")(remaining)?; + let (remaining, _gap_whitespace) = space1(remaining)?; + + let (remaining, _timestamp_junk) = alt(( + parser_with_context!(inactive_timestamp_range_duration)(context), + parser_with_context!(inactive_timestamp)(context), + ))(remaining)?; + + let (remaining, _trailing_ws) = + maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; + + let source = get_consumed(input, remaining); + Ok((remaining, Clock { source })) +} + +#[tracing::instrument(ret, level = "debug")] +fn inactive_timestamp_range_duration<'r, 's>( + context: Context<'r, 's>, + input: &'s str, +) -> Res<&'s str, &'s str> { + todo!() +} + +#[tracing::instrument(ret, level = "debug")] +fn inactive_timestamp<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { todo!() }