[Issue 8727] New: __traits(is_reserved_word, "") ?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 26 07:15:52 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8727

           Summary: __traits(is_reserved_word, "") ?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-09-26 07:16:33 PDT ---
Maybe it's worth adding a new trait that tells what currently are reserved
words of D:

assert(__traits(is_reserved_word, "import"));

For an use case see:
http://d.puremagic.com/issues/show_bug.cgi?id=6946

It replaces a function like this, that risks becoming out of date:

bool isReservedWord(in string w) {
    string[] reservedWords = "abstract alias align asm
    assert auto body bool break byte case cast catch cdouble cent cfloat
    char class const continue creal dchar debug default delegate delete
    deprecated do double else enum export extern false final finally
    float for foreach foreach_reverse function goto idouble if ifloat
    immutable import in inout int interface invariant ireal is lazy long
    macro mixin module new nothrow null out override package pragma
    private protected public pure real ref return scope shared short
    static struct super switch synchronized template this throw true try
    typedef typeid typeof ubyte ucent uint ulong union unittest ushort
    version void volatile wchar while with __FILE__ __LINE__ __gshared
    __thread __traits".split();
    return canFind(reservedWords, w);
}


Such __traits is useful to exclude the reserved words from usages in code
generation, to avoid bugs or avoid mysterious error messages.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list