www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Regex driving me nuts

Error: static variable `thompsonFactory` cannot be read at 
compile time, Trying to regex an import file.

Also I have a group (...)* and it always fails or matches only 
one but if I do (...)(...)(...) it matches all 3(fails if more or 
less of course. ... is the regex).

Also when I ignore a group (?:Text) I get Text as a matched group 
;/

But all this is irrelevant if I can't get the code to work at 
compile time. I tried ctRegex





// A workaround for R-T enum re = regex(...)
template defaultFactory(Char)
{
      property MatcherFactory!Char defaultFactory(const ref 
Regex!Char re)  safe
     {
         import std.regex.internal.backtracking : 
BacktrackingMatcher;
         import std.regex.internal.thompson : ThompsonMatcher;
         import std.algorithm.searching : canFind;
         static MatcherFactory!Char backtrackingFactory;
         static MatcherFactory!Char thompsonFactory;
         if (re.backrefed.canFind!"a != 0")
         {
             if (backtrackingFactory is null)
                 backtrackingFactory = new 
RuntimeFactory!(BacktrackingMatcher, Char);
             return backtrackingFactory;
         }
         else
         {
             if (thompsonFactory is null)
                 thompsonFactory = new 
RuntimeFactory!(ThompsonMatcher, Char);
             return thompsonFactory;
         }
     }
}

The workaround seems to workaround working.
Jun 17 2019