[Issue 23544] New: Allow enum types be defined with semicolons

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 8 14:48:28 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23544

          Issue ID: 23544
           Summary: Allow enum types be defined with semicolons
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: qs.il.paperinik at gmail.com

Currently, an enum type is defined with this syntax:
```d
enum Identifier { Value1, Value2, Value3 }
```
(Note: A trailing comma is allowed, but not required.)

It would be nice to allow semicolon syntax as well:
```d
enum Identifier { Value1; Value2; Value3; }
```
(Note: A semicolon for the last value is required.)


It would make meta-programming easier. A `static foreach` cannot generate a
comma-separated list, but it can generate a list of declarations.
Otherwise, one has to use string mixins which – apart from being hard to read –
have the limitation that naming symbols that are inaccessible due to visibility
attributes (private, usually) can be fed into and used by a template via an
alias, but using the name is a non-starter. (This is to prove that it solves an
issue actually present in the language.)

Grammar changes:
```diff
    EnumBody:
        { EnumMembers }
        ;

    EnumMembers:
+       EnumCommaMembers
+       EnumSemicolonMembers
+       
+   EnumCommaMembers:
        EnumMember
        EnumMember ,
        EnumMember , EnumMembers

+   EnumSemicolonMembers:
+       EnumMember ;
+       EnumMember ; EnumSemicolonMembers

    AnonymousEnumDeclaration:
        enum : EnumBaseType { EnumMembers }
        enum { EnumMembers }
        enum { AnonymousEnumMembers }

    AnonymousEnumMembers:
+       AnonymousCommaEnumMembers
+       AnonymousSemicolonEnumMembers

+   AnonymousCommaEnumMembers
        AnonymousEnumMember
        AnonymousEnumMember ,
        AnonymousEnumMember , AnonymousEnumMembers

+   AnonymousSemicolonEnumMembers:
+       AnonymousEnumMember ;
+       AnonymousEnumMember ; AnonymousSemicolonEnumMembers
```

--


More information about the Digitalmars-d-bugs mailing list