digitalmars.D.learn - Is it possible to escape a reserved keyword in Import/module?
- BoQsc (8/10) Jun 19 2019 I would like to make sure that my modules do not interfere with d
- Jonathan M Davis (13/23) Jun 19 2019 You can never use keywords as identifiers in D (or any language in the C
- Basile B. (8/26) Jun 19 2019 C# can use them when they are prefixed with a little "@" before
- XavierAP (7/10) Jun 19 2019 The only reason C# allows this is for interop or code generation
-
Basile B.
(8/18)
Jun 19 2019
I used twice a similar system (&
) that exists in ObjFPC.
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#keywordsimport alias;C:\Users\Juozas\Desktop\om.d(2): Error: identifier expected following import C:\Users\Juozas\Desktop\om.d(2): Error: ; expectedmodule abstract;C:\Users\Juozas\Desktop\commands\alias.d(1): Error: identifier expected following module
Jun 19 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#keywordsYou 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 Davisimport alias;C:\Users\Juozas\Desktop\om.d(2): Error: identifier expected following import C:\Users\Juozas\Desktop\om.d(2): Error: ; expectedmodule abstract;C:\Users\Juozas\Desktop\commands\alias.d(1): Error: identifier expected following module
Jun 19 2019
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:[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/filesI 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#keywordsYou can never use keywords as identifiers in D (or any language in the C family that I've ever heard of).import alias;C:\Users\Juozas\Desktop\om.d(2): Error: identifier expected following import C:\Users\Juozas\Desktop\om.d(2): Error: ; expectedmodule abstract;C:\Users\Juozas\Desktop\commands\alias.d(1): Error: identifier expected following module
Jun 19 2019
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 interfereThen don't name them as keywords :)
Jun 19 2019
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 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"...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 interfereThen don't name them as keywords :)
Jun 19 2019