Summary

I share a grammar for Ohm and a diagram to go with it.

Make-Work

This grammar - ohm in Ohm - already exists in the source code for the Ohm-JS compiler. For reasons not well understood, I backed into creating my own grammar from scratch.

Diagram of the Grammar

In the process, I drew myself a diagram (using draw.io) which can be seen in the SVG Diagram and in the README of the ohm-parse github.

Diagram Notation for Grammars

I think that I found a consistent diagrammatic notation for all constructs in the grammar.

Transpiler

I went on to build a transpiler using this grammar.

I used my glue1 DSL for the transpiler.

Testing

Identity Transform

I began by creating an identity transformation which sanity-checks the glue file by outputting the input after parsing it (a big fat no-op, but satisfying nonetheless).

Grammar Checking

Sanity-checking the grammar was done using the Ohm editor and various test samples, culminating in testing the whole of the grammar on itself.

Disclaimer

This stuff is dripping fresh and probably contains errors, but, I hope that it will be of use to someone in understanding how to create a grammar (or, at least, understanding how I do it).

Future

I intend to use this grammar to do some of my editing work for me - just enough to trade off the development time against the boring task of typing a glue specification for another project.

The beginnings of this partial-editor can be seen in emitglue.ohm and emitglue.glue.

I don’t intend to make the partial-editor complete. I will stop working on it when I think that editing the result manually will take less time that tweaking emitglue.glue.

Cannot Use Sed and Awk and REGEXs

Normally, I would use sed or awk or regular expressions to hack code for me, but, in this case, I needed to match structured blobs of code that would be best done with something better than REGEX, i.e. by using a parser.

Prep

I intend to use my prep 2 tool in combination with the .ohm and .glue files to give me a command-line code hacking utility.

Prep uses Ohm-JS to parse text code from stdin and uses glue to reformat the text code.

Prep is also dripping fresh, but, is based on experience with previous tools like pfr.

See Also

Table of Contents
Blog
Videos
References