MonParsing 0.2.0
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MonParsing --version 0.2.0
NuGet\Install-Package MonParsing -Version 0.2.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="MonParsing" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MonParsing --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MonParsing, 0.2.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 MonParsing as a Cake Addin
#addin nuget:?package=MonParsing&version=0.2.0
// Install MonParsing as a Cake Tool
#tool nuget:?package=MonParsing&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MonParsing
C# library for writing parsers using monadic parser combinators and LINQ syntax.
using MonParsing.Core;
using static MonParsing.Core.Parser;
public class SemVer
{
public required SemVerCore VersionCore { get; init; }
public PreRelease? PreRelease { get; init; }
public Build? Build { get; init; }
public static Parser<SemVer> Parser { get; private set; }
static SemVer()
{
var letter = Lower.Or(Upper);
var positive = If(x => '1' <= x && x <= '9');
var zero = Char('0');
var digit = zero.Or(positive);
var digits = OneOrMore(digit);
var dash = Char('-');
var nonDigit = letter.Or(dash);
var identifierCharacter = digit.Or(nonDigit);
var numericIdentifier = String(zero)
.Or(from p in positive from ds in ZeroOrMore(digit) select ds.Prepend(p));
var alphanumericIdentifier = (
from nd in nonDigit
from ics in ZeroOrMore(identifierCharacter)
select ics.Prepend(nd)
).Or(OneOrMore(identifierCharacter));
var buildIdentifier = alphanumericIdentifier.Or(digits);
var preReleaseIdentifier = alphanumericIdentifier.Or(numericIdentifier);
var dot = Char('.');
var build =
from bis in OneOrMoreSeparated(String(buildIdentifier), dot)
select new Build { Identifiers = bis };
var preRelease =
from pris in OneOrMoreSeparated(String(preReleaseIdentifier), dot)
select new PreRelease { Identifiers = pris };
var version = from n in String(numericIdentifier) select int.Parse(n);
var semVerCore =
from major in version
from minor in dot.And(version)
from patch in dot.And(version)
select new SemVerCore
{
Major = major,
Minor = minor,
Patch = patch
};
var plus = Char('+');
// The main parser
Parser =
from vc in semVerCore
from pr in ZeroOrOne(dash.And(preRelease))
from b in ZeroOrOne(plus.And(build))
select new SemVer
{
VersionCore = vc,
PreRelease = pr.Value,
Build = b.Value
};
}
}
public record struct SemVerCore(int Major, int Minor, int Patch);
public record PreRelease
{
public required IEnumerable<string> Identifiers { get; init; }
}
public record Build
{
public required IEnumerable<string> Identifiers { get; init; }
}
SemVer.Parser("1.0.0");
// {
// "Value": {
// "Result": {
// "VersionCore": {
// "Major": 1,
// "Minor": 0,
// "Patch": 0
// },
// },
// "Input": ""
// },
// "Error": null
//}
SemVer.Parser("01.0.0")
// {
// "Value": null,
// "Error": "Expectation: The character ., Actual: 1, Input 1.0.0"
// }
Examples
A number of example parsers can be found in MonParsing.Examples. In addition to the examples the tests are a good place to become familiar with how the library works.
Acknowledgements
This library is based on https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf
Product | Versions 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-alpha.1 | 76 | 7/29/2023 |
1.0.0-alpha | 108 | 7/19/2023 |
0.2.0 | 128 | 7/29/2023 |
0.1.0 | 125 | 7/16/2023 |
0.1.0-alpha | 110 | 7/9/2023 |