The faster monadic parser combinator library for C#
This library provides most useful Text Parsers, Stream Parsers, and Parser Combinators. All APIs are pure, immutable, can combine any others. Designed to utilize JIT Compilers optimization, realizes completely immutable, and can parse infinitely recursive data structures.
This project is affected by parsec, monadic parser library for Haskell.
- Easy construction APIs with monad on C#
- Pure/Immutable/Functional framework on C#
- Replace regular expressions on your code (applicable from smallest to largest)
- Most readable APIs source code
- Strictly typed parsers/combinators that support natural type inference
- A lot of reasonable built-in parsers/combinators
- Supports parsing infinitely recursive data structures
- Supports full backtracking: Parsing Expression Grammar (PEG) style parsing strategy
- Supports parsing streams with any token type (e.g. string, char stream, byte array, binary stream)
- Supports tokenization
- Supports partial parsing
- Supports nullable reference types (with C# 8.0 or later)
- No additional dependencies
- Faster running
- Just enough error messages
- No left-recursion support
- No packrat parsing support (because it increases parsing time in most cases)
dotnet-cli:
$ dotnet add package ParsecSharp
NuGet Package Manager Console:
> Install-Package ParsecSharp
PackageReference:
<ItemGroup>
<PackageReference Include="ParsecSharp" Version="*" />
</ItemGroup>
Download manually:
- netstandard2.0 (compatible with net461 or later, uap, xamarin and more)
- netstandard2.1 (compatible with netcoreapp, net5.0 or later, some performance improvements and additional APIs that depend on new runtime features)
Requires C# 7.3 or later for generic overloading resolution.
- Add package reference to your project.
- Add using directive:
using static ParsecSharp.Parser;
andusing static ParsecSharp.Text;
to your code. - Parse your all.
Implementation examples:
- JsonParser implementation
- CsvParser implementation
- Arithmetic expression parser implementation
- PEG parser generator implementation
Documents are included in UnitTest code (jp).
If you want more information, read APIs source code, all is there.
Feel free to create an Issue!
This software is released under the MIT License, see LICENSE.