PetitParser for Java
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 scannnerless parsing, parser combinators, parsing expression grammars and packrat parsers to model grammars and parsers as objects that can be reconfigured dynamically.
From the command line check out the code and install your own copy:
$ git clone https://github.com/petitparser/java-petitparser.git $ cd java-petitparser $ git checkout 2.0.0-alpha-2 $ mvn install
Then add the following snippet to your
<dependencies> <dependency> <groupId>com.github.petitparser</groupId> <artifactId>petitparser</artifactId> <version>2.0.0-alpha-2</version> </dependency> </dependencies>
The package comes with a large collections of grammars and language experiments ready to explore:
petitparser-jsoncontains a complete JSON grammar and parser.
petitparser-xmlcontains a complete XML grammar and parser.
petitparser-smalltalkcontains a complete Smalltalk parser.
PetitParser was originally implemented in Smalltalk. Later on, as a mean to learn these languages, I reimplemented PetitParser in Java and Dart. The implementations are very similar in their API and the supported features. If possible, the implementations adopt best practises of the target language.
The MIT License, see LICENSE.