Template regexes, version 2

Walter Bright newshound at digitalmars.com
Tue Feb 21 09:27:08 PST 2006


"Don Clugston" <dac at nospam.com.au> wrote in message 
news:dtev42$1g98$1 at digitaldaemon.com...
> Perl-ish languages deal with the last case by allowing embedded variables 
> in strings. The template regexes Ive been developing can cope with them by 
> using additional parameters and extended syntax, eg @1 for the string 
> value of the first parameter.
> eg
>
> char [] var1 = "here";
> char [] input = " a56aherea";
> char [] x = firstmatch!("a at 1a")(input, var1);
> var1 = "56";
> char [] y = firstmatch!("a at 1a")(input, var1);
>
> would give x == "aherea", y=="aherea".

Great! But can I suggest using the format used by 
std.regexp.RegExp.replace() ? It uses $$, $&, $`, $', and $n.

> How good is DMD at performing this optimisation?

Not good enough. But I wouldn't worry about that for the moment.

> I don't know where to go from here. There are a few possibilities:
> 1. use template regexps as a demonstration of the power of D templates.
> --> Implement reduced syntax, keep the code simple and not well optimised; 
> more of a proof-of-concept; go for "maximum coolness".
> 2. Like 1, but with optimisations; try to be the fastest regexp of any 
> language. (cleaner-faster-better ... but we use the built-in regexps 
> anyway <g>).
> 3. Create a standard library. This is what I was aiming for, but I don't
> think it makes sense any more.
> 4. potential integration into the language. Is this even possible?
>
> Probably the most sensible is to go with 1, to wake up the C++/boost 
> crowd. Hopefully this should also provide some direction for the built-in 
> syntax.
> Thoughts?

#1. No question about it! 





More information about the Digitalmars-d mailing list