2023-04-21 20:53:55 -04:00
|
|
|
use nom::branch::alt;
|
2023-04-21 20:26:49 -04:00
|
|
|
use nom::bytes::complete::tag;
|
2023-04-21 20:53:55 -04:00
|
|
|
use nom::character::complete::line_ending;
|
2023-04-21 20:26:49 -04:00
|
|
|
use nom::character::complete::space0;
|
2023-04-21 20:53:55 -04:00
|
|
|
use nom::combinator::eof;
|
|
|
|
use nom::combinator::recognize;
|
|
|
|
use nom::sequence::tuple;
|
2023-04-21 20:26:49 -04:00
|
|
|
|
2023-04-21 20:53:55 -04:00
|
|
|
use super::sexp::sexp;
|
2023-04-21 20:22:31 -04:00
|
|
|
use super::Context;
|
|
|
|
use crate::error::Res;
|
2023-04-21 20:26:49 -04:00
|
|
|
use crate::parser::util::get_consumed;
|
|
|
|
use crate::parser::util::start_of_line;
|
2023-04-21 20:22:31 -04:00
|
|
|
use crate::parser::DiarySexp;
|
|
|
|
|
|
|
|
#[tracing::instrument(ret, level = "debug")]
|
|
|
|
pub fn diary_sexp<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, DiarySexp<'s>> {
|
2023-04-21 20:26:49 -04:00
|
|
|
start_of_line(context, input)?;
|
|
|
|
let (remaining, _leading_whitespace) = space0(input)?;
|
|
|
|
let (remaining, _clock) = tag("%%")(remaining)?;
|
|
|
|
let (remaining, _gap_whitespace) = space0(remaining)?;
|
2023-04-21 20:53:55 -04:00
|
|
|
let (remaining, _sexp) = recognize(sexp)(remaining)?;
|
|
|
|
let (remaining, _trailing_whitespace) =
|
|
|
|
recognize(tuple((space0, alt((line_ending, eof)))))(remaining)?;
|
|
|
|
|
2023-04-21 20:26:49 -04:00
|
|
|
let source = get_consumed(input, remaining);
|
|
|
|
Ok((remaining, DiarySexp { source }))
|
2023-04-21 20:22:31 -04:00
|
|
|
}
|