uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Imports a list of token definitions from another Tokens collection, enabling the reuse of lexical configurations.
The current Tokens object, allowing for a fluent, chainable syntax.
The Add(Tokens) method provides a powerful way to reuse token configurations by importing all token definitions from one Tokens collection into another. This is essential for creating modular, maintainable, and consistent parsing logic across different components of an application.
Clear() before importing.Tokens collections are independent; modifying a token in one will not affect the other.Token precedence is determined by a Last-In, First-Out (LIFO) order. Since this method appends tokens to the end of the list, imported tokens will have higher precedence than any tokens that already exist in the collection. The tokenizer will check for matches against the imported tokens first.
Tokens object that defines the complete syntax for a language or data format. Other transformers can then import this base set, ensuring consistency.In traditional compiler development with tools like ANTLR or Flex/Bison, lexical rules are defined in static grammar files. To share or reuse these rules, you typically rely on file-based imports managed by the build system. This process is entirely static and occurs at compile-time.
uCalc's approach is fundamentally different and more flexible:
Tokens configurations and programmatically compose them based on application logic, user settings, or other dynamic conditions.This runtime flexibility makes Add(Tokens) a cornerstone feature for building modular and dynamically configurable parsing systems.
ID: 1009
using uCalcSoftware;
var uc = new uCalc();
// Create a source transformer and define a custom token.
var t_source = new uCalc.Transformer();
var customToken = t_source.Tokens.Add("###", TokenType.Generic);
// Create a destination transformer.
var t_dest = new uCalc.Transformer();
// Import all token definitions from the source.
t_dest.Tokens.Add(t_source.Tokens);
t_dest.FromTo("###", "MATCH");
Console.WriteLine($"t_dest can now find '###': {t_dest.Transform("Test ### Test")}");
t_dest can now find '###': Test MATCH Test using uCalcSoftware; var uc = new uCalc(); // Create a source transformer and define a custom token. var t_source = new uCalc.Transformer(); var customToken = t_source.Tokens.Add("###", TokenType.Generic); // Create a destination transformer. var t_dest = new uCalc.Transformer(); // Import all token definitions from the source. t_dest.Tokens.Add(t_source.Tokens); t_dest.FromTo("###", "MATCH"); Console.WriteLine($"t_dest can now find '###': {t_dest.Transform("Test ### Test")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Create a source transformer and define a custom token.
uCalc::Transformer t_source;
auto customToken = t_source.Tokens().Add("###", TokenType::Generic);
// Create a destination transformer.
uCalc::Transformer t_dest;
// Import all token definitions from the source.
t_dest.Tokens().Add(t_source.Tokens());
t_dest.FromTo("###", "MATCH");
cout << "t_dest can now find '###': " << t_dest.Transform("Test ### Test") << endl;
}
t_dest can now find '###': Test MATCH Test #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Create a source transformer and define a custom token. uCalc::Transformer t_source; auto customToken = t_source.Tokens().Add("###", TokenType::Generic); // Create a destination transformer. uCalc::Transformer t_dest; // Import all token definitions from the source. t_dest.Tokens().Add(t_source.Tokens()); t_dest.FromTo("###", "MATCH"); cout << "t_dest can now find '###': " << t_dest.Transform("Test ### Test") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Create a source transformer and define a custom token.
Dim t_source As New uCalc.Transformer()
Dim customToken = t_source.Tokens.Add("###", TokenType.Generic)
'// Create a destination transformer.
Dim t_dest As New uCalc.Transformer()
'// Import all token definitions from the source.
t_dest.Tokens.Add(t_source.Tokens)
t_dest.FromTo("###", "MATCH")
Console.WriteLine($"t_dest can now find '###': {t_dest.Transform("Test ### Test")}")
End Sub
End Module
t_dest can now find '###': Test MATCH Test Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Create a source transformer and define a custom token. Dim t_source As New uCalc.Transformer() Dim customToken = t_source.Tokens.Add("###", TokenType.Generic) '// Create a destination transformer. Dim t_dest As New uCalc.Transformer() '// Import all token definitions from the source. t_dest.Tokens.Add(t_source.Tokens) t_dest.FromTo("###", "MATCH") Console.WriteLine($"t_dest can now find '###': {t_dest.Transform("Test ### Test")}") End Sub End Module
ID: 167
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// This creates a simpler (not very useful) set of tokens for sake of example
var MyTokens = t.Tokens;
MyTokens.Clear(); // removes the default list of tokens
MyTokens.Add("."); // Should always have a fallback token like this one
MyTokens.Add(";", TokenType.StatementSep);
MyTokens.Add("<", TokenType.Generic, ">");
MyTokens.Add("[0-9]+", TokenType.Literal);
MyTokens.Add(" +", TokenType.Whitespace);
MyTokens.Add("[a-z]+", TokenType.AlphaNumeric);
t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep
Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC"));
Console.WriteLine("");
var OtherTransform = new uCalc.Transformer(uc); // This is an alternative way of constructing a new transformer
OtherTransform.Tokens.Add(MyTokens); // Imports the entire token list from the other transformer
OtherTransform.Pattern("{word:1}");
Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text);
[This is a test]; [That < 123.456; abc >]; ABC
This
is
a
test
;
That
<
123
.
456
;
abc
>
;
ABC using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // This creates a simpler (not very useful) set of tokens for sake of example var MyTokens = t.Tokens; MyTokens.Clear(); // removes the default list of tokens MyTokens.Add("."); // Should always have a fallback token like this one MyTokens.Add(";", TokenType.StatementSep); MyTokens.Add("<", TokenType.Generic, ">"); MyTokens.Add("[0-9]+", TokenType.Literal); MyTokens.Add(" +", TokenType.Whitespace); MyTokens.Add("[a-z]+", TokenType.AlphaNumeric); t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC")); Console.WriteLine(""); var OtherTransform = new uCalc.Transformer(uc); // This is an alternative way of constructing a new transformer OtherTransform.Tokens.Add(MyTokens); // Imports the entire token list from the other transformer OtherTransform.Pattern("{word:1}"); Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// This creates a simpler (not very useful) set of tokens for sake of example
auto MyTokens = t.Tokens();
MyTokens.Clear(); // removes the default list of tokens
MyTokens.Add("."); // Should always have a fallback token like this one
MyTokens.Add(";", TokenType::StatementSep);
MyTokens.Add("<", TokenType::Generic, ">");
MyTokens.Add("[0-9]+", TokenType::Literal);
MyTokens.Add(" +", TokenType::Whitespace);
MyTokens.Add("[a-z]+", TokenType::AlphaNumeric);
t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep
cout << t.Transform("This is a test; That < 123.456; abc >; ABC") << endl;
cout << "" << endl;
uCalc::Transformer OtherTransform(uc); // This is an alternative way of constructing a new transformer
OtherTransform.Tokens().Add(MyTokens); // Imports the entire token list from the other transformer
OtherTransform.Pattern("{word:1}");
cout << OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches().Text() << endl;
}
[This is a test]; [That < 123.456; abc >]; ABC
This
is
a
test
;
That
<
123
.
456
;
abc
>
;
ABC #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // This creates a simpler (not very useful) set of tokens for sake of example auto MyTokens = t.Tokens(); MyTokens.Clear(); // removes the default list of tokens MyTokens.Add("."); // Should always have a fallback token like this one MyTokens.Add(";", TokenType::StatementSep); MyTokens.Add("<", TokenType::Generic, ">"); MyTokens.Add("[0-9]+", TokenType::Literal); MyTokens.Add(" +", TokenType::Whitespace); MyTokens.Add("[a-z]+", TokenType::AlphaNumeric); t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep cout << t.Transform("This is a test; That < 123.456; abc >; ABC") << endl; cout << "" << endl; uCalc::Transformer OtherTransform(uc); // This is an alternative way of constructing a new transformer OtherTransform.Tokens().Add(MyTokens); // Imports the entire token list from the other transformer OtherTransform.Pattern("{word:1}"); cout << OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches().Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// This creates a simpler (not very useful) set of tokens for sake of example
Dim MyTokens = t.Tokens
MyTokens.Clear() '// removes the default list of tokens
MyTokens.Add(".") '// Should always have a fallback token like this one
MyTokens.Add(";", TokenType.StatementSep)
MyTokens.Add("<", TokenType.Generic, ">")
MyTokens.Add("[0-9]+", TokenType.Literal)
MyTokens.Add(" +", TokenType.Whitespace)
MyTokens.Add("[a-z]+", TokenType.AlphaNumeric)
t.FromTo("{ This | That} {etc}", "[{@Self}]") '// {etc} stops at the semicolon ";" TokenType.StatementSep
Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC"))
Console.WriteLine("")
Dim OtherTransform As New uCalc.Transformer(uc) '// This is an alternative way of constructing a new transformer
OtherTransform.Tokens.Add(MyTokens) '// Imports the entire token list from the other transformer
OtherTransform.Pattern("{word:1}")
Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text)
End Sub
End Module
[This is a test]; [That < 123.456; abc >]; ABC
This
is
a
test
;
That
<
123
.
456
;
abc
>
;
ABC Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// This creates a simpler (not very useful) set of tokens for sake of example Dim MyTokens = t.Tokens MyTokens.Clear() '// removes the default list of tokens MyTokens.Add(".") '// Should always have a fallback token like this one MyTokens.Add(";", TokenType.StatementSep) MyTokens.Add("<", TokenType.Generic, ">") MyTokens.Add("[0-9]+", TokenType.Literal) MyTokens.Add(" +", TokenType.Whitespace) MyTokens.Add("[a-z]+", TokenType.AlphaNumeric) t.FromTo("{ This | That} {etc}", "[{@Self}]") '// {etc} stops at the semicolon ";" TokenType.StatementSep Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC")) Console.WriteLine("") Dim OtherTransform As New uCalc.Transformer(uc) '// This is an alternative way of constructing a new transformer OtherTransform.Tokens.Add(MyTokens) '// Imports the entire token list from the other transformer OtherTransform.Pattern("{word:1}") Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text) End Sub End Module