Closed shnewto closed 6 years ago
Some revision needs to happen to allow Grammar::generate
to expose the functionality required for reproducible tests.
Is your rustfmt
still working? Or are we somehow on major different versions? Because when I pulled this down to play with it, my editor made a lot of auto changes. I'm on 0.9.0-nightly rustfmt
ha no the VS code started crashing my computer so I disabled it. That's a bummer about formatting, I can manually run rustfmt
on it all tho
I'd like to revise the grammar property tests to handle the excessive recursion potential as well as factor out the logic to potentially grow the stack to account for that heavy recursion.
Revised generate test.
Prior to this commit the generate tests only generated one random grammar to parse per run. This commit revises the approach and instead uses the generate function as an arbitrary property to test the the Grammar::from_str functionality with.
Additions relevant to the reopening of this PR:
First, a new error kind was introduced to indicate that the generation error isn't generic but the result of the limits of recursion being reached. This allows the property tests for the Grammar type to disregard problematic sentence generation, it is testing that what it gets is parsable.
In order to manage meeting recursion limits being met in the property tests, a new use case was accounted for, one that I belive implementaion for is useful. Logic was added to allow the "from_str" trait for bnf types to be parallel to Type::new() in all cases except the Term type. Because the Term type does not have a sensical way to implement new(), "from_str" for Term types corresponds to a Terminal rule for the empty string which is allowed in parsable gramamrs.
As this commit represents that addition of a new error kind it seemed that there is enough variety now to make our Error type public in order for users can match on them.