A lightweight, fast, and flexible parser combinator library for C#.
Pidgin is a lightweight and fast parser combinator library for C# that allows developers to build parsers directly in C# code. It solves the problem of parsing structured text or binary data by providing a declarative, composable API that is more expressive than regular expressions and easier to use than parser generators. It supports arbitrary token types, streaming input, and includes tools for parsing expression grammars.
C# developers who need to parse custom text formats, domain-specific languages, configuration files, or data interchange formats like JSON or XML subsets. It is particularly useful for those who prefer an embedded, code-based approach over external tooling.
Developers choose Pidgin for its combination of performance, flexibility, and simplicity. It offers a pure C# implementation with minimal allocation, controlled backtracking, and support for streaming inputs, making it a practical alternative to libraries like Sprache or FParsec for C# projects.
A lightweight and fast parsing library for C#.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Benchmarks in the README show Pidgin is faster and allocates less memory than Sprache and Superpower, making it efficient for parsing large inputs.
It can parse sequences of any token type, enabling use with binary formats or tokenized inputs, as highlighted in the comparison to Sprache.
Supports parsing from streaming sources like TextReader or IEnumerable, allowing efficient handling of large or continuous data without full memory loads.
Uses the `Try` combinator to enable backtracking only where needed, optimizing performance by avoiding unnecessary buffer overhead, unlike Sprache's automatic backtracking.
Pidgin does not support left-recursive grammars, requiring manual rewriting of such rules, which can complicate parsing certain languages like arithmetic expressions.
Due to being a struct, parsers don't support covariance in type parameters, causing compilation errors when assigning derived types, as explained in the variance note.
Using LINQ query syntax can increase garbage allocation, as mentioned in speed tips, potentially hurting performance in critical applications.