1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
.. Copyright (c) 2017-2026 Juancarlo AƱez (apalala@gmail.com)
.. SPDX-License-Identifier: BSD-4-Clause
.. include:: links.rst
ANTLR Grammars
--------------
.. _grammars: https://github.com/antlr/grammars-v4
ANTLR_ (ANother Tool for Language Recognition) is one of the best known
parser generators, and it has an important collection of grammars_. The
``tatsu.g2e`` module can translate an ANTLR_ grammar to the syntax used
by |TatSu|.
The resulting grammar won't be immediately usable. It will have to be edited to
make it abide to PEG_ semantics, and in general be adapted to the way things
are done with |TatSu|.
To use ``g2e`` as a module, invoke one of its translation functions.
.. code:: python
def translate(text=None, filename=None, name=None, encoding='utf-8', trace=False):
..
For example:
.. code:: python
from tatsu import g2e
tatsu_grammar = translate(filename='mygrammar.g', name='My')
with open('my.tatsu') as f:
f.write(tatsu_grammar)
..
``g2e`` can also be used from the command line:
.. code:: bash
$ python -m tatsu.g2e mygrammar.g > my.tatsu
..
|