2023-07-22 06:08:42 +00:00
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::bytes::complete::tag;
|
|
|
|
use nom::combinator::recognize;
|
|
|
|
use nom::sequence::tuple;
|
|
|
|
|
2023-08-23 04:30:26 +00:00
|
|
|
use super::org_source::OrgSource;
|
2023-09-08 22:35:33 +00:00
|
|
|
use super::util::get_consumed;
|
2023-08-31 19:44:44 +00:00
|
|
|
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
|
2023-09-03 16:23:18 +00:00
|
|
|
use crate::context::parser_with_context;
|
|
|
|
use crate::context::RefContext;
|
2023-07-22 05:49:07 +00:00
|
|
|
use crate::error::Res;
|
2023-09-03 16:23:18 +00:00
|
|
|
use crate::types::StatisticsCookie;
|
2023-07-22 05:49:07 +00:00
|
|
|
|
2023-08-11 00:04:59 +00:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-09-03 19:44:18 +00:00
|
|
|
pub fn statistics_cookie<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, StatisticsCookie<'s>> {
|
2023-07-22 06:08:42 +00:00
|
|
|
alt((
|
|
|
|
parser_with_context!(percent_statistics_cookie)(context),
|
|
|
|
parser_with_context!(fraction_statistics_cookie)(context),
|
|
|
|
))(input)
|
|
|
|
}
|
|
|
|
|
2023-08-11 00:04:59 +00:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-09-03 19:44:18 +00:00
|
|
|
pub fn percent_statistics_cookie<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, StatisticsCookie<'s>> {
|
2023-09-08 22:35:33 +00:00
|
|
|
let (remaining, _) =
|
2023-07-22 06:08:42 +00:00
|
|
|
recognize(tuple((tag("["), nom::character::complete::u64, tag("%]"))))(input)?;
|
2023-08-31 19:44:44 +00:00
|
|
|
let (remaining, _trailing_whitespace) =
|
|
|
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
2023-09-08 22:35:33 +00:00
|
|
|
let source = get_consumed(input, remaining);
|
2023-08-23 04:30:26 +00:00
|
|
|
Ok((
|
|
|
|
remaining,
|
|
|
|
StatisticsCookie {
|
|
|
|
source: source.into(),
|
|
|
|
},
|
|
|
|
))
|
2023-07-22 06:08:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 00:04:59 +00:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-09-03 19:44:18 +00:00
|
|
|
pub fn fraction_statistics_cookie<'b, 'g, 'r, 's>(
|
|
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
2023-08-23 04:30:26 +00:00
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, StatisticsCookie<'s>> {
|
2023-09-08 22:35:33 +00:00
|
|
|
let (remaining, _) = recognize(tuple((
|
2023-07-22 06:08:42 +00:00
|
|
|
tag("["),
|
|
|
|
nom::character::complete::u64,
|
|
|
|
tag("/"),
|
|
|
|
nom::character::complete::u64,
|
|
|
|
tag("]"),
|
|
|
|
)))(input)?;
|
2023-08-31 19:44:44 +00:00
|
|
|
let (remaining, _trailing_whitespace) =
|
|
|
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
2023-09-08 22:35:33 +00:00
|
|
|
let source = get_consumed(input, remaining);
|
2023-08-23 04:30:26 +00:00
|
|
|
Ok((
|
|
|
|
remaining,
|
|
|
|
StatisticsCookie {
|
|
|
|
source: source.into(),
|
|
|
|
},
|
|
|
|
))
|
2023-07-22 05:49:07 +00:00
|
|
|
}
|