Skip to content

How to get try_map to cut? #435

Answered by epage
viridia asked this question in Q&A
Jan 23, 2024 · 1 comments · 13 replies
Discussion options

You must be logged in to vote

What I overlooked in my message and yours is that ErrMode::from_external_error creates a backtracking error by default. You need to append .cut() to it to make it work.

Couple of tips

  • Put #[track_caller] on run_parser_err and run_parser so you can more easily tell what failed
  • Change assert!(err.contains("invalid property name:")); to assert!(err.contains("invalid property name:"), "{err}"); so you have context on the failures.
  • Something that can help a lot is if you wrap your parsers in trace parsers, like:
fn style_prop(input: &mut &str) -> PResult<StyleProp> {
    winnow::trace::trace("style_prop", |input: &mut _| {
    let (name, _, _, (_, value, _, _, _)) = (
        prop_name,

Replies: 1 comment 13 replies

Comment options

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

@viridia
Comment options

@viridia
Comment options

@epage
Comment options

Answer selected by viridia
@epage
Comment options

@epage
Comment options

@viridia
Comment options

@epage
Comment options

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