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-08-31 15:31:54 -04:00
|
|
|
use nom::character::complete::anychar;
|
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;
|
2023-08-31 15:31:54 -04:00
|
|
|
use nom::combinator::opt;
|
2023-04-21 20:53:55 -04:00
|
|
|
use nom::combinator::recognize;
|
2023-08-31 15:31:54 -04:00
|
|
|
use nom::multi::many_till;
|
2023-04-21 20:53:55 -04:00
|
|
|
use nom::sequence::tuple;
|
2023-04-21 20:26:49 -04:00
|
|
|
|
2023-08-23 00:30:26 -04:00
|
|
|
use super::org_source::OrgSource;
|
2023-04-21 20:53:55 -04:00
|
|
|
use super::sexp::sexp;
|
2023-09-03 12:23:18 -04:00
|
|
|
use crate::context::RefContext;
|
2023-04-21 20:22:31 -04:00
|
|
|
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-09-03 12:23:18 -04:00
|
|
|
use crate::types::DiarySexp;
|
2023-04-21 20:22:31 -04:00
|
|
|
|
2023-08-10 20:04:59 -04:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-08-23 00:30:26 -04:00
|
|
|
pub fn diary_sexp<'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>, DiarySexp<'s>> {
|
2023-08-24 19:29:00 -04:00
|
|
|
start_of_line(input)?;
|
2023-04-21 20:26:49 -04:00
|
|
|
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)?;
|
2023-08-31 15:31:54 -04:00
|
|
|
let (remaining, _trailing_comment) = opt(tuple((
|
|
|
|
space0,
|
|
|
|
tag(";"),
|
|
|
|
many_till(anychar, alt((line_ending, eof))),
|
|
|
|
)))(remaining)?;
|
2023-04-21 20:53:55 -04:00
|
|
|
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);
|
2023-08-23 00:30:26 -04:00
|
|
|
Ok((
|
|
|
|
remaining,
|
|
|
|
DiarySexp {
|
|
|
|
source: source.into(),
|
|
|
|
},
|
|
|
|
))
|
2023-04-21 20:22:31 -04:00
|
|
|
}
|