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

Update pest_derive to generate a list of all rules in Rule::all_rules(). #927

Merged
merged 2 commits into from
Sep 15, 2023

Conversation

davidsantiago
Copy link
Contributor

This function returns all variants of the generated Rule so that they can be enumerated/searched for/etc. Also updated the tests to reflect the new output.

The motivation for this is that I'd like to write a program to automatically verify some properties of the grammar that I'm working on, but the Rule type that is used by the generated parser is an enum. The Rust language doesn't provide any way to enumerate an enum unless you make a matching variable to hold all the variants and keep it in sync fastidiously (this kind of thing makes me tired and anxious). There are crates like strum that automate this, of course, but pest doesn't currently depend on any of those.

This change just makes the generator also produce a function that returns a variable with all of the Rule variants. That is just enough that you can iterate through all of the rules in the grammar, and with the generated Debug trait on Rule, you could also make yourself a way to look up a Rule variant by its name if you need that (I do).

I've already gotten my main program working with this change, so I'm hoping you guys are open to something like this. Happy to iterate.

This function returns all variants of the generated Rule so that they
can be enumerated/searched for/etc.
@davidsantiago davidsantiago requested a review from a team as a code owner September 14, 2023 08:17
@davidsantiago davidsantiago requested review from tomtau and removed request for a team September 14, 2023 08:17
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

@davidsantiago
Copy link
Contributor Author

I'm very happy to make this change, but I don't understand what is being indicated here...

@davidsantiago
Copy link
Contributor Author

I think I figured out what was going on, giving this a shot.

@tomtau tomtau merged commit 8799c8e into pest-parser:master Sep 15, 2023
9 checks passed
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.

2 participants