Grammars for programming languages are traditionally specified statically. They are hard to compose and reuse due to ambiguities that inevitably arise. PetitParser combines ideas from scannerless parsing, parser combinators, parsing expression grammars and packrat parsers to model grammars and parsers as objects that can be reconfigured dynamically.

PetitParser for Smalltalk

PetitParser was originally implemented in Smalltalk by Lukas Renggli as a component of the Helvetia language embedding framework.

An introduction to PetitParser can be found in the blog posts Writing Parsers with PetitParser and Composite Grammars with PetitParser. There is a dedicated chapter on PetitParser in Deep into Pharo.

The framework has been ported to numerous other programming languages.

PetitParser 2

PetitParser2 is a complete reimplementation of PetitParser by Jan Kurš as part of the PetitCompiler project.

PetitParser2 runs on Pharo and is integrated into Glamorous Toolkit.

There is an extensive PetitParser2 tutorial that explains the differences with the original PetitParser. Installation instructions can be found on the PetitParser2 github repo.

Running PetitParser in Pharo

To install the original version of PetitParser in Pharo, evaluate the following code snippet:

Gofer new
    renggli: 'petit'; 
    package: 'PetitParser';

To get the full toolset, including a dedicated editor and some experimental tools, use the following Metacello script:

Gofer new
    renggli: 'petit';
    package: 'ConfigurationOfPetitParser';
(Smalltalk at: #ConfigurationOfPetitParser)
    perform: #loadDefault.


PetitParser is licensed under the MIT license.