-
Notifications
You must be signed in to change notification settings - Fork 22
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
Reworked generate #127
Reworked generate #127
Conversation
…pable production or terminating expression
…at the grammar can actually reach a terminal state
Another couple notes. First, this opens the door to being able to better set some "min" and "max" for generated output but that seems to me better served by another PR. as it stands, if you generate with this grammar from the docs:
you're going to get the same, pretty random, non-deterministic output, i.e.
Second! I'm still kind of toying with the idea of changing the signature on generate to take an optional starting rule, i.e. the LHS of the prod you want to "start" generating from. On one hand, it means maybe if you want to generate from different parts of a large grammar, you can more readily. On the other, it clutters the invocation with a parameter that if you don't want to use it, have to deal with passing Maybe... that could be another PR and instead of adding an Option to the |
…ll in some holes in the function docs
woah that clippy action is great, will address those fixes a bit later but also, TIL that default |
Yeah since I personally think |
Implementation
A swing at addressing #70 though rather than getting any smarter about how we actually generate sentences (that can surely be improved someday), the changes in this PR implement checks that generation can succeed. Aside from the tests, and a couple little things
cargo fmt
threw in there, the actual implementation is relatively short, thanks to the proposal from @notDhruv, that served me well ❤️That proposal was for implementation that effectively lets us decide if generation can succeed lives here #70 (comment)
I was happy to follow it to the letter, though one note if you're looking at the code, in my implementation "marking" non-terminals means adding them to a
Vec
calledterminating_rules
Heads Up
This represents a breaking change! (though a great one imo) It removes the
RecursionLimit
error, and previously, you could generate from grammars that didn't hit a terminal state, they'd just print what they had, including the string representation of non-terminals if that's all there was. Now, that's not the case :)