-
Notifications
You must be signed in to change notification settings - Fork 821
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
nom::branch::alt handles at most 21 parsers #1144
Comments
The trait By the way, I think it will be useful that |
Workaround: You can nest fn match_alternatives(input: &str) -> IResult<&str, &str> {
alt((
alt((
tag("alternative_01"),
tag("alternative_02"),
tag("alternative_03"),
tag("alternative_04"),
tag("alternative_05"),
tag("alternative_06"),
tag("alternative_07"),
tag("alternative_08"),
tag("alternative_09"),
tag("alternative_10"),
tag("alternative_11"),
tag("alternative_12"),
tag("alternative_13"),
tag("alternative_14"),
tag("alternative_15"),
tag("alternative_16"),
tag("alternative_17"),
tag("alternative_18"),
tag("alternative_19"),
tag("alternative_20"),
tag("alternative_21"),
)),
alt((
tag("alternative_22"),
tag("alternative_23"),
tag("alternative_24"),
tag("alternative_25"),
tag("alternative_26"),
tag("alternative_27"),
)),
))(input)
} |
Thank you for your answer. You are right, I wonder if the generated code is as efficient as if |
Thank you for your explanation, I looked at the implementation in the source code and, for what I can understand, the problem is that the source code must provide an implementation for every tuple length. I wonder if the 21 limit is somewhat a limitation of Rust or if providing a new implementation for a tuple of 22 elements could solve the problem. |
@luca-i having more or less branches in alt compared to nesting is not likely to change performance much. I just had to find an arbitrary limit and stick to it (in libstd, they limit PartialEq implementation to tuples of 12 elements max). For cases like yours nesting should be fine. |
I'm getting the same error for
If I remove the 22nd element in the I don't see that written in the documentation though? I'm new to nom, is the recommended approach here to implement a trait? |
NonAnyType has 29 arms, more than builtin-supported 21 ones Refer: rust-bakery/nom#1144
NonAnyType has 29 arms, more than builtin-supported 21 ones Refer: rust-bakery/nom#1144
Hi, I'm not sure this is a bug, maybe it is a current limitation not documented.
I think
nom::branch::alt
can currently handle only 21 parsers.rustc 1.42.0 (b8cedc004 2020-03-09)
nom = "5.1.1"
In order to get the compiler error you have to uncomment the following line inside
match_alternatives
function:// tag("alternative_22"), // uncomment to get compiler error
The error message to me is a bit unclear:
^ the trait
nom::branch::Alt<_, _, _>
is not implemented for(impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>, impl std::ops::Fn<(_,)>)
Is there a way to overcome this limitation?
Thank you, Luca-
The text was updated successfully, but these errors were encountered: