Demonstrates how uCalc's token-aware Transformer safely renames a variable without corrupting a string literal, a common failure point for Regex.
ID: 1173
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
// A rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value");
// The input string where 'x' appears both as a variable and inside a string
var code = """
if (x > 10) print("Max value is x");
""";
// The transformation correctly ignores the 'x' inside the quoted string
Console.WriteLine(t.Transform(code));
if (value > 10) print("Max value is x"); using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); // A rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value"); // The input string where 'x' appears both as a variable and inside a string var code = """ if (x > 10) print("Max value is x"); """; // The transformation correctly ignores the 'x' inside the quoted string Console.WriteLine(t.Transform(code));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
// A rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value");
// The input string where 'x' appears both as a variable and inside a string
auto code = R"(if (x > 10) print("Max value is x");)";
// The transformation correctly ignores the 'x' inside the quoted string
cout << t.Transform(code) << endl;
}
if (value > 10) print("Max value is x"); #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; // A rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value"); // The input string where 'x' appears both as a variable and inside a string auto code = R"(if (x > 10) print("Max value is x");)"; // The transformation correctly ignores the 'x' inside the quoted string cout << t.Transform(code) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
'// A rule to replace the alphanumeric token 'x' with 'value'
t.FromTo("x", "value")
'// The input string where 'x' appears both as a variable and inside a string
Dim code = "if (x > 10) print(""Max value is x"");"
'// The transformation correctly ignores the 'x' inside the quoted string
Console.WriteLine(t.Transform(code))
End Sub
End Module
if (value > 10) print("Max value is x"); Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() '// A rule to replace the alphanumeric token 'x' with 'value' t.FromTo("x", "value") '// The input string where 'x' appears both as a variable and inside a string Dim code = "if (x > 10) print(""Max value is x"");" '// The transformation correctly ignores the 'x' inside the quoted string Console.WriteLine(t.Transform(code)) End Sub End Module