Is it possible to escape a reserved keyword in Import/module?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Wed Jun 19 19:07:30 UTC 2019
On Wednesday, June 19, 2019 12:56:57 PM MDT BoQsc via Digitalmars-d-learn
wrote:
> I would like to make sure that my modules do not interfere with d
> lang. Is there any way to escape reserved words?
> https://dlang.org/spec/lex.html#keywords
>
> > import alias;
>
> C:\Users\Juozas\Desktop\om.d(2): Error: identifier expected
> following import
> C:\Users\Juozas\Desktop\om.d(2): Error: ; expected
>
> > module abstract;
>
> C:\Users\Juozas\Desktop\commands\alias.d(1): Error: identifier
> expected following module
You can never use keywords as identifiers in D (or any language in the C
family that I've ever heard of). So, you can't ever declare symbols with
names like alias or abstract. The way that the official D style guide
tackles the problem is to say that any case where a keyword would be needed
should append _ to the keyword to make it a legal identifier.
https://dlang.org/dstyle.html#naming_keywords
So, that's the way that it's handled in the standard library or any other
code which follows the D style guide. e.g. The enum
std.traits.FunctionAttribute has members such as pure_, nothrow_, and
const_, since it can't use the actual keywords.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list