use nom::bytes::complete::is_not; use nom::bytes::complete::tag; use nom::combinator::recognize; use nom::multi::many0; use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; use super::keyword::affiliated_keyword; use super::org_source::OrgSource; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::org_line_ending; use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::types::DiarySexp; use crate::types::Keyword; #[cfg_attr( feature = "tracing", tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) )] pub(crate) fn diary_sexp<'b, 'g, 'r, 's, AK>( affiliated_keywords: AK, remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, DiarySexp<'s>> where AK: IntoIterator>, { start_of_line(remaining)?; let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(remaining)?; let (remaining, _eol) = org_line_ending(remaining)?; let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; let source = get_consumed(input, remaining); Ok(( remaining, DiarySexp { source: source.into(), affiliated_keywords: parse_affiliated_keywords( context.get_global_settings(), affiliated_keywords, ), value: Into::<&str>::into(value), }, )) } #[cfg_attr( feature = "tracing", tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) )] pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's, AK>( affiliated_keywords: AK, remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> where AK: IntoIterator>, { tuple((start_of_line, tag("%%(")))(remaining)?; Ok((input, ())) }