Token Add(ExistingToken)

ID: 163

				
					using uCalcSoftware;

var uc = new uCalc();

var t1 = uc.NewTransformer();
var CommentRegex = """
/\*([\s\S]*?)\*/
""";
var WhitespaceToken = t1.Tokens.Add(CommentRegex, TokenType.Whitespace);
WhitespaceToken.Description = "Treats text between /* and */ as whitespace";

var txt = "a b, a /* comment a b */ b, a x b, ab, a   b, a, b";

var t2 = uc.NewTransformer();
t2.FromTo("a b", "<{@Self}>");
t2.Transform(txt);
Console.WriteLine(t2);

// The token defined in the other transformer (WhitespaceToken) is imported into this one.
// Now, everything between /* and */ will be treated as whitespace
t2.Tokens.Add(WhitespaceToken);
Console.WriteLine(t2.Transform(txt));
				
			
<a b>, a /* comment <a b> */ b, a x b, ab, <a   b>, a, b
<a b>, <a /* comment a b */ b>, a x b, ab, <a   b>, a, b
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;

   auto t1 = uc.NewTransformer();
   auto CommentRegex = R"(/\*([\s\S]*?)\*/)";
   auto WhitespaceToken = t1.Tokens().Add(CommentRegex, TokenType::Whitespace);
   WhitespaceToken.Description("Treats text between /* and */ as whitespace");

   auto txt = "a b, a /* comment a b */ b, a x b, ab, a   b, a, b";

   auto t2 = uc.NewTransformer();
   t2.FromTo("a b", "<{@Self}>");
   t2.Transform(txt);
   cout << t2 << endl;

   // The token defined in the other transformer (WhitespaceToken) is imported into this one.
   // Now, everything between /* and */ will be treated as whitespace
   t2.Tokens().Add(WhitespaceToken);
   cout << t2.Transform(txt) << endl;
}
				
			
<a b>, a /* comment <a b> */ b, a x b, ab, <a   b>, a, b
<a b>, <a /* comment a b */ b>, a x b, ab, <a   b>, a, b
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      
      Dim t1 = uc.NewTransformer()
      Dim CommentRegex = "/\*([\s\S]*?)\*/"
      Dim WhitespaceToken = t1.Tokens.Add(CommentRegex, TokenType.Whitespace)
      WhitespaceToken.Description = "Treats text between /* and */ as whitespace"
      
      Dim txt = "a b, a /* comment a b */ b, a x b, ab, a   b, a, b"
      
      Dim t2 = uc.NewTransformer()
      t2.FromTo("a b", "<{@Self}>")
      t2.Transform(txt)
      Console.WriteLine(t2)
      
      '// The token defined in the other transformer (WhitespaceToken) is imported into this one.
      '// Now, everything between /* and */ will be treated as whitespace
      t2.Tokens.Add(WhitespaceToken)
      Console.WriteLine(t2.Transform(txt))
   End Sub
End Module
				
			
<a b>, a /* comment <a b> */ b, a x b, ab, <a   b>, a, b
<a b>, <a /* comment a b */ b>, a x b, ab, <a   b>, a, b