Don't raise UnusedElementError when used has more elems than Grammar#24
Merged
joente merged 1 commit intocesbit:masterfrom Mar 26, 2024
Merged
Don't raise UnusedElementError when used has more elems than Grammar#24joente merged 1 commit intocesbit:masterfrom
joente merged 1 commit intocesbit:masterfrom
Conversation
joente
approved these changes
Mar 26, 2024
Member
joente
left a comment
There was a problem hiding this comment.
I like the idea and agree with the purposed solution!
Thanks for the pull request!
joente
added a commit
that referenced
this pull request
Mar 26, 2024
…ror when used has more elems than Grammar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
Currently,
create_grammarwill check if all named Elements are used by comparing theusedvariable (which tracks the named elements found by_used_checker) withelems(which tracks the values assigned to the grammar). The comparison is done with an!=operator, which will fail for states where there are more used elements than included element.Why make this change?
This change would allow users to be assign Element names outside the grammar initialization.
I noticed this while trying to add a name to a Regex element. Normally, names are added by using a class variable assignment in
Grammar, however I have a grammar that conditionally includes Regex Elements based on user input. There are many different Regexes that could be included in the grammar, so naming them makes theResult.expectingeasier to understand.Steps to reproduce
This gives us the following state:
This fails the condition
if used != elems:and raises the following exception:Conclusion
When
int_value/float_valueare included in the grammar, they are inused, but it is not inelems, so when initializing the grammar, this raises anUnusedElementError. I felt like the correct approach was to update the logic to only raise anUnusedElementErrorwhen there are Elements inelemsthat are not inused.Let me know if there are other perspectives I should be considering. I'm not sure if it's intended for names to be manually set on Elements, but the only issue I saw was this condition, so I wanted to know if we should change it.
Great job on pyleri, btw. I love it.