TatSu icon indicating copy to clipboard operation
TatSu copied to clipboard

Add setuptools extension to compile TatSu grammar into Python code

Open dnicolodi opened this issue 2 years ago • 4 comments

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.

dnicolodi avatar Jul 29 '22 20:07 dnicolodi

This looks complicated. What would be the benefit?

apalala avatar Jul 30 '22 12:07 apalala

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).

dnicolodi avatar Jul 30 '22 12:07 dnicolodi

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.

dnicolodi avatar Jul 30 '22 13:07 dnicolodi

Just pushed a new version that is conceptually simpler.

dnicolodi avatar Jul 30 '22 15:07 dnicolodi

This is very outdated.

apalala avatar Dec 14 '23 23:12 apalala