/trako

RR - Railroad Diagram Generator

Primary LanguageJavaApache License 2.0Apache-2.0

Trako

Update: Nowadays, the original RR is available on Maven Central and offers an embeddable library. Therefore, this fork has served its purpose. 🎉


Trako is a generator of syntax diagrams, also known as railroad diagrams.

Besides generating diagrams from EBNF rules, Trako can also perform some grammar transformation, e.g. factorization and elimination of direct recursion. To some extent this transforms BNF to EBNF, yielding more compact diagrams.

️Trako is based on the excellent RR by Gunther Rademacher. Trako was created to make the RR diagram generator available to other applications and to add distribution via Maven Central. Since PR #14 and PR #22 were merged, Trako is no longer needed. ⚠️

By the way, the name "Trako" is the word for "track" in Esperanto.

Examples

Here are two examples of generated diagrams (taken from the Python grammar):

if_stmt:

if_stmt

try_stmt:

try_stmt

Grammar syntax

Trako accepts grammars in W3C-style EBNF. Some other representations, including some parser generator input notations, can be converted to W3C-style using Grammar Conversion.

Distribution

There are two flavors of Trako: a library for use with other applications and an all-in-one JAR for CLI use. Both are available on Maven Central.

Maven Central

In the examples below, VERSION must be replaced with the desired version.

Library usage

via Maven:

<dependency>
    <groupId>com.github.bannmann.trako</groupId>
    <artifactId>trako</artifactId>
    <version>VERSION</version>
</dependency>

CLI usage

To generate a diagram, run e.g.

   java -jar trako-VERSION-all.jar grammar.ebnf

For listing the full set of available options, run

   java -jar trako-VERSION-all.jar

without further command line arguments.

License

Trako is released under the Apache 2 License.