Safely renames a variable without corrupting a string literal, demonstrating the Transformer's token-awareness.

ID: 1196

				
					using uCalcSoftware;

var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
   
   // This rule replaces the ALPHANUMERIC token 'x', not just the character 'x'.
   t.FromTo("x", "value");

   var code = """
if (x > 10) print("Max value is x");
""";

   // The 'x' inside the string is ignored because QuoteSensitive is true by default.
   Console.WriteLine(t.Transform(code));

}
				
			
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;
      t.Owned(); // Causes t to be released when it goes out of scope

      // This rule replaces the ALPHANUMERIC token 'x', not just the character 'x'.
      t.FromTo("x", "value");

      auto code = R"(if (x > 10) print("Max value is x");)";

      // The 'x' inside the string is ignored because QuoteSensitive is true by default.
      cout << t.Transform(code) << endl;

   }
}
				
			
if (value > 10) print("Max value is x");
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using t As New uCalc.Transformer()
         
         '// This rule replaces the ALPHANUMERIC token 'x', not just the character 'x'.
         t.FromTo("x", "value")
         
         Dim code = "if (x > 10) print(""Max value is x"");"
         
         '// The 'x' inside the string is ignored because QuoteSensitive is true by default.
         Console.WriteLine(t.Transform(code))
         
      End Using
   End Sub
End Module
				
			
if (value > 10) print("Max value is x");