organic/src/parser/diary_sexp.rs

39 lines
1.2 KiB
Rust
Raw Normal View History

2023-04-21 20:53:55 -04:00
use nom::branch::alt;
use nom::bytes::complete::is_not;
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;
use nom::combinator::eof;
use nom::sequence::tuple;
2023-04-21 20:26:49 -04:00
use super::org_source::OrgSource;
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-09-11 13:13:28 -04:00
pub(crate) fn diary_sexp<'b, 'g, 'r, 's>(
_context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, DiarySexp<'s>> {
start_of_line(input)?;
let (remaining, _clock) = tag("%%(")(input)?;
let (remaining, _contents) = is_not("\r\n")(remaining)?;
let (remaining, _eol) = alt((line_ending, eof))(remaining)?;
2023-04-21 20:53:55 -04:00
2023-04-21 20:26:49 -04:00
let source = get_consumed(input, remaining);
Ok((
remaining,
DiarySexp {
source: source.into(),
},
))
2023-04-21 20:22:31 -04:00
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
2023-09-11 13:13:28 -04:00
pub(crate) fn detect_diary_sexp<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
tuple((start_of_line, tag("%%(")))(input)?;
Ok((input, ()))
}