MCPcopy Create free account
hub / github.com/cloudflare/saffron / expr

Function expr

saffron/src/parse.rs:744–783  ·  view source on GitHub ↗

A parser that can parse delimited expressions given a parser for that part. This can't parse day of the month or week expressions.

(f: F)

Source from the content-addressed store, hash-verified

742/// A parser that can parse delimited expressions given a parser for that part.
743/// This can't parse day of the month or week expressions.
744fn expr<E, F>(f: F) -> impl Fn(&str) -> IResult<&str, Expr<E>>
745where
746 E: ExprValue + TryFrom<u8, Error = ValueOutOfRangeError> + Ord + Copy,
747 F: Fn(&str) -> IResult<&str, E>,
748{
749 move |mut input: &str| {
750 let expressions: Exprs<E>;
751 // Attempt to read a `*`. If that succeeds,
752 // try to read a `/` for a step expr.
753 // If this isn't a step expr, return Expr::All,
754 // If it's not a `*`, initialize the expressions
755 // list with an ors_expr.
756 let star = opt(char('*'))(input)?;
757 input = star.0;
758 if star.1.is_some() {
759 let slash = opt(char('/'))(input)?;
760 input = slash.0;
761 // If there is no slash after this, just return All and expect the next
762 // parser to fail if it's invalid
763 if slash.1.is_none() {
764 return Ok((input, Expr::All));
765 }
766 let step = step_digit::<E>()(input)?;
767 input = step.0;
768 expressions = Exprs::new(OrsExpr::Step {
769 start: ExprValue::min(),
770 end: ExprValue::max(),
771 step: step.1,
772 })
773 } else {
774 let expr = ors_expr::<E, _>(&f)(input)?;
775 input = expr.0;
776 expressions = Exprs::new(expr.1)
777 }
778
779 let (input, exprs) = tail_ors_exprs(input, &f, expressions)?;
780
781 Ok((input, Expr::Many(exprs)))
782 }
783}
784
785#[inline]
786fn map_digit1<E>() -> impl Fn(&str) -> IResult<&str, E>

Callers 3

minutes_exprFunction · 0.85
hours_exprFunction · 0.85
months_exprFunction · 0.85

Calls 1

tail_ors_exprsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…