Improving std.regex(p)

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Fri Jun 18 05:09:54 PDT 2010


On Fri, 18 Jun 2010 11:36:48 +0000, Ben Hanson wrote:

> I'm thinking I could look at getting as far as the regex syntax tree and
> then we could discuss DFA representation (it sounds like you want to
> generate code directly - how do you do that?! This is why I mentioned
> the .NET bytecode stuff - I imagine there is some overlap there, but I
> don't know enough to be sure. Can you output source code at compilation
> time and have D compile it, or do you use a load of recursion like C++
> TMP?

D's metaprogramming facilities are insanely powerful.  You can take any 
string containing valid source code (that is known at compile time, of 
course) and "paste" it into your code with the mixin() expression:

  mixin("int i;");
  i = 2;

For the regex parser, I suppose you'd do something like:

  string makeParserCode(string regex) { ... }

  struct sregex(string regex)
  {
      mixin(makeParserCode(regex));
  }


-Lars


More information about the Digitalmars-d mailing list