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
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 optimize
before parse:
.
Try it out! Compare the optimized version of PP2SmalltalkParser
, non-optimized version, SmaCC
and RBParser
. Evaluate the following code:
PP2Benchmark exampleSmalltalk
PetitParser2 applies many optimizations to reduce the overhead of context-sensitive combinators, when used in optimized mode.
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:
PP2ReadKeysExample example
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 GToolkit
and Roassal2
dependencies):
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 PetitParser2. In the tutorial we cover all the topics related to PetitParser2. We discuss PetitParser2 best practices, testing, abstract syntax tree generation, optimizations or even context-sensitive parsing.
https://kursjan.github.io/petitparser2/
Feel free to open an issue or post a StackOverflow question with the petitparser2
tag.