PetitParser Examples

Pub Package Build Status Code Coverage GitHub Issues GitHub Forks GitHub Stars GitHub License

This package contains examples to illustrate the use of PetitParser. A tutorial and full documentation is contained in the package description and API documentation. petitparser.github.io contains more information about PetitParser, running examples in the browser, and links to ports to other languages.

Examples

BibTeX

A simple parser that reads a BibTeX file into a list of BibTeX entries with a list of fields.

Dart

This example contains the grammar of the Dart programming language. This is based on an early Dart 1.0 grammar specification and unfortunately does not support all valid Dart programs yet.

JSON

This example contains a complete implementation of JSON. It is a simple grammar that can be used for benchmarking with the native implementation.

Lisp

This example contains a simple grammar and evaluator for LISP. The code is reasonably complete to run and evaluate complex programs. Binaries for a Read–Eval–Print Loop (REPL) are provided for the console and the web browser.

dart run bin/lisp/lisp.dart

Math

This example contains a simple evaluator for mathematical expressions, it builds a parse-tree that can then be used to print or evaluate expressions.

Prolog

This example contains a simple grammar and evaluator for Prolog programs. The code is reasonably complete to run and evaluate basic prolog programs. Binaries for a Read–Eval–Print Loop (REPL) are provided for the console and the web browser.

dart run bin/prolog/prolog.dart

Smalltalk

This example contains a complete implementation of the Smalltalk grammar. This is a verbatim export of a grammar that was originally developed for the PetitParser infrastructure in Smalltalk and that was the base of the Helvetia Language Workbench.

URI

This is a simple grammar that takes an URL string and decomposes it into scheme, authority (including username, password, hostname, and port), path, query (including parameters as key-value pairs), and fragment.

XML

This examples parses XML files to events, creates and pretty-prints a DOM tree, and evaluates XPath expressions. Depends on xml package.

Web

To run the web examples execute the following commands from the command line and navigate to http://localhost:8080/:

dart pub global activate webdev
webdev serve --release

Benchmarks

To run the benchmarks execute the following command from the command line:

ls -1 bin/benchmark/*.dart | xargs -n 1 dart run --no-enable-asserts

Libraries

bibtex
dart
This package contains the grammar of the Dart programming language.
json
This package contains a complete implementation of JSON.
lisp
This package contains a simple grammar and evaluator for LISP.
math
This package contains a simple expression parser.
prolog
This package contains a simple grammar and evaluator for Prolog based on this blog post: https://curiosity-driven.org/prolog-interpreter.
regexp
This package contains a simple parser and evaluator for Regular Expressions.
smalltalk
This package contains the complete grammar of Smalltalk.
uri
A simple URI parser based on RFC-3986.