![]() |
VOOZH | about |
dotnet add package ktsu.Coder.Core --version 1.0.3
NuGet\Install-Package ktsu.Coder.Core -Version 1.0.3
<PackageReference Include="ktsu.Coder.Core" Version="1.0.3" />
<PackageVersion Include="ktsu.Coder.Core" Version="1.0.3" />Directory.Packages.props
<PackageReference Include="ktsu.Coder.Core" />Project file
paket add ktsu.Coder.Core --version 1.0.3
#r "nuget: ktsu.Coder.Core, 1.0.3"
#:package ktsu.Coder.Core@1.0.3
#addin nuget:?package=ktsu.Coder.Core&version=1.0.3Install as a Cake Addin
#tool nuget:?package=ktsu.Coder.Core&version=1.0.3Install as a Cake Tool
A flexible and extensible .NET library for representing code as Abstract Syntax Trees (AST), serializing to YAML, and generating code in multiple programming languages.
ktsu.Coder provides a language-agnostic way to represent code structures using Abstract Syntax Trees. The library allows you to:
This makes it ideal for code generation tools, transpilers, and any application that needs to work with code structures in a language-independent way.
Add the NuGet package:
dotnet add package ktsu.Coder
using ktsu.Coder.Core.Ast;
using ktsu.Coder.Core.Languages;
using ktsu.Coder.Core.Serialization;
// Create a function declaration
var function = new FunctionDeclaration("calculate_sum")
{
ReturnType = "int"
};
// Add parameters
function.Parameters.Add(new Parameter("a", "int"));
function.Parameters.Add(new Parameter("b", "int"));
function.Parameters.Add(new Parameter("debug", "bool")
{
IsOptional = true,
DefaultValue = "False"
});
// Add function body
function.Body.Add(new ReturnStatement(new AstLeafNode<string>("a + b")));
var serializer = new YamlSerializer();
string yamlContent = serializer.Serialize(function);
Console.WriteLine(yamlContent);
Output:
functionDeclaration:
name: calculate_sum
returnType: int
parameters:
- name: a
type: int
- name: b
type: int
- name: debug
type: bool
isOptional: true
defaultValue: False
body:
- returnStatement:
expression:
Leaf<String>: a + b
var pythonGenerator = new PythonGenerator();
string pythonCode = pythonGenerator.Generate(function);
Console.WriteLine(pythonCode);
Output:
def calculate_sum(a: int, b: int, debug: bool = False) -> int:
return "a + b"
// Deserialize from YAML
var deserializer = new YamlDeserializer();
AstNode deserializedAst = deserializer.Deserialize(yamlContent);
// Generate code from deserialized AST
string regeneratedCode = pythonGenerator.Generate(deserializedAst);
The library follows SOLID principles with a clean separation of concerns:
To add support for a new language, implement the ILanguageGenerator interface:
public class JavaScriptGenerator : LanguageGeneratorBase
{
public override string LanguageId => "javascript";
public override string DisplayName => "JavaScript";
public override string FileExtension => "js";
protected override void GenerateInternal(AstNode node, StringBuilder builder, int indentLevel)
{
// Implementation for JavaScript code generation
}
}
The repository includes two example applications:
Run them to see the library in action:
dotnet run --project Coder.CLI
dotnet run --project Coder.App
Contributions are welcome! Please feel free to submit pull requests or open issues for:
MIT License. Copyright (c) ktsu.dev
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. 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. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.0.4-pre.1 | 186 | 7/9/2025 | |
| 1.0.3 | 555 | 6/13/2025 | 1.0.3 is deprecated because it is no longer maintained. |
| 1.0.2 | 350 | 6/13/2025 |
## v1.0.3 (patch)
Changes since v1.0.2:
- Enhance YAML serialization and deserialization for new node types ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance expression system integration and serialization support ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.2 (patch)
Changes since v1.0.1:
- Enhance expression handling in ExpressionDemo ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor project structure and enhance expression handling ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance YAML serialization and deserialization handling ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor expression handling and improve code consistency ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.1 (patch)
Changes since v1.0.0:
- Implement dependency injection and enhance AST expression handling ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor AST expression handling and enhance visual editor support ([@matt-edmondson](https://github.com/matt-edmondson))
- Update implementation and design documents to reflect current project status ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.0 (major)
- Design and implementation plan documentation ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor Coder library to address build errors and improve serialization logic ([@matt-edmondson](https://github.com/matt-edmondson))
- Add AST node classes and YAML serialization support ([@matt-edmondson](https://github.com/matt-edmondson))
- Update package references in Coder.Core.csproj ([@matt-edmondson](https://github.com/matt-edmondson))
- Update project configuration and enhance build scripts ([@matt-edmondson](https://github.com/matt-edmondson))
- Add initial project files and implementation plan for Coder library ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance Coder.App with type consistency and testing improvements ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor AST node classes to improve deep cloning and metadata handling ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance Coder.App with XML documentation and null handling improvements ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor AST node classes and improve YAML serialization ([@matt-edmondson](https://github.com/matt-edmondson))
- Initial commit for Coder ([@matt-edmondson](https://github.com/matt-edmondson))
- Transform Coder.App into a TUI using Spectre.Console ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove Sample class and associated unit tests from the project ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance Coder library with comprehensive CLI and App examples ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor AST implementation and improve serialization ([@matt-edmondson](https://github.com/matt-edmondson))