RhoMicro.ParserGenerator
1.0.2
Prefix Reserved
dotnet add package RhoMicro.ParserGenerator --version 1.0.2
NuGet\Install-Package RhoMicro.ParserGenerator -Version 1.0.2
<PackageReference Include="RhoMicro.ParserGenerator" Version="1.0.2" />
<PackageVersion Include="RhoMicro.ParserGenerator" Version="1.0.2" />
<PackageReference Include="RhoMicro.ParserGenerator" />
paket add RhoMicro.ParserGenerator --version 1.0.2
#r "nuget: RhoMicro.ParserGenerator, 1.0.2"
#:package RhoMicro.ParserGenerator@1.0.2
#addin nuget:?package=RhoMicro.ParserGenerator&version=1.0.2
#tool nuget:?package=RhoMicro.ParserGenerator&version=1.0.2
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):
| Name | Syntax | Explanation |
|---|---|---|
| Rule List | r = s<br/>s = p |
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. |
| Rule | r = p |
The rule r is defined by the pattern p. |
| Quoted Range | "a"-"z" |
Matches a single character in the range [a,z]. |
| Hex Range | %x61-7A |
Matches a single character in the range [a,z]. |
| Quoted Sequence | "foo" |
Matches the character sequence foo. |
| Hex Sequence | %x66.6F.6F |
Matches the character sequence foo. |
| Repetition | n*mp<br/>*mp<br/>n*p<br/>*p |
Matches at least n and at most m repetitions of p.<br/>Matches at most m repetitions of p.<br/>Matches at least n repetitions of p.<br/>Matches any amount of repetitions of p. |
| Option | [p] |
Optionally matches p. |
| Concatenation | p q |
Matches p followed by q. |
| Alternative | p / q |
Matches p or q. |
| Group | (p) |
Matches p. |
| Wildcard | . |
Matches any character. |
| Reference | r |
Matches the pattern defining the rule r. |
Utilize the generated lexer and parser on an input text:
var options = LexerOptions.Default;
var lexer = new Lexer(inputText, options);
var parser = new Parser(lexer);
var parseTree = 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("/*");
parseTree?.Accept(
new SyntaxTreeWriter(
SyntaxTreeWriterOptions.Default,
new DescendantsCollector(DescendantsCollectorOptions.ChildNodesOnly),
output),
ct);
output.WriteLine("*/");
| 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. 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. |
-
.NETStandard 2.0
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.14.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.