Improving std.regex(p)

Ben Hanson Ben.Hanson at tfbplc.co.uk
Sat Jun 19 10:25:05 PDT 2010


== Quote from BCS (none at anon.com)'s article
> Hello bearophile,
> > Ben Hanson:
> >
> >> Can you output source code at compilation time and have D compile it,
> >> or do you use a load of recursion like C++ TMP?
> >>
> > This can be done with string mixin. You can use compile-time
> > evaluation to build a string of code, and the mix it in somewhere, the
> > compiler will compile it. It's a dirty thing, but unless D3 gets
> > macros, it's the thing to be used. You can use it to build a string of
> > asm code too, because it's part of D syntax.
> OTOH, and IHMO it should be avoided where you can, kinda like goto. (For
> one things, forget having usable line numbers in your error messages.) You
> can often get a lot done with static if, tuple foreach, const values feed
> to boilerplate code and the like with just a scattering of one or two line
> mixins stuffed in the middle.
> >
> > Bye,
> > bearophile

It occurred to me that you could have a normal regex library that builds the regex at
runtime, debug it, produce a code generator (similar code to re2c), debug that and then just
wrap it with the mixin at the end. If you run into bugs, you can just do it at runtime
instead and debug. The nice thing is, if I can get this converted, the lexer library is just
slightly different. That means you could have the same approach with a lexer generator! This
would lead to huge interest from the boost.spirit guys...

Regards,

Ben


More information about the Digitalmars-d mailing list