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:
Retrieves a token definition by its name and can optionally re-categorize it in a single operation.
Returns the Item object for the token. If the token is not found, an empty item is returned (for which IsEmpty() is true).
The ByName method is a versatile tool for interacting with a Tokens collection. It serves a dual purpose: it retrieves a specific token definition by its unique name and can optionally re-categorize it in the same operation.
This method is the primary way to access built-in or user-defined tokens programmatically when you know their name (e.g., _token_alphanumeric). It is often used as a precursor to modifying a token's properties, such as its regex pattern or its lexical type.
The method's behavior depends on the newType parameter:
Getter Mode (Default): If newType is omitted or set to TokenType::None, ByName acts purely as a getter. It finds the token with the specified name and returns its corresponding Item object.
Setter Mode: If you provide a specific TokenType for newType, the method first finds the token and then immediately changes its lexical category to the new type. This is a convenient shortcut for tokens.ByName("...").TypeOfToken(newType).
item.Regex()._token_newline) from a StatementSep to Whitespace to allow patterns to match across multiple lines.In traditional compiler tools like ANTLR or Flex/Bison, token definitions are static. They are defined in a grammar file, and changing a token's type requires modifying that file, regenerating parser code, and recompiling the application. This is a compile-time, static process.
uCalc's token system is entirely dynamic and programmatic. The ByName method is a key part of this dynamism. It allows your application to:
This runtime flexibility provides a significant advantage over static parsing systems, enabling the creation of highly adaptable and user-configurable applications.
ID: 1012
using uCalcSoftware;
var uc = new uCalc();
var tokens = uc.ExpressionTokens;
var alphaToken = tokens.ByName("_token_alphanumeric");
Console.WriteLine($"Alphanumeric Regex: {alphaToken.Regex}");
Alphanumeric Regex: [a-zA-Z_][a-zA-Z0-9_]* using uCalcSoftware; var uc = new uCalc(); var tokens = uc.ExpressionTokens; var alphaToken = tokens.ByName("_token_alphanumeric"); Console.WriteLine($"Alphanumeric Regex: {alphaToken.Regex}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto tokens = uc.ExpressionTokens();
auto alphaToken = tokens.ByName("_token_alphanumeric");
cout << "Alphanumeric Regex: " << alphaToken.Regex() << endl;
}
Alphanumeric Regex: [a-zA-Z_][a-zA-Z0-9_]* #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto tokens = uc.ExpressionTokens(); auto alphaToken = tokens.ByName("_token_alphanumeric"); cout << "Alphanumeric Regex: " << alphaToken.Regex() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim tokens = uc.ExpressionTokens
Dim alphaToken = tokens.ByName("_token_alphanumeric")
Console.WriteLine($"Alphanumeric Regex: {alphaToken.Regex}")
End Sub
End Module
Alphanumeric Regex: [a-zA-Z_][a-zA-Z0-9_]* Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim tokens = uc.ExpressionTokens Dim alphaToken = tokens.ByName("_token_alphanumeric") Console.WriteLine($"Alphanumeric Regex: {alphaToken.Regex}") End Sub End Module
ID: 1013
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
var source = """
content spans
multiple lines
""";
t.FromTo("{body}", "Body: [{body}]");
Console.WriteLine("--- Before: Newline is a Separator ---");
Console.WriteLine(t.Transform(source));
// Use ByName to find the newline token and change its type.
t.Tokens.ByName("_token_newline", TokenType.Whitespace);
Console.WriteLine("");
Console.WriteLine("--- After: Newline is Whitespace ---");
Console.WriteLine(t.Transform(source));
--- Before: Newline is a Separator ---
<data>
content spans
multiple lines
</data>
--- After: Newline is Whitespace ---
Body: [content spans
multiple lines] using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); var source = """ <data> content spans multiple lines </data> """; t.FromTo("<data>{body}</data>", "Body: [{body}]"); Console.WriteLine("--- Before: Newline is a Separator ---"); Console.WriteLine(t.Transform(source)); // Use ByName to find the newline token and change its type. t.Tokens.ByName("_token_newline", TokenType.Whitespace); Console.WriteLine(""); Console.WriteLine("--- After: Newline is Whitespace ---"); Console.WriteLine(t.Transform(source));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
auto source = R"(
content spans
multiple lines
)";
t.FromTo("{body}", "Body: [{body}]");
cout << "--- Before: Newline is a Separator ---" << endl;
cout << t.Transform(source) << endl;
// Use ByName to find the newline token and change its type.
t.Tokens().ByName("_token_newline", TokenType::Whitespace);
cout << "" << endl;
cout << "--- After: Newline is Whitespace ---" << endl;
cout << t.Transform(source) << endl;
}
--- Before: Newline is a Separator ---
<data>
content spans
multiple lines
</data>
--- After: Newline is Whitespace ---
Body: [content spans
multiple lines] #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; auto source = R"(<data> content spans multiple lines </data>)"; t.FromTo("<data>{body}</data>", "Body: [{body}]"); cout << "--- Before: Newline is a Separator ---" << endl; cout << t.Transform(source) << endl; // Use ByName to find the newline token and change its type. t.Tokens().ByName("_token_newline", TokenType::Whitespace); cout << "" << endl; cout << "--- After: Newline is Whitespace ---" << endl; cout << t.Transform(source) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
Dim source = "
content spans
multiple lines
"
t.FromTo("{body}", "Body: [{body}]")
Console.WriteLine("--- Before: Newline is a Separator ---")
Console.WriteLine(t.Transform(source))
'// Use ByName to find the newline token and change its type.
t.Tokens.ByName("_token_newline", TokenType.Whitespace)
Console.WriteLine("")
Console.WriteLine("--- After: Newline is Whitespace ---")
Console.WriteLine(t.Transform(source))
End Sub
End Module
--- Before: Newline is a Separator ---
<data>
content spans
multiple lines
</data>
--- After: Newline is Whitespace ---
Body: [content spans
multiple lines] Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() Dim source = "<data> content spans multiple lines </data>" t.FromTo("<data>{body}</data>", "Body: [{body}]") Console.WriteLine("--- Before: Newline is a Separator ---") Console.WriteLine(t.Transform(source)) '// Use ByName to find the newline token and change its type. t.Tokens.ByName("_token_newline", TokenType.Whitespace) Console.WriteLine("") Console.WriteLine("--- After: Newline is Whitespace ---") Console.WriteLine(t.Transform(source)) End Sub End Module
ID: 169
using uCalcSoftware;
var uc = new uCalc();
// This example removes the single quote pattern from the list
var t = uc.NewTransformer();
var txt = "This is a test, 'This is a test'";
t.FromTo("{token:1}", "<{@Self}>");
Console.WriteLine(t.Transform(txt).Text);
// Now the ' character will no longer be special
// (see the Name() example for list of token names
t.Tokens.Remove(t.Tokens["_token_string_singlequoted"]);
Console.WriteLine(t.Transform(txt).Text);
<This> <is> <a> <test><,> <'This is a test'>
<This> <is> <a> <test><,> <'><This> <is> <a> <test><'> using uCalcSoftware; var uc = new uCalc(); // This example removes the single quote pattern from the list var t = uc.NewTransformer(); var txt = "This is a test, 'This is a test'"; t.FromTo("{token:1}", "<{@Self}>"); Console.WriteLine(t.Transform(txt).Text); // Now the ' character will no longer be special // (see the Name() example for list of token names t.Tokens.Remove(t.Tokens["_token_string_singlequoted"]); Console.WriteLine(t.Transform(txt).Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// This example removes the single quote pattern from the list
auto t = uc.NewTransformer();
auto txt = "This is a test, 'This is a test'";
t.FromTo("{token:1}", "<{@Self}>");
cout << t.Transform(txt).Text() << endl;
// Now the ' character will no longer be special
// (see the Name() example for list of token names
t.Tokens().Remove(t.Tokens()["_token_string_singlequoted"]);
cout << t.Transform(txt).Text() << endl;
}
<This> <is> <a> <test><,> <'This is a test'>
<This> <is> <a> <test><,> <'><This> <is> <a> <test><'> #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // This example removes the single quote pattern from the list auto t = uc.NewTransformer(); auto txt = "This is a test, 'This is a test'"; t.FromTo("{token:1}", "<{@Self}>"); cout << t.Transform(txt).Text() << endl; // Now the ' character will no longer be special // (see the Name() example for list of token names t.Tokens().Remove(t.Tokens()["_token_string_singlequoted"]); cout << t.Transform(txt).Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// This example removes the single quote pattern from the list
Dim t = uc.NewTransformer()
Dim txt = "This is a test, 'This is a test'"
t.FromTo("{token:1}", "<{@Self}>")
Console.WriteLine(t.Transform(txt).Text)
'// Now the ' character will no longer be special
'// (see the Name() example for list of token names
t.Tokens.Remove(t.Tokens("_token_string_singlequoted"))
Console.WriteLine(t.Transform(txt).Text)
End Sub
End Module
<This> <is> <a> <test><,> <'This is a test'>
<This> <is> <a> <test><,> <'><This> <is> <a> <test><'> Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// This example removes the single quote pattern from the list Dim t = uc.NewTransformer() Dim txt = "This is a test, 'This is a test'" t.FromTo("{token:1}", "<{@Self}>") Console.WriteLine(t.Transform(txt).Text) '// Now the ' character will no longer be special '// (see the Name() example for list of token names t.Tokens.Remove(t.Tokens("_token_string_singlequoted")) Console.WriteLine(t.Transform(txt).Text) End Sub End Module
ID: 220
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("""
a b c
x
y
z
1 2 3
""");
t.Pattern("{body}");
Console.WriteLine("Newline as statement separator (default)");
Console.WriteLine("----------------------------------------");
Console.WriteLine(t.Find().Matches.Text);
Console.WriteLine("");
Console.WriteLine("Newline as whitespace");
Console.WriteLine("---------------------");
t.Tokens["_token_newline"].TypeOfToken = TokenType.Whitespace;
Console.WriteLine(t.Find().Matches.Text);
Newline as statement separator (default)
----------------------------------------
<div>a b c</div>
<div>1 2 3</div>
Newline as whitespace
---------------------
<div>a b c</div>
<div>
x
y
z
</div>
<div>1 2 3</div> using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Str(""" <div>a b c</div> <div> x y z </div> <div>1 2 3</div> """); t.Pattern("<div>{body}</div>"); Console.WriteLine("Newline as statement separator (default)"); Console.WriteLine("----------------------------------------"); Console.WriteLine(t.Find().Matches.Text); Console.WriteLine(""); Console.WriteLine("Newline as whitespace"); Console.WriteLine("---------------------"); t.Tokens["_token_newline"].TypeOfToken = TokenType.Whitespace; Console.WriteLine(t.Find().Matches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Str(R"(
a b c
x
y
z
1 2 3
)");
t.Pattern("{body}");
cout << "Newline as statement separator (default)" << endl;
cout << "----------------------------------------" << endl;
cout << t.Find().Matches().Text() << endl;
cout << "" << endl;
cout << "Newline as whitespace" << endl;
cout << "---------------------" << endl;
t.Tokens()["_token_newline"].TypeOfToken(TokenType::Whitespace);
cout << t.Find().Matches().Text() << endl;
}
Newline as statement separator (default)
----------------------------------------
<div>a b c</div>
<div>1 2 3</div>
Newline as whitespace
---------------------
<div>a b c</div>
<div>
x
y
z
</div>
<div>1 2 3</div> #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Str(R"( <div>a b c</div> <div> x y z </div> <div>1 2 3</div> )"); t.Pattern("<div>{body}</div>"); cout << "Newline as statement separator (default)" << endl; cout << "----------------------------------------" << endl; cout << t.Find().Matches().Text() << endl; cout << "" << endl; cout << "Newline as whitespace" << endl; cout << "---------------------" << endl; t.Tokens()["_token_newline"].TypeOfToken(TokenType::Whitespace); cout << t.Find().Matches().Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Str("
a b c
x
y
z
1 2 3
")
t.Pattern("{body}")
Console.WriteLine("Newline as statement separator (default)")
Console.WriteLine("----------------------------------------")
Console.WriteLine(t.Find().Matches.Text)
Console.WriteLine("")
Console.WriteLine("Newline as whitespace")
Console.WriteLine("---------------------")
t.Tokens("_token_newline").TypeOfToken = TokenType.Whitespace
Console.WriteLine(t.Find().Matches.Text)
End Sub
End Module
Newline as statement separator (default)
----------------------------------------
<div>a b c</div>
<div>1 2 3</div>
Newline as whitespace
---------------------
<div>a b c</div>
<div>
x
y
z
</div>
<div>1 2 3</div> Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Str(" <div>a b c</div> <div> x y z </div> <div>1 2 3</div> ") t.Pattern("<div>{body}</div>") Console.WriteLine("Newline as statement separator (default)") Console.WriteLine("----------------------------------------") Console.WriteLine(t.Find().Matches.Text) Console.WriteLine("") Console.WriteLine("Newline as whitespace") Console.WriteLine("---------------------") t.Tokens("_token_newline").TypeOfToken = TokenType.Whitespace Console.WriteLine(t.Find().Matches.Text) End Sub End Module
ID: 170
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Name);
Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Regex);
Console.WriteLine("");
// Note: In C# or VB you can simply use [TokenType::Literal, n]
// instead of ByType(TokenType::Literal, n)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name);
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name);
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name);
_token_alphanumeric
[a-zA-Z_][a-zA-Z0-9_]*
_token_string_singlequoted
_token_string_doublequoted
_token_string_tripledoublequoted using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Name); Console.WriteLine(uc.ExpressionTokens[TokenType.AlphaNumeric].Regex); Console.WriteLine(""); // Note: In C# or VB you can simply use [TokenType::Literal, n] // instead of ByType(TokenType::Literal, n) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name); Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name); Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Name() << endl;
cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex() << endl;
cout << "" << endl;
// Note: In C# or VB you can simply use [TokenType::Literal, n]
// instead of ByType(TokenType::Literal, n)
cout << uc.ExpressionTokens().ByType(TokenType::Literal, 0).Name() << endl;
cout << uc.ExpressionTokens().ByType(TokenType::Literal, 1).Name() << endl;
cout << uc.ExpressionTokens().ByType(TokenType::Literal, 2).Name() << endl;
}
_token_alphanumeric
[a-zA-Z_][a-zA-Z0-9_]*
_token_string_singlequoted
_token_string_doublequoted
_token_string_tripledoublequoted #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Name() << endl; cout << uc.ExpressionTokens()[TokenType::AlphaNumeric].Regex() << endl; cout << "" << endl; // Note: In C# or VB you can simply use [TokenType::Literal, n] // instead of ByType(TokenType::Literal, n) cout << uc.ExpressionTokens().ByType(TokenType::Literal, 0).Name() << endl; cout << uc.ExpressionTokens().ByType(TokenType::Literal, 1).Name() << endl; cout << uc.ExpressionTokens().ByType(TokenType::Literal, 2).Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Name)
Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Regex)
Console.WriteLine("")
'// Note: In C# or VB you can simply use [TokenType::Literal, n]
'// instead of ByType(TokenType::Literal, n)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name)
Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name)
End Sub
End Module
_token_alphanumeric
[a-zA-Z_][a-zA-Z0-9_]*
_token_string_singlequoted
_token_string_doublequoted
_token_string_tripledoublequoted Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Name) Console.WriteLine(uc.ExpressionTokens(TokenType.AlphaNumeric).Regex) Console.WriteLine("") '// Note: In C# or VB you can simply use [TokenType::Literal, n] '// instead of ByType(TokenType::Literal, n) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 0).Name) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 1).Name) Console.WriteLine(uc.ExpressionTokens.ByType(TokenType.Literal, 2).Name) End Sub End Module