Skip to content
Discussion options

You must be logged in to vote

The problem is alt. It always ends with the last error.

One option is to use cut_err to "commit" to the result of one branch of alt

/*
[dependencies]
winnow = "0.7"
*/
use winnow::{
    combinator::{alt, not, cut_err},
    error::{StrContext, StrContextValue},
    Parser as _, ModalResult,
};

fn multi<'s>(input: &mut &'s str) -> ModalResult<(&'s str, ())> {
    (
        "/**",
        cut_err(not('*'))
            .context(StrContext::Label("delimiter"))
            .context(StrContext::Expected(StrContextValue::Description("/**"))),
    )
        .parse_next(input)
}

fn single<'s>(input: &mut &'s str) -> ModalResult<(&'s str, ())> {
    ("///", cut_err(not('/'))).parse_next(input)
}

fn 

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@epage
Comment options

epage May 1, 2025
Maintainer

@beeb
Comment options

@beeb
Comment options

@epage
Comment options

epage May 1, 2025
Maintainer

@beeb
Comment options

Answer selected by beeb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants