Simple, modular and flexible high-performance parsing framework.
Introduction
Introduction to PetitParser2
Migration from PetitParser
Parser Development
Scripting with Bounded Seas
Grammar
Context-Sensitive Grammar
Abstract-Syntax Tree
Full Parser
Comments
Optimizations
Optimization (Memoization)
PetitParser2 Internals
Star Lazy (In Progress)
Caches (In Progress)
Matching Tags (In Progress)
Context-Sensitivity (In Progress)
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 #startOfLine
, #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, SmaCC
and RBParser
. Evaluate the following code:
PP2Benchmark exampleSmalltalk
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 PP2BufferStream
).
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:
PP2ReadKeysExample example
If you want to use Zinc stream, try PP2HtmlHeaderGrammar
, which can read headers of the web page, without downloading the whole page:
PP2HtmlHeaderGrammar example
With PetitParser2 you can define only part of the grammar and skip the rest. With bounded seas you define islands of interest only. Bounded seas will skip the undefined input and return only islands. For example, you can easily extract JavaScript from HTML pages.
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:
PP2Node
, not PPParser
.PP2Failure
, not PPFailure
. Failures are created using asPetit2Failure
, not asPetitFailure
.asPParser
method, not asParser
.PP2CompositeNode
, not PPCompositeParser
.PP2
prefix.PP2CompositeNode
does not support dependencies
as 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.