Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatch! unable to handle cfg attributes #609

Open
2 tasks done
zeenix opened this issue Oct 20, 2024 · 0 comments · May be fixed by #619
Open
2 tasks done

dispatch! unable to handle cfg attributes #609

zeenix opened this issue Oct 20, 2024 · 0 comments · May be fixed by #619
Labels
A-combinator Area: combinators C-bug Category: Things not working as expected

Comments

@zeenix
Copy link

zeenix commented Oct 20, 2024

Please complete the following tasks

rust version

1.81.0

winnow version

0.6.13

Minimal reproducible code

fn main() {
    use winnow::combinator::{dispatch, empty, fail, preceded};
    use winnow::prelude::*;
    use winnow::token::any;

    fn escaped(input: &mut &str) -> PResult<char> {
        preceded('\\', escape_seq_char).parse_next(input)
    }

    fn escape_seq_char(input: &mut &str) -> PResult<char> {
        dispatch! {any;
            'b' => empty.value('\u{8}'),
            #[cfg(unix)]
            '"' => empty.value('"'),
            _ => fail::<_, char, _>,
        }
        .parse_next(input)
    }

    assert_eq!(escaped.parse_peek("\\b\""), Ok(("\"", '\u{8}')));
}

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

   Compiling tmp-unpavh v0.1.0 (/home/zeenix/.cache/cargo-temp/tmp-UNpAvH)
error: no rules expected the token `#`
  --> src/main.rs:13:13
   |
13 |             #[cfg(unix)]
   |             ^ no rules expected this token in macro call
   |
note: while trying to match meta-variable `$pat:pat`
  --> /home/zeenix/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winnow-0.6.20/src/macros/dispatch.rs:43:30
   |
43 |     ($match_parser: expr; $( $pat:pat $(if $pred:expr)? => $expr: expr ),+ $(,)? ) => {
   |                              ^^^^^^^^

warning: unused imports: `empty` and `fail`
 --> src/main.rs:2:40
  |
2 |     use winnow::combinator::{dispatch, empty, fail, preceded};
  |                                        ^^^^^  ^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `winnow::token::any`
 --> src/main.rs:4:9
  |
4 |     use winnow::token::any;
  |         ^^^^^^^^^^^^^^^^^^

warning: `tmp-unpavh` (bin "tmp-unpavh") generated 2 warnings
error: could not compile `tmp-unpavh` (bin "tmp-unpavh") due to 1 previous error; 2 warnings emitted

Expected Behaviour

Code should compile and run successfully (on unix systems).

Additional Context

@epage Hello from China. :)

@zeenix zeenix added the C-bug Category: Things not working as expected label Oct 20, 2024
@epage epage added the A-combinator Area: combinators label Oct 21, 2024
@39555 39555 linked a pull request Nov 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-combinator Area: combinators C-bug Category: Things not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants