Make an enum idiomatic D - enhancing GNU Bison's Dlang support

Bastiaan Veelo Bastiaan at Veelo.net
Thu Sep 3 14:19:07 UTC 2020


On Thursday, 3 September 2020 at 14:05:10 UTC, Bastiaan Veelo 
wrote:
> enum SymbolKindEnum {
>     S_YYEMPTY = -2,  /* No symbol.  */
>     S_YYEOF = 0,     /* "end of file"  */
>     S_YYerror = 1,   /* error  */
>     /* ... */
>     S_input = 14,    /* input  */
>     S_line = 15,     /* line  */
>     S_exp = 16,      /* exp  */
> }

By the way, since you are specifically asking about idiomatic D, 
the common prefix "S_" in enum members is unnecessary in D, since 
D already punts these in a separate name space. I can immagine 
you'd prefer to keep things like it is to have some uniformity 
among back ends, but if D were the only one you could do this 
instead:

enum S {
      YYEMPTY = -2,  /* No symbol.  */
      YYEOF = 0,     /* "end of file"  */
      YYerror = 1,   /* error  */
      /* ... */
      input = 14,    /* input  */
      line = 15,     /* line  */
      exp = 16,      /* exp  */
}

And refer to enum members as S.YYEOF (instead of S_YYEOF in other 
back ends).

-- Bastiaan.


More information about the Digitalmars-d mailing list