ParsecSharp 4.0.0

dotnet add package ParsecSharp --version 4.0.0                
NuGet\Install-Package ParsecSharp -Version 4.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ParsecSharp" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ParsecSharp --version 4.0.0                
#r "nuget: ParsecSharp, 4.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ParsecSharp as a Cake Addin
#addin nuget:?package=ParsecSharp&version=4.0.0

// Install ParsecSharp as a Cake Tool
#tool nuget:?package=ParsecSharp&version=4.0.0                

ParsecSharp

NuGet

The faster monadic parser combinator library for C#

[!Important]

ParsecSharp v4 has some major breaking-changes from v3. Please check the following notes.

The basic parser type is now an interface IParser<TToken, T>, instead of a class Parser<TToken, T>

The main data types like Parser, Result, Success and Failure have been changed to interfaces to enable covariant result types. To follow this change, you can simply rename it, and it should work.

- private static readonly Parser<char, int> integer = Many1(DecDigit()).ToInt();
+ private static readonly IParser<char, int> integer = Many1(DecDigit()).ToInt();
The operator | for Choice composition is no longer available in netstandard2.0

Unfortunately, netstandard2.0 doesn't support binary operator overloading for interfaces. Please use netstandard2.1 compatibles, or rewrite it with other combinators that have the same semantics.

var textChar = unescapedChar | escapedChar; // no longer available in netstandard2.0
var textChar = unescapedChar.Or(escapedChar); // use Or combinator
var textChar = Choice(unescapedChar, escapedChar); // use Choice combinator

What's this

This library provides the most useful Text Parsers, Stream Parsers, and Parser Combinators. All APIs are pure, immutable, and can combine with any others. Designed to utilize JIT Compiler optimizations, it realizes complete immutability and can parse infinitely recursive data structures.

This project is inspired by parsec, a monadic parser library for Haskell.

Concept

  • Easy construction APIs with monads in C#
  • Pure/Immutable/Functional framework in C#
  • Replace regular expressions in your code (applicable from smallest to largest)
  • Most readable API source code

Overview

  • 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 custom deriviation for core types
  • Supports nullable reference types (with C# 8.0 or later)
  • Supports Source Link (that allows to refer every parser implementation source codes)
  • 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)

How to install

from NuGet

dotnet-cli:

$ dotnet add package ParsecSharp

NuGet Package Manager Console:

> Install-Package ParsecSharp

PackageReference:

<ItemGroup>
  <PackageReference Include="ParsecSharp" Version="*" />
</ItemGroup>

Download manually:

NuGet gallery

Supported platform

  • netstandard2.1 (compatible with net5.0 or later, netcoreapp, with some performance improvements and additional implementations that depend on new runtime features)
  • netstandard2.0 (compatible with net461 or later, uap, xamarin, and more)

Requires C# 7.3 or later for generic overloading resolution. Recommends C# 13.0 or later for better overloading resolution via OverloadResolutionPriority.

Get started

  1. Add the package reference to your project.
  2. Add the using directives: using static ParsecSharp.Parser; and using static ParsecSharp.Text; to your code.
  3. Parse your all.

How to use

Implementation examples

Documentation is included in the UnitTest code.

If you want more information, read the API source code, all is there.

Questions?

Feel free to create an Issue!

License

This software is released under the MIT License, see LICENSE.

Using
  • Fody (MIT): Only for internal use; does NOT propagate license acceptance to users.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ParsecSharp:

Package Downloads
KSPMMCfgParser

Parses .cfg files in combined KSP/MM format

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 172 1/1/2025
3.6.0 145 8/6/2024
3.5.0 9,503 11/24/2022
3.4.0 954 3/18/2022
3.3.2 21,292 3/9/2021
3.3.1 726 11/14/2020
3.3.0 484 11/11/2020
3.2.2 620 5/17/2020
3.2.1 605 3/5/2020
3.2.0 576 2/27/2020
3.1.1 639 1/22/2020
3.1.0 613 12/11/2019
3.0.0 607 12/5/2019
2.4.0 651 10/26/2019
2.3.0 638 10/21/2019
2.2.1 623 10/17/2019
2.2.0 612 10/17/2019
2.0.0 612 9/28/2019
1.6.0 728 6/2/2019
1.5.0 699 2/26/2019
1.4.1 1,152 5/1/2018
1.4.0 1,019 4/24/2018
1.3.0 1,048 12/11/2017
1.2.0 980 10/25/2017
1.1.0 999 10/5/2017
1.0.0 1,030 7/25/2017
0.9.0 1,061 2/20/2017
0.8.0 1,297 11/11/2016
0.7.0 1,353 3/3/2016
0.6.2 1,350 1/27/2016
0.6.1 1,349 1/24/2016
0.6.0 1,333 1/23/2016
0.5.1 1,547 1/20/2016
0.5.0 1,294 1/10/2016
0.4.0 1,438 12/25/2015
0.3.0 1,613 12/24/2015