Support for the Python target is currently only available in the source repository.
I would consider it to be in early beta state. This means that most parts are working (one big exception is AST and ST output stuff), but bugs and problems are to be expected and documentation is pretty poor. It still has to prove itself in a real world application (which is currently being done).
Documentation
Documentation is one of the missing pieces... Have a peek at the testcases in lib/Python/tests to get an idea how to invoke lexers/parsers from python.
Requirements
The following Python versions are supported: 2.3 2.4 2.5
Actions
This target currently supports the action scopes @lexer
and @parser
for global actions. The following action names are known:
header
- Will be inserted right after ANTLRs own imports at the top of the generated file. Use it forimport
statements or any other functions/classes which you need in the module scope.init
- Will be inserted at the end of the__init__
method of the lexer/parser. Here you can setup your own instance attributes.members
- Will be inserted in the class body of the lexer/parser right after__init__
. This is the right place for custom methods and class attributes.
Caveats
{{NotImplementedError}}s and {{FIXME}}s
There are still some white areas on the map. Mostly because I was not able to find a grammar that triggered the usage of specific templates in Python.stg
. If your grammar fails with NotImplementedError
exceptions or references to FIXME
, you have just found such a case and I'd be happy to have a peek at your grammar.
Unsupported features
- output=(AST|template)
- ... (I still have to work my way through The Book - perhaps I'll stumble upon more stuff that I have not yet considered)