Why should you migrate to PetitParser2? If you find one of these interesting:
PetitParser2 is still actively maintained. By the author of PetitParser2 and by the Moose community.
PetitParser2 can express everything PetitParser can and more.
For example, there are predicates such as
#endOfLine, which are not available in PetitParser.
The performance of PetitParser2 is 2-5 times better compared to PetitParser. The optimizations are based on our experience with PetitCompiler.
Try it out! Compare the optimized version of
PP2SmalltalkParser, non-optimized version,
RBParser. Evaluate the following code:
You can see that PetitParser2 is as fast as SmaCC while having all the advantages of PetitParser.
PP2 parsers can be optimized by calling
optimize method on the resulting parser.
PetitParser2 supports real streams: no need to load the whole input into the memory (see
Try to parse an input comming from your keystrokes.
The following parser waits for the input from a keyboard does parsing as characters come in:
If you want to use Zinc stream, try
PP2HtmlHeaderGrammar, which can read headers of the web page, without downloading the whole page:
With PetitParser2 you can parse more languages than PEGs can express. PetitParser2 contains an extension for parsing context sensitive grammars.
How is PetitParser2 different to PetitParser? To increase performance, PetitParser2 decouples the parsing strategy from the parser structure while preserving the PetitParser interface. The parsing strategy is replaced behind the scenes and is mostly transparent for the end user.
The differences are:
PPFailure. Failures are created using
PP2CompositeNodedoes not support
PPCompositeParser. I am not aware of any use-case for dependencies, so I didn’t migrated the functionality. Let me know if there is a use-case for you.