Skip to content

"alt" is limited on how many alternatives exist #1189

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

Closed
csarn opened this issue Aug 24, 2020 · 4 comments
Closed

"alt" is limited on how many alternatives exist #1189

csarn opened this issue Aug 24, 2020 · 4 comments

Comments

@csarn
Copy link

csarn commented Aug 24, 2020

Hi! I'm trying to write (well, to auto-generate) a disassembler using nom.
So far I have a python script that generates the nom-based parsers for all different instructions.
The problem is that alt can't take many hundreds of alternatives.

Prerequisites

Here are a few things you should provide to help me understand the issue:

  • Rust version : rustc 1.45.0 (5c1f21c3b 2020-07-13)
  • nom version : 5.1.2
  • nom compilation features used: default

Test case

The following minimal example does not compile, and I need something like that to compile.
In my case, of course, the parsers inside the alt are self-written/generated functions that are not easily
combined as in this example.

#[macro_use]
extern crate nom;
use nom::branch::alt;
use nom::IResult;
use nom::character::complete::char;

fn parse_many(i: &str) -> IResult<&str, &str> {
    alt((
        char('a'),
        char('b'),
        char('c'),
        char('d'),
        char('e'),
        char('f'),
        char('g'),
        char('h'),
        char('i'),
        char('j'),
        char('k'),
        char('l'),
        char('m'),
        char('n'),
        char('o'),
        char('p'),
        char('q'),
        char('r'),
        char('s'),
        char('t'),
        char('u'),
        char('v'),
        char('w'),
        char('x'),
        char('y'),
        char('z'),
    ))(i)
}
fn main() {
 assert!("that it compiles".len() > 0);
}

I will try to group my alt expressions, to have nested alts, but it would be nice to allow this, or at least document how to work around that limit.

@ottosson
Copy link
Contributor

You can read a bit about it here #1144

@csarn
Copy link
Author

csarn commented Aug 27, 2020

Thanks for the additional information! I did not find that issue while searching, because I limited myself to open issues.
I worked around my issue with nested alts.

I still think this necessity of nesting should appear in the documentation, so maybe this issue can stay open for the documentation fix, or should I create another issue?

@ottosson
Copy link
Contributor

It's always a good idea to check closed issues for solutions 😊

For clarity's sake I would say close this one and open another.

@csarn
Copy link
Author

csarn commented Aug 28, 2020

Closed in favor for #1192

@csarn csarn closed this as completed Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants