PetitParser2 is a new version of PetitParser that allows one to define flexible and high-performance parsers.
- Modular, composable and easy to extend
- Natural, easy-to-follow definitions
- High performance
- Supports context-sensitive parsing
- Supports tolerant parsing
- Rich IDE support
Why to switch from PetitParser to PetitParser2?
The performance of PetitParser2 is 2-5 times faster compared to PetitParser when used in optimized mode. The optimizations are based on the technologies of PetitCompiler. To optimize, simply call
Try it out! Compare the optimized version of
PP2SmalltalkParser, non-optimized version,
RBParser. Evaluate the following code:
Much faster context-sensitive parsing
PetitParser2 applies many optimizations to reduce the overhead of context-sensitive combinators, when used in optimized mode.
Support for real streams
PetitParser2 supports real streams - no need to have the whole input in memory (see
PP2BufferStream). The following demo utilizes a parser created on top of a character stream coming from your keystrokes. The parser waits for input from the keyboard and proceeds with parsing as characters come in:
Support for bounded seas
With PetitParser2 you can define only part of the grammar and skip an uninteresting input. Bounded seas are extensible so you can always add more rules to your grammar to extract more data.
Use the configuration manager in your Pharo image and install the stable version.
Installing standard version for the latest Pharo:
Metacello new baseline: 'PetitParser2'; repository: 'github://kursjan/petitparser2'; load.
To install graphical tools (with
Metacello new baseline: 'PetitParser2Gui'; repository: 'github://kursjan/petitparser2'; load.
To install experimental tools, e.g., RewriteEngine, use:
Metacello new baseline: 'PetitParser2Experimental'; repository: 'github://kursjan/petitparser2'; load.
To install a core with minimal external dependencies, use:
Metacello new baseline: 'PetitParser2Core'; repository: 'github://kursjan/petitparser2'; load.
Here you can find an illustrative explanation how to debug when parsers do not work as expected.
Learn more about PetitParser. In the book we cover all the topics related to PetitParser. We discuss basics of parsing such as testing or AST generation as well as advanced topics including context-sensitive parsing or optimizations.