Cyjb.Compilers.Design 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cyjb.Compilers.Design --version 1.0.0
NuGet\Install-Package Cyjb.Compilers.Design -Version 1.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="Cyjb.Compilers.Design" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cyjb.Compilers.Design --version 1.0.0
#r "nuget: Cyjb.Compilers.Design, 1.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 Cyjb.Compilers.Design as a Cake Addin
#addin nuget:?package=Cyjb.Compilers.Design&version=1.0.0

// Install Cyjb.Compilers.Design as a Cake Tool
#tool nuget:?package=Cyjb.Compilers.Design&version=1.0.0

Cyjb.Compilers.Design

允许通过设计时 T4 模板生成词法分析器和语法分析器的实现。

使用方式:

  1. 在通过 nuget 引用包时,需要指定 GeneratePathProperty="true"
<ItemGroup>
	<PackageReference Include="Cyjb.Compilers.Design" Version="1.0.0" GeneratePathProperty="true" />
</ItemGroup>
  1. 编写词法分析器或语法分析器的控制器类,例如:
using Cyjb.Compilers.Lexers;

enum Calc { Id, Add, Sub, Mul, Div, Pow, LBrace, RBrace }

[LexerSymbol("\\+", Kind = Calc.Add)]
[LexerSymbol("\\-", Kind = Calc.Sub)]
[LexerSymbol("\\*", Kind = Calc.Mul)]
[LexerSymbol("\\/", Kind = Calc.Div)]
[LexerSymbol("\\^", Kind = Calc.Pow)]
[LexerSymbol("\\(", Kind = Calc.LBrace)]
[LexerSymbol("\\)", Kind = Calc.RBrace)]
[LexerSymbol("\\s")]
// 必须是部分类,且继承自 LexerController<Calc>
public partial class TestCalcController : LexerController<Calc>
{
	/// <summary>
	/// 数字的终结符定义。
	/// </summary>
	[LexerSymbol("[0-9]+", Kind = Calc.Id)]
	public void DigitAction()
	{
		Value = int.Parse(Text);
		Accept();
	}
}
  1. 添加与词法分析器同名的 tt 文件,内容如下:
<#@ include file="$(PkgCyjb_Compilers_Design)\content\CompilerTemplate.t4" #>

运行 T4 模板后即可生成同名的 .lexer.cs 文件,包含了词法分析器的实现。

欢迎访问我的博客获取更多信息。

C# 词法分析器系列博文

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • 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.22 81 6/4/2024
1.0.21 82 6/4/2024
1.0.20 103 3/23/2024
1.0.19 108 3/20/2024
1.0.18 106 3/15/2024
1.0.17 87 3/14/2024
1.0.16 130 1/15/2024
1.0.15 227 3/10/2023
1.0.14 212 3/3/2023
1.0.13 219 2/9/2023
1.0.12 307 1/28/2023
1.0.11 265 1/25/2023
1.0.10 265 1/24/2023
1.0.9 252 1/23/2023
1.0.8 269 1/16/2023
1.0.7 317 12/4/2022
1.0.6 411 11/1/2022
1.0.5 437 10/25/2022
1.0.4 437 9/7/2022
1.0.3 443 8/27/2022
1.0.2 433 8/27/2022
1.0.1 436 8/18/2022
1.0.0 439 8/18/2022