This is not an introduction to PEGs. For that I recommend leafo’s guide.
peg/leg and greg
The peg/leg parser generator is commonly used to create PEG parsers in C. The project was forked by why the lucky stiff and modified to create the greg parser generator, which is currently being de facto maintained by the ooc language.
The central difference between peg/leg and greg (aside from some minor bug fixes) is that greg can be used to construct re-entrant parsers. This means that its parsers can avoid using global variables. If you take a look at the examples that come with the peg/leg distribution, especially
basic.leg, you may notice globals which store state. This becomes a problem if you want to spin up multiple parsers at once or have a multi-threaded application.1
Apparently after _why’s fork, re-entrant parsers were made possible in peg/leg.2
Curly brace problem
The *eg family of parser generators disallow the use of curly braces within actions. This isn’t so much a bug as it is a consequence of how it parses actions.
It seems the ooc language authors and I came across the same issue while writing parsers and independently came up with the same solution, that is to use the preprocessor to substitute the appropriate curly brace symbol after the parser has been generated.
The LPeg documentation speaks about matching EOF as
lpeg.P(-1), but it makes no mention of how to match the BOF. This can be achieved using