[GSOC] regular expressions beta is here

bearophile bearophileHUGS at lycos.com
Tue Aug 16 16:47:10 PDT 2011


Dmitry Olshansky:

> > To get a small no-crap-included beta package see download section of 
> > https://github.com/blackwhale/FReD for .7zs.

I have not patched DMD, but it gives me some problem here:

void parseFlags(S)(S flags)
{
    foreach(ch; flags)//flags are ASCII anyway
    {
        switch(ch)
        {

            foreach(i, op; __traits(allMembers, RegexOption))
            {
                case RegexOptionNames[i]:
                        if(re_flags & mixin("RegexOption."~op))
                            throw new RegexException(text("redundant flag specified: ",ch));
                        re_flags |= mixin("RegexOption."~op);
                        break;
            }
            default:
                if(__ctfe)
                   assert(text("unknown regex flag '",ch,"'"));
                else
                    new RegexException(text("unknown regex flag '",ch,"'"));
        }


To better see the situation I have written a small test case:

import std.typetuple: TypeTuple;

enum RegexOption : uint { A, B, C } // no need to put a semicolon here

alias TypeTuple!(RegexOption.A, RegexOption.B, RegexOption.C) RegexOptionNames;

void main() {
    RegexOption ch;

    switch (ch) {
        foreach (i, op; __traits(allMembers, RegexOption))
            case RegexOptionNames[i]: break;

        default: assert(0);
    }
}


test.d(12): Error: switch case fallthrough - use 'goto case;' if intended
test.d(12): Error: switch case fallthrough - use 'goto case;' if intended
test.d(12): Error: switch case fallthrough - use 'goto case;' if intended
test.d(14): Error: switch case fallthrough - use 'goto default;' if intended

This used to work, I think. The new DMD switch analysis seems to have a bug.

-------------

If you want a benchmark, to compare it with other implementations, there is this one:
http://shootout.alioth.debian.org/debian/program.php?test=regexdna&lang=gdc&id=4

Bye,
bearophile


More information about the Digitalmars-d mailing list