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.

Getting Started

Although PetitParser was born as part of the Helvetia infrastructure, it can be used independently. An introduction to PetitParser can be found in the following blog posts: Writing Parsers with PetitParser and Composite Grammars with PetitParser. There is a dedicated chapter on PetitParser in Deep into Pharo, and there is a chapter on using PetitParser with Moose in the Moose Book.

Pharo Smalltalk

Pharo Smalltalk is the main development environment of PetitParser. To load the core library evaluate the following code:

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 has been reported to also work in Squeak.

GNU Smalltalk

To load the package one can type:


To load the into the image do:

PackageLoader fileInPackage: 'PetitParser'

There are some differences between the official PetitParser and this port. GNU Smalltalk does not support binary selectors that have more than two characters. This means that ==> and >=> had to be mapped to something else. I have picked => and >< for now.

More details can be found in the blog article of Holger Hans Peter Freyther.

Cincom Smalltalk

This requires Cincom VisualWorks 7.7 or later:

  1. Choose ’Connect to Repository’ from the ’Store’ menu.
  2. Provide the following information in the dialog that pops up:
    • Interface: PostgreSQLEXDIConnection
    • Environment:
    • User Name: storeguest (if you have one, put yours)
    • Password: storeguest (if you have one, put yours)
    • Table Owner: BERN
  3. Click on ’Save...’ and ’Connect’.
  4. Choose ’Published Items’ from the ’Store’ menu.
  5. Load the bundle PetitParser.

Visual Smalltalk Enterprise

There is a port of PetitParser to VSE by Leandro Caniglia.


There is a version of PetitParser for Java.


There is also a version of PetitParser for Dart.


There is also a version of PetitParser for Smalltalk/X.


Please report bugs or ask questions in the Pharo or Moose mailing-lists.


PetitParser is licensed under the MIT license.


  1. Jan Kurš, Guillaume Larcheveque, Lukas Renggli, Alexandre Bergel, Damien Cassou, Stéphane Ducasse, and Jannik Laval. PetitParser: Building Modular Parsers. In Deep Into Pharo, p. 36, Square Bracket Associates, September 2013. PDF 
  2. Jan Kurš, Mircea Lungu, and Oscar Nierstrasz. Top-Down Parsing with Parsing Contexts. In Proceedings of International Workshop on Smalltalk Technologies (IWST 2014), 2014. PDF 
  3. Fabrizio Perin, Lukas Renggli, and Jorge Ressia. Natural Language Checking with Program Checking Tools. In Smalltalks 2010, 2010. PDF 
  4. Fabrizio Perin, Lukas Renggli, and Jorge Ressia. Linguistic Style Checking with Program Checking Tools. In Journal of Computer Languages, Systems and Structures, 2011. DOI PDF 
  5. Lukas Renggli, Stéphane Ducasse, Tudor Gîrba, and Oscar Nierstrasz. Practical Dynamic Grammars for Dynamic Languages. In 4th Workshop on Dynamic Languages and Applications (DYLA 2010), p. 1—4, Malaga, Spain, June 2010. PDF 
  6. Michael Rüfenacht. Enabling Software Analysis using PetitParser and Moose. Bachelor's thesis, supplementary documentation, University of Bern, August 2013. PDF 
  7. Michael Rüfenacht. Error Handling in PEG Parsers — Local Error Recovery for PetitParser. Masters thesis, University of Bern, August 2016. PDF 
  8. Attieh Sadeghi Givi. Layout Sensitive Parsing in the PetitParser Framework. Bachelor's thesis, University of Bern, October 2013. PDF 

Last changed by admin on 21 April 2009