www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is it possible to escape a reserved keyword in Import/module?

reply BoQsc <vaidas.boqsc gmail.com> writes:
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
Jun 19 2019
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
Jun 19 2019
parent Basile B. <b2.temp gmx.com> writes:
On Wednesday, 19 June 2019 at 19:07:30 UTC, Jonathan M Davis 
wrote:
 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).
[1]. At some point the idea was brought for D [2]. [1] https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/index [2] https://github.com/dlang/DIPs/pull/52/files
Jun 19 2019
prev sibling parent reply XavierAP <n3minis-git yahoo.es> writes:
On Wednesday, 19 June 2019 at 18:56:57 UTC, BoQsc wrote:
 I would like to make sure that my modules do not interfere with 
 d lang. Is there any  way to escape reserved words?
for other languages that use the same keyword. For example "class" is an HTML attribute. gurus would also agree.
 I would like to make sure that my modules do not interfere
Then don't name them as keywords :)
Jun 19 2019
parent Basile B. <b2.temp gmx.com> writes:
On Wednesday, 19 June 2019 at 21:21:53 UTC, XavierAP wrote:
 On Wednesday, 19 June 2019 at 18:56:57 UTC, BoQsc wrote:
 I would like to make sure that my modules do not interfere 
 with d lang. Is there any  way to escape reserved words?
generation for other languages that use the same keyword. For example "class" is an HTML attribute. gurus would also agree.
 I would like to make sure that my modules do not interfere
Then don't name them as keywords :)
I used twice a similar system (&<keyword>) that exists in ObjFPC. The context was a RTTI inspector and allowed to have enum members displayed without using a prefix or a translation table. Just to say, it's rarely useful but nice to have. "do" change, which was a bad decision because focused on a detail. You mentioned "class"...
Jun 19 2019