TatSu
TatSu copied to clipboard
Add setuptools extension to compile TatSu grammar into Python code
This is a proof of concept for an extension to setuptools that compiles a TatSu grammar into a python module at build time. I added an example of how it can be used to the tests
folder, planning to turn it into an actual test. It boils down to specifying a new keyword argument to setup()
into setup.py
in the form:
tatsu_parsers=[
"example/calc.ebnf:example.parser",
],
where the argument value is a list of strings with the path of the grammar EBNF source and the destination Python module name separated by a colon.
Documentation and tests are missing. I can add those if a tool like this is considered interesting.
This looks complicated. What would be the benefit?
The convenience is for projects using TatSu: generating the parser from the grammar at package build time would require simply adding a declaration insetup.py
. The approach is inspired by what CFFI does for generating bindings. I'm investigating whether a simpler implementation is possible giving up compatibility with old setuptools (CFFI supports very old Python and setuptools releases).
Anyhow, it is just an idea. I just published a small project that uses CFFI and I found the setuptools integration very convenient and I wanted to see how difficult it would have been to have something very similar for TatSu. Extending setuptools is definitely more complicated that what it should be, but I don't find the code too horrible either. Being convinced that the code does the right thing in all circumstances is another matter...
All in all, I don't want to push this feature too hard. I'm fine if you decide that it is not worth the trouble.
Just pushed a new version that is conceptually simpler.
This is very outdated.