Improving std.regex(p)
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Fri Jun 18 05:20:45 PDT 2010
On Fri, 18 Jun 2010 12:09:54 +0000, Lars T. Kyllingstad wrote:
> 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));
> }
I should mention that the makeParserCode() function in the example must
of course be evaluatable at compile time, and there are some restrictions
on such functions. Lately, many of those restrictions have been
overcome, though, and I'm not sure what's left.
Does anyone know what the current limitations on CTFE are?
-Lars
More information about the Digitalmars-d
mailing list