VOOZH about

URL: https://www.nuget.org/packages/MrKWatkins.Ast/

⇱ NuGet Gallery | MrKWatkins.Ast 0.9.135




👁 Image
MrKWatkins.Ast 0.9.135

Prefix Reserved
dotnet add package MrKWatkins.Ast --version 0.9.135
 
 
NuGet\Install-Package MrKWatkins.Ast -Version 0.9.135
 
 
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="MrKWatkins.Ast" Version="0.9.135" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MrKWatkins.Ast" Version="0.9.135" />
 
Directory.Packages.props
<PackageReference Include="MrKWatkins.Ast" />
 
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 MrKWatkins.Ast --version 0.9.135
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MrKWatkins.Ast, 0.9.135"
 
 
#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 MrKWatkins.Ast@0.9.135
 
 
#: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=MrKWatkins.Ast&version=0.9.135
 
Install as a Cake Addin
#tool nuget:?package=MrKWatkins.Ast&version=0.9.135
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MrKWatkins.Ast

👁 Build Status
👁 DeepSource
👁 NuGet Version
👁 NuGet Downloads

C# library to build and manipulate abstract syntax trees when writing compilers.

Background

As part of my Oakley project to create a compiler and it's associated OakAsm project to create an assembler (details coming soon) I needed to represent abstract syntax trees in C#. This library was created so I could share the code between those two projects.

Usage

Create a base node type for your abstract syntax tree:

public abstract class Expression : Node<Expression>
{
}

Create more specific nodes:

public sealed class ConstantNumber : Expression
{
 public ConstantNumber(int value)
 {
 Value = value;
 }

 public int Value
 {
 get => Properties.GetOrThrow<int>(nameof(Value));
 init => Properties.Set(nameof(Value), value);
 }
}

public sealed class Addition : Expression
{
 public Addition(ConstantNumber x, ConstantNumber y)
 {
 Children.Add(x);
 Children.Add(y);
 }
}

Walk the tree:

var fifty = new ConstantNumber(50);
var sixty = new ConstantNumber(60);
var expression = new Addition(fifty, sixty);

var allNodes = expression.ThisAndDescendents;
var fiftyAndParent = fifty.ThisAndAncestors;
var fiftyAndSixty = fifty.ThisAndNextSiblings;
var justSixty = sixty.PreviousSibling;
var result = expression.Children.OfType<ConstantNumber>().Sum(n => n.Value);

Mark nodes with errors, warnings and info messages:

sixty.AddError("Value must be less than 55.");
var expressionHasErrors = expression.HasErrors; // true.

Associate nodes with their position in source code during parsing:

var source = new TextFile(new FileInfo("MySource.code")); // Contains "50 + 60".
expression.SourcePosition = source.CreatePosition(0, 7, 0, 0); // startIndex, length, startLineIndex, startColumnIndex.
fifty.SourcePosition = source.CreatePosition(0, 2, 0, 0);
sixty.SourcePosition = source.CreatePosition(5, 2, 0, 5);

Output errors with highlighted source information:

var errors = MessageFormatter.FormatErrors(expression);

// MySource.code (1, 6): Error: Parent Value must be less than 55.
// 50 + 60
// --

Manipulate and copy the tree:

sixty.ReplaceWith(new ConstantNumber(55));

var copy = expression.Copy();

Full documentation will be available with version 1.0.x.

Install

dotnet add package MrKWatkins.Ast

Pull Requests

I'm not accepting pull requests at the current time; this project is tailored for some other projects of mine and I want to get them in a suitable state first.

Feel free to raise issues for bugs or suggestions, but I make no guarantees they will get looked at I'm afraid!

License

MIT

Product Versions Compatible and additional computed target framework versions.
.NET net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (15)

Showing the top 5 NuGet packages that depend on MrKWatkins.Ast:

Package Downloads
MrKWatkins.OakAsm

Shared code for the OakAsm project.

MrKWatkins.OakAsm.Z80

Library containing assembly definitions for the Z80 CPU, part of the OakAsm project.

MrKWatkins.OakAsm.Formatting

Library for formatting assembly code, part of the OakAsm project.

MrKWatkins.OakAsm.Parsing

Library for parsing assembly code, part of the OakAsm project.

MrKWatkins.OakAsm.IO

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.135 639 3/10/2026
0.9.134 1,416 11/15/2025
0.9.133 676 9/8/2025
0.9.132 425 8/12/2025
0.9.131 352 8/10/2025
0.9.130 430 8/6/2025
0.9.129 2,548 1/29/2025
0.9.128 2,490 12/22/2024
0.9.127 276 12/17/2024
0.9.126 208 12/17/2024
0.9.125 212 12/17/2024
0.9.124 410 12/15/2024
0.9.123 506 12/8/2024
0.9.122 397 11/17/2024
0.9.121 598 11/1/2024
0.9.120 1,126 10/24/2024
0.9.119 1,081 10/21/2024
0.9.118 2,076 7/8/2024
0.9.117 1,163 3/27/2024
0.9.116 258 3/23/2024
Loading failed