I'm writing an interpreter for a grammar parser generated with TatSu. I'm looking for a convenient way to generate use cases for my grammar, so I can write unit tests for my interpreter. Currently, I'm generating my test cases by hand.
I wonder if the TatSu package does provide any (maybe undocumented) means to auto-generate random grammar derivations so I could use them as test cases for my interpreter. In addition, it would be desirable to specify the grammar rule, for which I need the random productions.
If you look at the
__str__()method ingrammars.pyyou'll see an example of walking through a grammar to transform it into something readable.You could also use a
Visitor.Because the set of derivations for a grammar is potentially infinite, you need a strategy to generate some interesting samples before quitting (
Ctrl-C):|), which should be the one producing the shortest derivationBecause TatSu skips over whitespace, you'll probably need to add a step to pretty-print the output.
This is an interesting project, and it would be good if at the end you added it as a pull request to TatSu.
My apologies for providing only guidelines instead of an example.