pub(crate) fn dynamic_context<I: Clone, C, E: DynamicParseError<I>, F, O>(
    context_creator: C,
    mut f: F,
) -> impl FnMut(I) -> nom::IResult<I, O, E>
where
    C: Fn() -> String,
    F: Parser<I, O, E>,
{
    move |i: I| match f.parse(i.clone()) {
        Ok(o) => Ok(o),
        Err(nom::Err::Incomplete(i)) => Err(nom::Err::Incomplete(i)),
        Err(nom::Err::Error(e)) => Err(nom::Err::Error(E::add_dynamic_context(
            i,
            context_creator(),
            e,
        ))),
        Err(nom::Err::Failure(e)) => Err(nom::Err::Failure(E::add_dynamic_context(
            i,
            context_creator(),
            e,
        ))),
    }
}
/// This is used mainly as the [dynamic_context] combinator, to add user friendly information
/// to errors when backtracking through a parse tree.
/// It works by executing the callback function context_creator to get a dynamic String,
/// which is then stored in the error as context
/// (this execution only happens in the case of parsing errors).

This is used mainly as the [dynamic_context] combinator, to add user friendly information
to errors when backtracking through a parse tree.
It works by executing the callback function context_creator to get a dynamic String,
which is then stored in the error as context
(this execution only happens in the case of parsing errors).
This is used mainly as the [ dynamic_context ] combinator to add user friendly information to errors when backtracking through a parse tree . It works by executing the callback function context_creator to get a dynamic String which is then stored in the error as context ( this execution only happens in the case of parsing errors ) .
pub(crate) fn dynamic_context<I: Clone, C, E: DynamicParseError<I>, F, O>(
    context_creator: C,
    mut f: F,
) -> impl FnMut(I) -> nom::IResult<I, O, E>
where
    C: Fn() -> String,
    F: Parser<I, O, E>,
{
    move |i: I| match f.parse(i.clone()) {
        Ok(o) => Ok(o),
        Err(nom::Err::Incomplete(i)) => Err(nom::Err::Incomplete(i)),
        Err(nom::Err::Error(e)) => Err(nom::Err::Error(E::add_dynamic_context(
            i,
            context_creator(),
            e,
        ))),
        Err(nom::Err::Failure(e)) => Err(nom::Err::Failure(E::add_dynamic_context(
            i,
            context_creator(),
            e,
        ))),
    }
}
pub ( crate ) fn dynamic_context < I : Clone , C , E : DynamicParseError < I > , F , O > ( context_creator : C , mut f : F , ) -> impl FnMut ( I ) -> nom :: IResult < I , O , E > where C : Fn ( ) -> String , F : Parser < I , O , E > , { move | i : I | match f . parse ( i . clone ( ) ) { Ok ( o ) => Ok ( o ) , Err ( nom :: Err :: Incomplete ( i ) ) => Err ( nom :: Err :: Incomplete ( i ) ) , Err ( nom :: Err :: Error ( e ) ) => Err ( nom :: Err :: Error ( E :: add_dynamic_context ( i , context_creator ( ) , e , ) ) ) , Err ( nom :: Err :: Failure ( e ) ) => Err ( nom :: Err :: Failure ( E :: add_dynamic_context ( i , context_creator ( ) , e , ) ) ) , } }
This is used mainly as the [dynamic_context] combinator, to add user friendly information
to errors when backtracking through a parse tree.
This is used mainly as the [ dynamic_context ] combinator to add user friendly information to errors when backtracking through a parse tree .
context_creator
C
f
F
context_creator
C
f
F