2023-07-22 06:08:42 +00:00
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::bytes::complete::tag;
|
|
|
|
use nom::character::complete::space0;
|
|
|
|
use nom::combinator::recognize;
|
|
|
|
use nom::sequence::tuple;
|
|
|
|
|
2023-07-22 05:49:07 +00:00
|
|
|
use super::Context;
|
|
|
|
use crate::error::Res;
|
2023-07-22 06:08:42 +00:00
|
|
|
use crate::parser::parser_with_context::parser_with_context;
|
2023-07-22 05:49:07 +00:00
|
|
|
use crate::parser::StatisticsCookie;
|
|
|
|
|
2023-08-11 00:04:59 +00:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-07-22 05:49:07 +00:00
|
|
|
pub fn statistics_cookie<'r, 's>(
|
|
|
|
context: Context<'r, 's>,
|
|
|
|
input: &'s str,
|
|
|
|
) -> Res<&'s str, 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-07-22 06:08:42 +00:00
|
|
|
pub fn percent_statistics_cookie<'r, 's>(
|
|
|
|
context: Context<'r, 's>,
|
|
|
|
input: &'s str,
|
|
|
|
) -> Res<&'s str, StatisticsCookie<'s>> {
|
|
|
|
let (remaining, source) =
|
|
|
|
recognize(tuple((tag("["), nom::character::complete::u64, tag("%]"))))(input)?;
|
|
|
|
let (remaining, _) = space0(remaining)?;
|
|
|
|
Ok((remaining, StatisticsCookie { source }))
|
|
|
|
}
|
|
|
|
|
2023-08-11 00:04:59 +00:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-07-22 06:08:42 +00:00
|
|
|
pub fn fraction_statistics_cookie<'r, 's>(
|
|
|
|
context: Context<'r, 's>,
|
|
|
|
input: &'s str,
|
|
|
|
) -> Res<&'s str, StatisticsCookie<'s>> {
|
|
|
|
let (remaining, source) = recognize(tuple((
|
|
|
|
tag("["),
|
|
|
|
nom::character::complete::u64,
|
|
|
|
tag("/"),
|
|
|
|
nom::character::complete::u64,
|
|
|
|
tag("]"),
|
|
|
|
)))(input)?;
|
|
|
|
let (remaining, _) = space0(remaining)?;
|
|
|
|
Ok((remaining, StatisticsCookie { source }))
|
2023-07-22 05:49:07 +00:00
|
|
|
}
|