PetitParser

PetitParser makes writing parsers fast, enjoyable, and fully type-safe.

Instead of configuring external code generators or writing cryptic regular expressions, PetitParser models grammars directly as composable objects in your programming language. Assemble small, specialized parsers as modular building blocks to model everything from configuration formats to full programming languages.

Quick Look

Building a parser with PetitParser is straightforward and readable. Here is an example in Dart that recognizes key-value assignment pairs and maps them into a typed record:

import 'package:petitparser/petitparser.dart';

void main() {
  final key = letter().plus().flatten();
  final value = digit().plus().flatten().map(int.parse);
  final entry = key.trim().skip(after: char('=')).then(value.trim());

  final result = entry.parse('port = 8080');
  print(result.value); // ('port', 8080)
}

Supported Languages

PetitParser is available in many programming languages:

Examples & Grammars

Explore interactive browser playgrounds and example grammars:

Programming Languages

Interpreters & Engines

Mathematics & Expressions

Formats & Protocols

Background & Theory

PetitParser combines foundational concepts from computer science into an approachable object-oriented architecture:

PetitParser was originally created by Lukas Renggli as part of his research on the Helvetia Language Workbench at the University of Bern.

Resources