TinyAst.Preprocessor 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TinyAst.Preprocessor --version 0.1.0
                    
NuGet\Install-Package TinyAst.Preprocessor -Version 0.1.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="TinyAst.Preprocessor" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TinyAst.Preprocessor" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TinyAst.Preprocessor" />
                    
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 TinyAst.Preprocessor --version 0.1.0
                    
#r "nuget: TinyAst.Preprocessor, 0.1.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.
#:package TinyAst.Preprocessor@0.1.0
                    
#: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=TinyAst.Preprocessor&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TinyAst.Preprocessor&version=0.1.0
                    
Install as a Cake Tool

TinyAst.Preprocessor

AST-native preprocessor bridge between TinyAst (TinyTokenizer.Ast) and TinyPreprocessor.

Requirements

  • TinyPreprocessor 0.3.0+ (generic content API)
  • TinyAst 0.11.0+ (schema binding, SyntaxEditor)
  • .NET 8.0+

Overview

This bridge enables AST-native import/include preprocessing:

  • Import directives are detected via schema-bound syntax trees, not text parsing
  • Downstream consumers define imports by binding a node type in their schema, and providing a reference-extractor delegate
  • Merging uses SyntaxEditor to inline resolved content directly into the AST
  • Source maps track original locations through the merge process

Quick Start

1. Define Your Import Node

Create a SyntaxNode type for your import directive shape (no required interface):

using TinyTokenizer.Ast;

public sealed class MyImportNode : SyntaxNode
{
    public MyImportNode(CreationContext context) : base(context) { }

    public string Reference
    {
        get
        {
            // Extract the import path from your node's children
            // Example: import "path/to/file"
            var stringToken = Children
                .OfType<SyntaxToken>()
                .FirstOrDefault(t => t.Kind == NodeKind.String);

            if (stringToken is null)
                return string.Empty;

            var text = stringToken.Text;
            // Strip quotes
            return text.Length >= 2 && text[0] == '"' && text[^1] == '"'
                ? text[1..^1]
                : text;
        }
    }
}

2. Register in Your Schema

var importPattern = new PatternBuilder()
    .Ident("import")
    .String()
    .BuildQuery();

var schema = Schema.Create()
    .DefineSyntax<MyImportNode>("Import", b => b.Match(importPattern))
    .Build();

3. Wire Up the Preprocessor

using TinyAst.Preprocessor.Bridge;
using TinyAst.Preprocessor.Bridge.Resources;
using TinyPreprocessor.Core;

// Create resource store and add your resources
var store = new InMemorySyntaxTreeResourceStore();

var mainTree = SyntaxTree.ParseAndBind(mainSource, schema);
var mainResource = new Resource<SyntaxTree>(new ResourceId("main"), mainTree);
store.Add(mainResource);

// Add other resources that can be imported
var libTree = SyntaxTree.ParseAndBind(libSource, schema);
store.Add(new Resource<SyntaxTree>(new ResourceId("lib"), libTree));

// Create the preprocessor (defaults wired for SyntaxTree content)
var preprocessor = new SyntaxTreePreprocessor<MyImportNode>(
    store,
    getReference: n => n.Reference);

// Process
var result = await preprocessor.ProcessAsync(
    mainResource,
    context: null!,
    PreprocessorOptions.Default);

if (result.Success)
{
    // result.Content is the merged SyntaxTree
    Console.WriteLine(result.Content.ToText());
}
else
{
    foreach (var diagnostic in result.Diagnostics)
    {
        Console.WriteLine(diagnostic);
    }
}

Public API

Core Types

Type Namespace Description
SyntaxTreePreprocessor<T> Bridge One-stop preprocessor setup (context = object)
SyntaxTreePreprocessor<T,C> Bridge One-stop preprocessor setup for SyntaxTree content
SyntaxTreeBridge<T,C> Bridge Convenience wrapper (parser + merge strategy)
ImportDirective Bridge.Imports Directive record with Reference, Location, Resource
ImportDirectiveModel Bridge.Imports IDirectiveModel<ImportDirective> implementation
ImportDirectiveParser<T> Bridge.Imports IDirectiveParser<SyntaxTree, ImportDirective>
SyntaxTreeContentModel Bridge.Content IContentModel<SyntaxTree> implementation
SyntaxTreeMergeStrategy<T,C> Bridge.Merging IMergeStrategy using SyntaxEditor
InMemorySyntaxTreeResourceStore Bridge.Resources In-memory resource store for testing
InMemorySyntaxTreeResourceResolver Bridge.Resources Resolver using the in-memory store

Key Constraints

  • Schema binding is required: Trees must have HasSchema == true
  • Locations are absolute offsets: TinyAst node coordinates (trivia-inclusive)
  • No text reparsing: Merge operates directly on AST nodes via SyntaxEditor

Documentation

License

See LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
0.4.3 97 1/25/2026
0.4.2 99 1/15/2026
0.4.1 95 1/11/2026
0.4.0 96 1/11/2026
0.1.0 102 1/11/2026