Tersor 2.0.0
dotnet add package Tersor --version 2.0.0
NuGet\Install-Package Tersor -Version 2.0.0
<PackageReference Include="Tersor" Version="2.0.0" />
<PackageVersion Include="Tersor" Version="2.0.0" />
<PackageReference Include="Tersor" />
paket add Tersor --version 2.0.0
#r "nuget: Tersor, 2.0.0"
#:package Tersor@2.0.0
#addin nuget:?package=Tersor&version=2.0.0
#tool nuget:?package=Tersor&version=2.0.0
Tersor
A Runtime Templating and Expression Language
Tersor is a domain-specific string transformation compiler, designed for advanced runtime templating and expression evaluation.
More formally, it is:
A runtime-compilable, token-aware expression engine and template compiler that binds to runtime data sources, allowing deeply nested property and method resolution.
Table of Contents
Quickstart
using System;
class Person { public string Name { get; set; } }
class Program
{
static void Main()
{
// Compiler instance
ITerserCompiler compiler = new MyTerserCompiler();
// Runtime runner
IRunTersor runner = new TersorRunner();
runner.SetCompiler(compiler);
// Lorraine mappings enable object-based resource loading
runner.SetLorraineMappings(new[] { new TersorLorraineMapping { LorraineId = 0, QualifiedName = nameof(Person) } });
// Load a data object
var myData = new Person { Name = "Alice" };
runner.LoadResource(myData);
// Run a template
string output = runner.Run(0, "/"Hello/" Name!");
Console.WriteLine(output); // Output: "Hello Alice!"
// Unload resource
runner.UnloadResource(myData);
}
}
Key Points:
SetLorraineMappings()allowsLoadResource(object)andUnloadResource(object)without needing indices.Run(objectIndex, template)executes the template using the mapped resources.
Overview
Tersor combines compile-time parsing with runtime execution:
- Compiler (
ITerserCompiler): parses, compiles, transforms templates. - Runner (
IRunTersor): executes compiled templates, resolves resources. - Lorraine Mappings: maps object types to resource indices for convenient object-based access.
Language Syntax
Constants
String Literals
The following characters are treated as string literals:
& % - , * $ ~ @
- Use double quotes to define string literals:
"example"
Supported Types
int, double, float, time, date, datetime, string
- Convert to identifier with
~prefix:~int
Methods
Legend
- 🚧 = In Development (may be unstable or incomplete)
General Syntax:
method(obj, memberA, memberB, type):memberPath
method: Name of the method.obj, memberA, memberB, type: Input parameters.:memberPath: Optional accessor path into the returned object.- Categories: Logical, Conditional, Aggregate, Chaining
Note: Methods marked as In Development exist in the state diagram but may not be fully implemented. Their signatures may change.
Logical Methods
🚧latest(array, startDate, endDate, referenceMember):otherMemberReturns the most recent object in the array within a date range usingreferenceMember.relevant(comparator, array, (DateTime) floor, (DateTime) ceiling)Returns the index of the object found between the given floor and ceiling DateTime properties. If multiple are found then the last found element's index is returned.🚧find(array, memberA, target)Searches an array for the first object wherememberAmatchestarget.enumerate(memberA, start | [int1, int2, ..., intN], char1, ..., charN)Maps a sequence to specified values (non-linear enumerations supported).
Conditional Methods
🚧lesser(object, memberA, memberB, type)Returns the lesser ofmemberAandmemberB, typecasted totype.🚧greater(object, memberA, memberB)Returns the greater ofmemberAandmemberB.equal(memberA, memberB, [trueResult], [falseResult])- 2 args: Returns
TrueorFalse. - 3 args: Returns
trueResultif equal; elsefalse. - 4 args: Returns
trueResultorfalseResultaccordingly.
- 2 args: Returns
bool(bool | object, trueMember, falseMember, [falseResult])- If first param is boolean: returns
trueMemberorfalseMember - If first param is object: compares values and returns
trueMemberif equal, elsefalseResult
- If first param is boolean: returns
exists(object, memberA, memberB)ReturnsmemberAif object is not null; else returnsmemberB
Aggregate Methods
🚧all(array, memberA)Returns a concatenated string of allmemberAvalues from the array.
Chaining Methods
concatenate(memberA, memberB, ..., memberN)Converts inputs to strings and returns a space-separated string. Returnsnullif any input isnull.
Typecasting
[[type]]
Supported typecasts: time, date, datetime, string, int, double, float
Placeholders
method(...):memberPath:-PlaceholderName
Example:
relevant(dateMember, myArray[], startDate, endDate):status:-Status
"Status": {{Status}}[[string]]
Source Targeting
Access properties from multiple data sources using %:
propertyFromPrimary propertyFromSecondary%2%
Array Indexes
- Keywords like
lastor[0,1,2,...]can be used to access array indexes.
Grammar Features
- Genitive Case (In Development): appending
'sautomatically formats genitive forms (e.g.,child'sorparents').
Syntax Limitations
- Identifiers cannot include numbers.
Example:
StringProperty1is parsed asStringProperty+1(constant), not as a single identifier.
Runtime API
Interface:
public interface IRunTersor
{
void SetCompiler(ITerserCompiler compiler);
string Run(int objectOrigin, string code);
void LoadResource(int index, object obj);
void LoadResource(object obj);
void UnloadResource(int index);
void UnloadResource(object obj);
void SetLorraineMappings(TersorLorraineMapping[] mappings);
}
Notes:
SetLorraineMappings()allows object-based Load/Unload without knowing indices.TersorRunneris the default implementation ofIRunTersor.
License
MIT License
| Product | Versions 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. |
-
net8.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 |
|---|---|---|
| 2.0.0 | 486 | 8/26/2025 |
| 0.5.0 | 911 | 8/15/2025 |
| 0.5.0-alpha1 | 200 | 8/14/2025 |
ReleaseNotes.md