How to find matched patterns while skipping commented text using SkipOver().

ID: 110

See: Count, SkipOver
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */");

// Capture standard blocks surrounded by parentheses
t.Pattern("({expr})");

// Instruct the transformer to ignore any text inside C-style block comments.
// This prevents the commented "(x + y)" from being falsely counted as a match.
t.SkipOver("/* {etc} */"); // commented text between /* */ is skipped

t.Find();
Console.WriteLine(t.Matches.Count());
				
			
3
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */");

   // Capture standard blocks surrounded by parentheses
   t.Pattern("({expr})");

   // Instruct the transformer to ignore any text inside C-style block comments.
   // This prevents the commented "(x + y)" from being falsely counted as a match.
   t.SkipOver("/* {etc} */"); // commented text between /* */ is skipped

   t.Find();
   cout << t.Matches().Count() << endl;
}
				
			
3
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Str("int result = (x + 3) * 2 - (y - 7 / z) * (5 ^ a + 10); /* (x + y) */")
      
      '// Capture standard blocks surrounded by parentheses
      t.Pattern("({expr})")
      
      '// Instruct the transformer to ignore any text inside C-style block comments.
      '// This prevents the commented "(x + y)" from being falsely counted as a match.
      t.SkipOver("/* {etc} */") '// commented text between /* */ is skipped
      
      t.Find()
      Console.WriteLine(t.Matches.Count())
   End Sub
End Module
				
			
3