A high-performance, zero-allocation tokenizer library for .NET that parses text into abstract tokens using ReadOnlySpan for maximum efficiency.
$ dotnet add package TinyTokenizerA high-performance syntax tree library for .NET 8+ with fluent queries, pattern matching, and undo/redo editing — built on a zero-allocation tokenizer with SIMD optimization.
SearchValues<char>dotnet add package TinyTokenizer
using TinyTokenizer.Ast;
// Parse source into a syntax tree
var tree = SyntaxTree.Parse("function foo() { return 1; }");
// Query nodes with CSS-like selectors
var idents = tree.Select(Query.AnyIdent); // [Ident("function"), Ident("foo"), Ident("return")]
// Fluent mutations with undo support
tree.CreateEditor()
.Replace(Query.Ident("foo"), "bar")
.Insert(Query.BraceBlock.First().InnerStart(), "console.log('enter');")
.Commit();
// Undo/redo
tree.Undo();
tree.Redo();
var tree = SyntaxTree.Parse("obj.method(x)", Schema.Default);
var methodCalls = tree.Match<MethodCallSyntax>().ToList(); // [MethodCallSyntax { Object="obj", Method="method" }]
For scenarios where you don't need a syntax tree:
using TinyTokenizer;
var tokens = "func(a, b)".TokenizeToTokens();
// tokens contains:
// - IdentToken("func")
// - BlockToken("(a, b)") with children:
// - IdentToken("a"), SymbolToken(","), WhitespaceToken(" "), IdentToken("b")
Full documentation on the Wiki →
| Topic | Description |
|---|---|
| TinyAst Guide | Syntax tree API |
| Schema | Unified configuration |
| Query API | CSS-like node selectors |
| SyntaxEditor | Batch mutations, undo/redo |
| Syntax Nodes | Pattern-based matching |
| TreeWalker | DOM-style traversal |
| Trivia | Whitespace preservation |
| Topic | Description |
|---|---|
| Token Types | SimpleToken vs Token, all types |
| Configuration | Operators, comments, symbols |
| Async Streaming | Stream/PipeReader APIs |
| Error Handling | ErrorToken and recovery |
| Topic | Description |
|---|---|
| Getting Started | Installation and basic usage |
| Architecture | Two-level design, red-green trees |
| API Reference | Types, enums, methods |
CommunityToolkit.HighPerformance (automatically included)MIT