PetitParser for Dart
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.
An introductionary tutorial is part of the class documentation.
Add the dependency to your package's pubspec.yaml file:
dependencies: petitparser: ">=1.0.0 <2.0.0"
Then on the command line run:
$ pub get
To PetitParser in your Dart code write:
The package comes with a large collections of grammars and language experiments ready to explore:
lib/dart.dartcontains an experimental Dart grammar.
lib/json.dartcontains a complete JSON grammar and parser.
lib/lisp.dartcontains a complete Lisp grammar, parser and evaluator:
example/lisphellcontains a command line lisp interpreter.
example/lispwebcontains a web based lisp interpreter.
lib/smalltalk.dartcontains a complete Smalltalk grammar.
Furthermore, there are various open source projects using PetitParser:
- dart-xml is a lightweight library for parsing, traversing, and querying XML documents.
- Haml.dart is an implementation of Haml in Dart.
- RythmDart is a rich featured, high performance template engine.
- SharkDart is a small template engine.
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.
This package contains a experimental features of PetitParser. The code here might be removed or changed in incompatible ways without keeping backward compatibility.
This package contains a complete grammar of the Dart programming language.
This package contains some simple debugging tools.
This package contains a complete implementation of JSON.
This package contains a simple grammar and evaluator for LISP.
This package contains the core library of PetitParser, a dynamic parser combinator framework.
This package contains tools to reflect on and transform parsers.
This package contains the complete grammar of Smalltalk.
This package contains matches to write tests for parsers.