Fast and lightweight parser creation tools
Parlot is a fast, lightweight and simple to use .NET parser combinator.
Parlot provides a fluent API based on parser combinators that provide a more readable grammar definition.
| Branch | Purpose | Package feed |
|---|---|---|
release/1.x |
Maintenance of stable Parlot 1.x releases. | |
main |
Development of Parlot 2.0, including source-generated parsers. |
Tagged releases are published to NuGet.org,
using the feed https://api.nuget.org/v3/index.json. To install the latest stable version:
dotnet add package ParlotAfter a successful Ubuntu build triggered by a push to main, the workflow publishes preview packages to the
Parlot feed on feedz.io.
Versions follow 2.0.0-preview-, using the GitHub Actions build run number.
These packages contain the latest development changes and are intended for testing before release.
Add the preview feed alongside NuGet.org, then install the latest prerelease version:
dotnet nuget add source https://f.feedz.io/sebastienros/parlot/nuget/index.json --name parlot-preview
dotnet add package Parlot --prereleaseKeep NuGet.org enabled so dependencies can be restored. If your NuGet.config uses package source
mapping, also map Parlot to the parlot-preview source.
The Fluent API provides simple parser combinators that are assembled to express more complex expressions. The main goal of this API is to provide an easy-to-read grammar. Another advantage is that grammars are built at runtime, and they can be extended dynamically.
To use the Fluent API, you need to import the static Parsers class which provides access to Terms, Literals, and other parser combinators:
using Parlot.Fluent;
using static Parlot.Fluent.Parsers;Important: The
using static Parlot.Fluent.Parsers;statement is required to accessTerms,Literals,ZeroOrOne,Between, and other parser combinators used in the examples below.Alternatively, if your project has
ImplicitUsings(also known as Global Usings) enabled, this import is included automatically.
The following example is a complete parser that creates a mathematical expression tree (AST). The source is available here.
…Parlot's analyzer generates direct parsing methods during the normal build. Generated code and shared internal support sources compile into your assembly, with no Parlot runtime dependency.
Parlot.SourceGenerator package with PrivateAssets="all".bool TryParse(string text, out T value) method in a normal .cs file..parlot.cs file with [GenerateParser(nameof(TryParse))].If, Select, or other supported parse-time callbacks in the matching factory.Application code, in MyGrammar.cs:
public static partial class MyGrammar
{
public static partial bool TryParse(string text, out string value);
}
// Usage: MyGrammar.TryParse("hello", out var value)Build-only grammar, in MyGrammar.parlot.cs:
using Parlot.SourceGenerator;
using Parlot.Fluent;
using static Parlot.Fluent.Parsers;
public static partial class MyGrammar
{
[GenerateParser(nameof(TryParse))]
private static Parser Build() => Terms.Text("hello").Eof();
}net472, netstandard2.0, net8.0, and net10.0; older targets use compatibility packages such as System.Memory, not Parlot.CancellationToken before the out result to enable cooperative cancellation, without adding it to the grammar factory.partial.Additional attributes can be combined with [GenerateParser]:
[IncludeFiles("*.cs")] – Include source files (supports globs) for types used by your parser.[IncludeUsings("Namespace")] – Add extra using directives to generated code.[IncludeGenerators("AssemblyName")] – Run other source generators before parser generation.For detailed documentation, see Source Generation Guide.
Why use source generation?
- Inlined parsing without combinator dispatch
- Faster startup (no runtime parser graph construction)
- AOT-friendly, deterministic parser code
- No Parlot assembly or package dependency for downstream consumers
Parlot is faster and allocates less memory than all other known parser combinators for .NET.
It was originally created to provide a more efficient alternative to projects like:
Finally, even though Pidgin showed some very good performance, Parlot is still faster.
The tables below were measured on September 7, 2026 using the current dependency-free generated parsers.
All 41 cases use BenchmarkDotNet's out-of-process ShortRun job, with three warmup and three measurement
iterations. These are short-run estimates; consider the reported error bounds when comparing timings.
To reproduce:
dotnet build -c Release
dotnet run --project test/Parlot.Benchmarks/Parlot.Benchmarks.csproj -c Release --no-build -- --filter "*ExprBench*" "*JsonBench*" "*RegexBenchmarks*"This benchmark creates an expression tree (AST) representing mathematical expressions with operator precedence and grouping. It exercises three expressions:
3 - 1 / 2 + 11 - ( 3 + 2.5 ) * 4 - 1 / 2 + 1 - ( 3 + 2.5 ) * 4 - 1 / 2 + 1 - ( 3 + 2.5 ) * 4 - 1 / 2-(3 + 2) * -4 + --6The benchmark compares Raw, Fluent, and source-generated Parlot parsers with Pidgin. It parses the expressions into the same AST without evaluating them.
In these results, Parlot Fluent is about 12-13 times faster than Pidgin and Parlot Raw is faster still. The source-generated parser takes about 20-26% less time than Fluent and allocates 144 fewer bytes per parse in all three expressions. Generated helpers use normal JIT inlining heuristics to avoid expanding large parser chains into oversized native methods.
…This benchmark was taken from the Pidgin repository and demonstrates how to perform simple JSON document parsing. It exercises the parsers with different kinds of documents. Pidgin, Sprache, Superpower and Parlot are compared. The programming models are all based on parser combinators. For reference, Newtonsoft.Json is also added to show the differences with a dedicated parser. The benchmark compares Fluent and source-generated Parlot parsers with Pidgin, Sprache, Superpower, Newtonsoft.Json, and System.Text.Json. For most documents, the best JSON parser is System.Text.Json; don't build your own!
…Regular expressions can also be replaced by more formal parser definitions. The following benchmarks show how Parlot compares to them when checking if a string matches
an email with the pattern [\w\.+-]+@[\w-]+\.[\w\.-]+. Note that in the case of pattern matching Parlot can use the pattern matching mode and do fewer allocations.
The benchmark compares regular, compiled, and source-generated .NET regular expressions with Fluent and source-generated Parlot parsers.
…The benchmarks were executed with the following versions:
Parlot supports intuitive operators for parser composition:
+ operator: Combines parsers in sequence (alternative to .And())| operator: Creates choice between parsers (alternative to .Or())// Using operators
var parser = Literals.Char('a') + Literals.Char('b') + Literals.Char('c');
var choice = Literals.Char('x') | Literals.Char('y') | Literals.Char('z');
// Equivalent to
var parser = Literals.Char('a').And(Literals.Char('b')).And(Literals.Char('c'));
var choice = Literals.Char('x').Or(Literals.Char('y')).Or(Literals.Char('z'));Parlot is already used in these projects:
No open issues yet, or sync has not completed.