2023-09-11 12:34:57 -04:00
|
|
|
use nom::bytes::complete::is_not;
|
2023-04-21 20:26:49 -04:00
|
|
|
use nom::bytes::complete::tag;
|
2023-10-05 03:46:14 -04:00
|
|
|
use nom::combinator::recognize;
|
2023-10-04 20:01:09 -04:00
|
|
|
use nom::multi::many0;
|
2023-04-21 20:53:55 -04:00
|
|
|
use nom::sequence::tuple;
|
2023-04-21 20:26:49 -04:00
|
|
|
|
2023-10-11 14:44:25 -04:00
|
|
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
2023-10-04 20:01:09 -04:00
|
|
|
use super::keyword::affiliated_keyword;
|
2023-08-23 00:30:26 -04:00
|
|
|
use super::org_source::OrgSource;
|
2023-10-06 11:45:15 -04:00
|
|
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
2023-10-05 03:46:14 -04:00
|
|
|
use super::util::org_line_ending;
|
2023-10-15 14:22:01 -04:00
|
|
|
use crate::context::parser_with_context;
|
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-10-12 17:12:55 -04:00
|
|
|
use crate::types::Keyword;
|
2023-04-21 20:22:31 -04:00
|
|
|
|
2023-10-09 18:00:48 -04:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "tracing",
|
2023-10-14 19:02:35 -04:00
|
|
|
tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords))
|
2023-10-09 18:00:48 -04:00
|
|
|
)]
|
2023-10-12 17:12:55 -04:00
|
|
|
pub(crate) fn diary_sexp<'b, 'g, 'r, 's, AK>(
|
|
|
|
affiliated_keywords: AK,
|
|
|
|
remaining: OrgSource<'s>,
|
2023-10-06 11:45:15 -04:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 00:30:26 -04:00
|
|
|
input: OrgSource<'s>,
|
2023-10-12 17:12:55 -04:00
|
|
|
) -> Res<OrgSource<'s>, DiarySexp<'s>>
|
|
|
|
where
|
|
|
|
AK: IntoIterator<Item = Keyword<'s>>,
|
|
|
|
{
|
2023-10-06 11:45:15 -04:00
|
|
|
start_of_line(remaining)?;
|
|
|
|
let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(remaining)?;
|
2023-10-05 03:46:14 -04:00
|
|
|
let (remaining, _eol) = org_line_ending(remaining)?;
|
2023-04-21 20:53:55 -04:00
|
|
|
|
2023-10-06 11:45:15 -04:00
|
|
|
let (remaining, _trailing_ws) =
|
|
|
|
maybe_consume_trailing_whitespace_if_not_exiting(context, 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-10-11 14:44:25 -04:00
|
|
|
affiliated_keywords: parse_affiliated_keywords(
|
|
|
|
context.get_global_settings(),
|
|
|
|
affiliated_keywords,
|
|
|
|
),
|
2023-10-05 03:46:14 -04:00
|
|
|
value: Into::<&str>::into(value),
|
2023-08-23 00:30:26 -04:00
|
|
|
},
|
|
|
|
))
|
2023-04-21 20:22:31 -04:00
|
|
|
}
|
2023-09-11 12:28:15 -04:00
|
|
|
|
2023-10-16 14:55:40 -04:00
|
|
|
#[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>,
|
2023-10-15 14:22:01 -04:00
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
2023-10-16 14:55:40 -04:00
|
|
|
) -> Res<OrgSource<'s>, ()>
|
|
|
|
where
|
|
|
|
AK: IntoIterator<Item = Keyword<'s>>,
|
|
|
|
{
|
|
|
|
tuple((start_of_line, tag("%%(")))(remaining)?;
|
2023-09-11 12:28:15 -04:00
|
|
|
Ok((input, ()))
|
|
|
|
}
|