Practical: Re-categorizes the newline token as whitespace to allow a pattern to match across multiple lines, a common requirement for parsing HTML or XML.

ID: 678

				
					using uCalcSoftware;

var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
   var source = """
<data>
  content spans
  multiple lines
</data>
""";
   t.FromTo("<data>{body}</data>", "Body: [{body}]");

   Console.WriteLine("--- Default (Newline is a Separator) ---");
   // This fails because {body} stops at the first newline
   Console.WriteLine(t.Transform(source).Text);
   Console.WriteLine("");

   Console.WriteLine("--- Modified (Newline is Whitespace) ---");
   // Find the newline token and change its type
   var newlineToken = t.Tokens["_token_newline"];
   newlineToken.TypeOfToken = TokenType.Whitespace;
   // Now the transform succeeds
   Console.WriteLine(t.Transform(source).Text);
}
				
			
--- Default (Newline is a Separator) ---
<data>
  content spans
  multiple lines
</data>

--- Modified (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;
      t.Owned(); // Causes t to be released when it goes out of scope
      auto source = R"(<data>
  content spans
  multiple lines
</data>)";
      t.FromTo("<data>{body}</data>", "Body: [{body}]");

      cout << "--- Default (Newline is a Separator) ---" << endl;
      // This fails because {body} stops at the first newline
      cout << t.Transform(source).Text() << endl;
      cout << "" << endl;

      cout << "--- Modified (Newline is Whitespace) ---" << endl;
      // Find the newline token and change its type
      auto newlineToken = t.Tokens()["_token_newline"];
      newlineToken.TypeOfToken(TokenType::Whitespace);
      // Now the transform succeeds
      cout << t.Transform(source).Text() << endl;
   }
}
				
			
--- Default (Newline is a Separator) ---
<data>
  content spans
  multiple lines
</data>

--- Modified (Newline is Whitespace) ---
Body: [content spans
  multiple lines]
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using t As New uCalc.Transformer()
         Dim source = "<data>
  content spans
  multiple lines
</data>"
         t.FromTo("<data>{body}</data>", "Body: [{body}]")
         
         Console.WriteLine("--- Default (Newline is a Separator) ---")
         '// This fails because {body} stops at the first newline
         Console.WriteLine(t.Transform(source).Text)
         Console.WriteLine("")
         
         Console.WriteLine("--- Modified (Newline is Whitespace) ---")
         '// Find the newline token and change its type
         Dim newlineToken = t.Tokens("_token_newline")
         newlineToken.TypeOfToken = TokenType.Whitespace
         '// Now the transform succeeds
         Console.WriteLine(t.Transform(source).Text)
      End Using
   End Sub
End Module
				
			
--- Default (Newline is a Separator) ---
<data>
  content spans
  multiple lines
</data>

--- Modified (Newline is Whitespace) ---
Body: [content spans
  multiple lines]