compile-time regexp lib released

Marton Papp anteusz at freemail.hu
Wed Aug 8 07:08:49 PDT 2007


== Quote from Robert Fraser (fraserofthenight at gmail.com)'s article
> Marton Papp Wrote:
> > Hi!
> >
> > I do not mind. Except I do not understand your choice of __1, __2..
> > why not _1,_2,_3?
> > Or dollar1,dollar2,dollar3?
> > and would you fork it or would you like it to be added to scregexp?
> >
> > Regards
> >
> > Marton Papp
> I was just going to extend it for my project when I eventually get around to it,
probably not for another few months (I want to see Descent get as strong an IDE as
JDT before I start splitting my attention). If you think it might be useful for
scregexp, I don't think it'd be too hard to add.
> Thinking a bit more about it, an array might be better for that. _[0] would be
the first capture, _[1] the second, etc. But that still doesn't allow something
awesome like:
> if(str =~ m/(\d+)_(\w+)/)
> {
>     print "$1 = $2";
> }
> ... or how I'd like to see it in D:
> if(str.matches(`(\d+)_(\w+)`)
> {
>     writefln("%d = %d", _[0], _[1]);
> }
> ... where matches() compiles the regex at compile time like scregex.
> Oh well, maybe AST macros will open up that possibility, though I'm not sure
exactly how that's work.
Have a look how it is now!
import scregexp;
auto groups=indexgroups!(`(\d+)_(\w+)`)(str));
if (groups !is null)
{
 writefln("%d = %d", group(str,groups,0), group(str,groups,1));
}

I cannot see how this can be done in D at all
if(str.matches(`(\d+)_(\w+)`)
> {
>     writefln("%d = %d", _[0], _[1]);
> }
T

Marton Papp







More information about the Digitalmars-d mailing list