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

Allow using arrays as input to alt #1556

Merged
merged 3 commits into from
Jul 30, 2023
Merged

Conversation

glittershark
Copy link
Contributor

Now that min-const-generics is stabilized, it's possible to (backwards-compatibly) write a version of alt that uses a const array as input instead of being limited to only tuples - this allows us to lift the 21-element limitation on tuples passed to alt.

Now that min-const-generics is stabilized, it's possible
to (backwards-compatibly) write a version of `alt` that uses a const
array as input instead of being limited to only tuples - this allows us
to lift the 21-element limitation on tuples passed to `alt`.
@Geal Geal added this to the 8.0 milestone Dec 28, 2022
@MTRNord
Copy link

MTRNord commented Jul 29, 2023

Hi,

any update on this? I am running into a case where I have a grammar with 35 cases. Obviously this doesnt't work with current nom

epage pushed a commit to epage/winnow that referenced this pull request Jul 30, 2023
Now that min-const-generics is stabilized, it's possible
to (backwards-compatibly) write a version of `alt` that uses a const
array as input instead of being limited to only tuples - this allows us
to lift the 21-element limitation on tuples passed to `alt`.

Upstream: rust-bakery/nom#1556
epage pushed a commit to epage/winnow that referenced this pull request Jul 30, 2023
Now that min-const-generics is stabilized, it's possible
to (backwards-compatibly) write a version of `alt` that uses a const
array as input instead of being limited to only tuples - this allows us
to lift the 21-element limitation on tuples passed to `alt`.

Upstream: rust-bakery/nom#1556
@Geal
Copy link
Collaborator

Geal commented Jul 30, 2023

there were a few things missing to make the DX on this reasonable, mainly having most parsers return a concrete type instead of a closure, and having a Either parser. All elements of the array have to be of the same type. Now we can revisit this :)

@Geal Geal self-requested a review as a code owner July 30, 2023 20:41
@Geal Geal merged commit 9dffd60 into rust-bakery:main Jul 30, 2023
28 checks passed
@Geal
Copy link
Collaborator

Geal commented Jul 30, 2023

great work @glittershark, thanks!

match branch.parse(input.clone()) {
for branch in &mut self.parser {
match branch.process::<OM>(input.clone()) {
//branch.parse(input.clone()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have been committed?

for branch in &mut self.parser {
match branch.process::<OM>(input.clone()) {
//branch.parse(input.clone()) {
Err(Err::Error(e)) => error = Some(e),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't oring the errors but only accepting the last one

@glittershark glittershark deleted the alt-arrays branch August 10, 2023 16:54
@Geal
Copy link
Collaborator

Geal commented Aug 10, 2023

good catch, fixed in 8c68e22

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

Successfully merging this pull request may close these issues.

None yet

4 participants