Vitrail is a text generator using context-free grammars, inspired by projects like Tracery, or Grammy.
It can be used on the spot by providing a grammar as a JSON file, and following the default syntax, and can also be used as a library.
I also have a Kotlin version here ;)
- Read grammar from JSON file
- Shared variables, available through all symbol expansions
- Customisable grammar syntax/operators (when used as a library)
- Potential for custom modifiers (when used as a library)
JSON Grammar file
Symbol expansion (default:
Looks up the rules corresponding to the symbol, and picks one randomly as a replacement
Variable capture (default:
variableName symbol with a static value. The rules corresponding to
symbol determine the value of
This value never changes once it's initialized.
In the example above, both
subject symbols will expand with the value coming from
Note: The placement of the variable capture matters!
The algorithm expands symbols from left to right. This means that a symbol expansion captured inside a variable is only available for expressions on its right side.
Otherwise, placement is free.
Note (expanding on the previous note):
While placement is free for now, future plans involve allowing for more granularity regarding the scope of variables.
One possibility would be to declare captures inside a symbol to make it available only inside the scope of this symbol's expansion:
In the example above,
subjectcould have different values in the expansion of
Do keep this in mind when writing your grammars.
Applies a modification on the expanded value of a symbol.
Note: while a
Modifierinterface exists, and modifiers added to the
Grammarat runtime are applied, the library does not provide any modifier yet.
Considering that the
Grammar has a modifier with the name
capitalize, that capitalizes the first letter of the value passed to it, the result of the example above would be:
Vitrail is released under MIT License