Implement the statistics cookie parser.
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::recognize;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::util::not_yet_implemented;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use crate::parser::StatisticsCookie;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
@@ -8,6 +14,35 @@ pub fn statistics_cookie<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, StatisticsCookie<'s>> {
|
||||
not_yet_implemented()?;
|
||||
todo!()
|
||||
alt((
|
||||
parser_with_context!(percent_statistics_cookie)(context),
|
||||
parser_with_context!(fraction_statistics_cookie)(context),
|
||||
))(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
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 }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
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 }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user