www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using keywords as elements of module names?

reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I've noticed that a number of the DStress files use the word "complex" 
as part of the module name.  However, "complex" is also a keyword.

My question: Is this intentional, to be able to use keyword in module 
names?  Or is this a bug?

My comment: It makes files harder to parse, at least with some types of 
parsers, to allow keywords there.  I have a D parsing tool that uses lex 
as its lexer; basically, lex looks for all of the known keywords first. 
  Then, any string that is not a keyword but looks like an identifier is 
taken as an identifier.  The problem that I get here is that my parser 
expects a module declaration (and, similarly, an import statement) to be 
a string of identifiers separated by '.' tokens.  But now I have to 
alter the parser so that it will also handle the "complex" keyword in 
any of those places....in fact, I have to alter it to be able to hand 
just about any D keyword.  That makes the parser much harder to write.

My request: Can we ban this?

Russ
Aug 14 2005
next sibling parent Derek Parnell <derek psych.ward> writes:
On Sun, 14 Aug 2005 07:09:54 -0700, Russ Lewis wrote:

 I've noticed that a number of the DStress files use the word "complex" 
 as part of the module name.  However, "complex" is also a keyword.
"complex" is not a keyword in the DMD that I'm using. DMD v0.129 Windows.
 My question: Is this intentional, to be able to use keyword in module 
 names?  Or is this a bug?
Keywords in module names are forbidden in D. -- Derek Parnell Melbourne, Australia 15/08/2005 12:14:12 AM
Aug 14 2005
prev sibling parent xs0 <xs0 xs0.com> writes:
Russ Lewis wrote:
 I've noticed that a number of the DStress files use the word "complex" 
 as part of the module name.  However, "complex" is also a keyword.
 
 My question: Is this intentional, to be able to use keyword in module 
 names?  Or is this a bug?
 
 My comment: It makes files harder to parse, at least with some types of 
 parsers, to allow keywords there.  I have a D parsing tool that uses lex 
 as its lexer; basically, lex looks for all of the known keywords first. 
  Then, any string that is not a keyword but looks like an identifier is 
 taken as an identifier.  The problem that I get here is that my parser 
 expects a module declaration (and, similarly, an import statement) to be 
 a string of identifiers separated by '.' tokens.  But now I have to 
 alter the parser so that it will also handle the "complex" keyword in 
 any of those places....in fact, I have to alter it to be able to hand 
 just about any D keyword.  That makes the parser much harder to write.
 
 My request: Can we ban this?
 
 Russ
I don't know exactly what tool you're building the parser for, but a workaround at least regarding type keywords would be to not treat them as keywords in the first place - I don't think there's anything in the syntax that actually requires them to be keywords (you can alias them anyway, so everything that works on those keywords must also work on generic identifiers) xs0
Aug 14 2005