G is a functional, interpreted language designed for creating random text, tables, and other game aids and features. Its flexible nature allows for other uses, especially creating test data for applications. In this article, we’ll look at the background and basics of G. You can find it on github, or check out the documentation here.

History

G began as most good things do- at the Dungeons & Dragons table. As a Dungeon Master, I soon found a need for quickly rolling complex tables. At first, I wrote these individually as Python scripts, but the boilerplate and tedium became obvious very quickly.

So, I developed the first iteration of G, an xml-based specification of a random table. Take a look at generator.py for more information. Generator.py is a good system that fulfills most of the needs, but ultimately it’s missing ease-of-use and some advanced features that I wanted to add.

Despite these flaws, Generator.py lasted for a while. I envisioned a social generator host where users could develop tables that could reference other users’ tables. Thus, I built Gengin, a now-defunct online platform for Generator.py. Gengin has several notable competitors, so I haven’t invested much time in its development since 2015.

Frustrated with the flaws of Generator.py, I sat down one weekend and wrote up the grammar of G, which I decided would be a functional, interpreted, dynamically typed language with bare strings everywhere. These design decisions were inspired by the target audience: intelligent gamers, but not necessarily programmers. Code aspects have to take a back seat to content aspects.

The Basics

The G interpreter is called Geval. It runs on Python 2.7.

$ python --version
2.7.12

Let’s load a file:

$ ./geval.py -f ./examples/planets.gn
Hello jupiter!

Generator files use the .gn suffix. Planets.gn is an extremely simple generator file used to demonstrate the most basic elements of G:

File: ./examples/planets.gn

@planet: @table(
    mercury
    | venus
    | earth
    | mars
    | jupiter
    | saturn
    | neptune
    | uranus
)

Hello `planet!

@ indicates that the element is an identifier, used by the system as a variable or protected word. In planets.gn, we create a variable called @planet, then assign a table object to it.

In the last line, we use the selector (`) syntax. The selector does its best to render the the variable in a meaningful way. For tables, this means to select an element from the table. You may also notice that G doesn’t require any type of output statement. Lines that begin with bare words are treated as output after evaluation.

In Closing

If you’re interested in exploring G, check out the documentation.

G is much more flexible that just creating single tables, and work isn’t completely done on it yet. In particular, the ability to weight and label table records for advanced generation is in development now.