RhoMicro.ParserGenerator 1.0.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package RhoMicro.ParserGenerator --version 1.0.1
                    
NuGet\Install-Package RhoMicro.ParserGenerator -Version 1.0.1
                    
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="RhoMicro.ParserGenerator" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RhoMicro.ParserGenerator" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="RhoMicro.ParserGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RhoMicro.ParserGenerator --version 1.0.1
                    
#r "nuget: RhoMicro.ParserGenerator, 1.0.1"
                    
#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.
#:package RhoMicro.ParserGenerator@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RhoMicro.ParserGenerator&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=RhoMicro.ParserGenerator&version=1.0.1
                    
Install as a Cake Tool

ParserGenerator

Overview

This is a parser generator for generating parsers that are suitable for use in Roslyn source generators. It allows for faster development of Domain Specific Languages (DSL) by automating the development of parsing infrastructure. For example, DSLs that transpile to C# are suitable for implementation as a source generator using this library.

Installation

Terminal:

dotnet add package RhoMicro.ParserGenerator --version 1.0.0

PackageReference:

<PropertyGroup>
    <PackageReference Include="RhoMicro.ParserGenerator" Version="1.0.0"/>
</PropertyGroup>

Quick Start

Define a grammar for which to generate a parser:

[assembly: ParserGenerator.GenerateParser(
    """
    type-parameter-template = HEAD arity-hole TAIL
    arity-hole = "{" arity-range / ARITY "}"
    arity-range = ARITY "-" ARITY
    HEAD = "a"-"z" / "A"-"Z" TAIL
    TAIL = *("a"-"z" / "A"-"Z" / "0"-"9" / "_")
    ARITY = "1"-"9" / ("1"-"9" "0"-"9") / ("1" / "2" "0"-"4" "0"-"9") / ( "2" "5" "0"-"6")

    """)]

Here is a reference for the syntax of grammars (they use a dialect of ABNF): <table> <thead> <tr> <th>Name</th> <th>Syntax</th> <th>Explanation</th> </tr> </thead> <tbody> <tr> <td>Rule List</td> <td>r = s<br/>s = p</td> <td> The rules r and s are defined.<br/> Rule definitions are terminated by line breaks.<br/> Ensure that the last rule is also terminated by a line break. </td> </tr> <tr> <td>Rule</td> <td>r = p</td> <td>The rule r is defined by the pattern p.</td> </tr> <tr> <td>Quoted Range</td> <td>"a"-"z"</td> <td>Matches a single character in the range [a,z].</td> </tr> <tr> <td>Hex Range</td> <td>%x61-7A</td> <td>Matches a single character in the range [a,z].</td> </tr> <tr> <td>Quoted Sequence</td> <td>"foo"</td> <td>Matches the character sequence foo.</td> </tr> <tr> <td>Hex Sequence</td> <td>%x66.6F.6F</td> <td>Matches the character sequence foo.</td> </tr> <tr> <td rowspan=4>Repetition</td> <td>n*mp</td> <td>Matches at least n and at most m repetitions of p.</td> </tr> <tr> <td>mp</td> <td>Matches at most m repetitions of p.</td> </tr> <tr> <td>np</td> <td>Matches at least n repetitions of p.</td> </tr> <tr> <td>*p</td> <td>Matches any amount of repetitions of p.</td> </tr> <tr> <td>Option</td> <td>[p]</td> <td>Optionally matches p.</td> </tr> <tr> <td>Concatenation</td> <td>p q</td> <td>Matches p followed by q.</td> </tr> <tr> <td>Alternative</td> <td>p / q</td> <td>Matches p or q.</td> </tr> <tr> <td>Group</td> <td>(p)</td> <td>Matches p.</td> </tr> <tr> <td>Wildcard</td> <td>.</td> <td>Matches any character.</td> </tr> <tr> <td>Reference</td> <td>r</td> <td>Matches the pattern defining the rule r.</td> </tr> </tbody> </table>

Utilize the generated lexer and parser on an input text:

var options = LexerOptions.Default;
var lexer = new Lexer(templateSource, options);
var parser = new Parser(lexer);
var parsing = parser.Parse(ct);

If the input text is not recognized by the parser, null is returned. The generated infrastructure does not emit diagnostics for invalid inputs or other failure modes. This is an area for future development.

Process the parsed syntax tree, e.g. using one of the provided visitors:

var stringBuilder = new StringBuilder();
var output = new StringWriter(stringBuilder);

output.WriteLine("/*");

parsing?.Accept(
    new SyntaxTreeWriter(
        SyntaxTreeWriterOptions.Default,
        new DescendantsCollector(DescendantsCollectorOptions.ChildNodesOnly),
        output),
    ct);

output.WriteLine("*/");
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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 was computed. 
.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.

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.2 269 9/9/2025
1.0.1 227 9/9/2025