Tagged enums why reserved words are not permitted ?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 27 18:00:45 PDT 2014


On Tue, 28 Oct 2014 00:31:43 +0000
Domingo via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> Hello !
> 
> I'm not sure if I'm missing something here but for a tagged enum 
> it doesn't seem to make sense to forbid reserved keywords like:
> 
> enum CrudOps {read, write, delete}
> 
> The dmd compiler are complaining:
> ------
> cte.d(4): Error: basic type expected, not delete
> cte.d(4): Error: no identifier for declarator int
> cte.d(4): Error: type only allowed if anonymous enum and no enum 
> type
> cte.d(4): Error: if type, there must be an initializer
> cte.d(4): Error: found 'delete' when expecting ','
> ------
> 
> It doesn't make sense to me because this kind of enum will not 
> polute the global space and always need to beused with the tag: 
> CrudOps.delete
> 
> I'm missing something here ?
> 
> Cheers !
D has no "context keywords". i.e. no keyword can be used as identifier,
even if it's possible to distinguish between use cases. you can't, for
example, use "body" identifier for variable/field name (and this annoys
me alot).

i believe that this was done so source code analyzing tools can stop
tracking context while parsing D source. i.e. tool is not required to
do semantic analysis to determine if "body" is identifier or function
body start.

i don't think that this will change. and this is the reason, for
example, for adding "@property", "@safe", "@trusted" and so on instead
of "property", "safe", "trusted": D taken some valuable keywords
already and nobody wants to lose even more names. ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141028/225fce12/attachment.sig>


More information about the Digitalmars-d-learn mailing list