Update pest_derive to generate a list of all rules in Rule::all_rules(). #927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.