www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D and file names

reply Russel Winder <russel russel.org.uk> writes:
It appears that DMD barfs on files with - in the file name.  Why?

--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder ekiga.n=
et
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
Mar 25 2011
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Fri, 25 Mar 2011 13:05:39 +0200, Russel Winder <russel russel.org.uk>  
wrote:

 It appears that DMD barfs on files with - in the file name.  Why?
Do you mean, why doesn't DMD try to work around the problem automatically (e.g. by substituting/removing invalid characters in the module identifier)? The error message answers your verbatim question. "test-file-name.d: Error: module test-file-name has non-identifier characters in filename, use module declaration instead" -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Mar 25 2011
next sibling parent reply Russel Winder <russel russel.org.uk> writes:
On Fri, 2011-03-25 at 13:10 +0200, Vladimir Panteleev wrote:
 On Fri, 25 Mar 2011 13:05:39 +0200, Russel Winder <russel russel.org.uk> =
=20
 wrote:
=20
 It appears that DMD barfs on files with - in the file name.  Why?
=20 Do you mean, why doesn't DMD try to work around the problem automatically=
=20
 (e.g. by substituting/removing invalid characters in the module =20
 identifier)? The error message answers your verbatim question.
- is a perfectly valid character in a file name, well on Posix compliant systems anyway. The question is why D, aping Java, imposes restrictions when there is no need.
 "test-file-name.d: Error: module test-file-name has non-identifier =20
 characters in filename, use module declaration instead"
The real irritant for me is that the file in question has one function, main, there is nothing to do with modules going on here. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Mar 25 2011
next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Fri, 25 Mar 2011 13:27:10 +0200, Russel Winder <russel russel.org.uk>  
wrote:

 - is a perfectly valid character in a file name, well on Posix compliant
 systems anyway.  The question is why D, aping Java, imposes restrictions
 when there is no need.
Lacking a module declaration as is your case, what would the auto-generated module name be? I'd reckon it'd be pretty much always not what the programmer expected. Allowing symbols like - in module names would complicate parsing, I'd imagine.
 The real irritant for me is that the file in question has one function,
 main,  there is nothing to do with modules going on here.
The compiler doesn't know that that module will never be imported by anything. What's the problem with adding a module declaration? -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Mar 25 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 25 Mar 2011 07:27:10 -0400, Russel Winder <russel russel.org.uk>  
wrote:

 On Fri, 2011-03-25 at 13:10 +0200, Vladimir Panteleev wrote:
 On Fri, 25 Mar 2011 13:05:39 +0200, Russel Winder <russel russel.org.uk>
 wrote:

 It appears that DMD barfs on files with - in the file name.  Why?
Do you mean, why doesn't DMD try to work around the problem automatically (e.g. by substituting/removing invalid characters in the module identifier)? The error message answers your verbatim question.
- is a perfectly valid character in a file name, well on Posix compliant systems anyway. The question is why D, aping Java, imposes restrictions when there is no need.
Every character except '/' is valid in a file name. In D, the module name must be a valid symbol, and also the name of the file you import to get that module. It's as simple as "don't name your files with non-valid symbol characters." It's the way the language is designed, and if that's too much of a burden, then don't use the language.
 "test-file-name.d: Error: module test-file-name has non-identifier
 characters in filename, use module declaration instead"
The real irritant for me is that the file in question has one function, main, there is nothing to do with modules going on here.
Every compiled d file is a module, the compiler uses the file name if you don't provide one. Note it is not advisable to name your modules differently than the file name, because the module name is also used to import the file. This means, if you named a file differently from a module, importing the module will fail to find it. However, standalone single-file programs should not be an issue. This should compile: test-file-name.d: module testfilename; void main() {} -Steve
Mar 25 2011
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/25/2011 4:10 AM, Vladimir Panteleev wrote:
 On Fri, 25 Mar 2011 13:05:39 +0200, Russel Winder <russel russel.org.uk> wrote:

 It appears that DMD barfs on files with - in the file name. Why?
Do you mean, why doesn't DMD try to work around the problem automatically (e.g. by substituting/removing invalid characters in the module identifier)? The error message answers your verbatim question. "test-file-name.d: Error: module test-file-name has non-identifier characters in filename, use module declaration instead"
The compiler synthesizes the module name from the file name. If the file name has non-valid module identifiery characters in it, it can't do that. Hence the error message. The solution is to either use a module declaration to set the module name, or rename the file to be a valid module identifier. The filename=modulename and directory=packagename equivalence allows for the compiler to simply find and load imported modules. Without it you'd need some complex database to map the module names to files.
Mar 25 2011