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 4 Next »

Support for the Python target is currently only available in the source repository.
It is still under development and not yet ready for any real use.

Simple lexers and parsers are already working, but there are still many bits and pieces missing (e.g. malformed input will crash the parser or even result in an infinite loop).

Documentation

Requirements

The following Python versions are supported: 2.3 2.4 2.5

Actions

See also the caveats below (until that issue is fixed...).

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

Actions

Actions must not have any extra whitespace on the left side, antlr does not yet properly dedent action code so it will end up with too much indention in the generated code. For one-liners make sure that there is no whitespace between the '{' and the code, e.g. {print "foobar"}. For longer blocks use something like

rule:
    subrule
    {
if condition:
    print "foobar"
    }

instead of the more readable

rule:
    subrule
    {
        if condition:
            print "foobar"
    }

This has to be fixed.

  • No labels