Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Partially working support for the Python target is available since release 3.0b6, but you should either grab the lastest code from the source repository or use a recent daily build.

I would consider it to be in early beta state. This means that most parts are working (big exceptions are ST output and tree parser 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).

Please send bugreports, feedback, patches to me or the antlr-interest mailing list

Credits go to Clinton Roy for the code to support output=AST.

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 for import 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

Don't use TABs

Make sure that your editor is using spaces for indention, when you are editing your grammar files. The generated code uses spaces and when your actions are copied into the output, TABs will only cause confusion. A warning should be generated, when ANTLR stumples upon TABs.

NotImplementedErrors and FIXMEs

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=template
  • Tree parsers
  • ... (I still have to work my way through The Book - perhaps I'll stumble upon more stuff that I have not yet considered)
  • No labels