Thread overview
Unexpected restriction of file names ???
Nov 09, 2005
Georg Wrede
Nov 09, 2005
J C Calvarese
Nov 10, 2005
Georg Wrede
November 09, 2005
I have the following file, called foo-bar.d:

void main(){}

Trying to compile this gives the following error message:

$dmd foo-bar.d
foo-bar.d: module foo-bar has non-identifier characters in filename, use module declaration instead


I fear this is on purpose, so I didn't post on Bugs.
But this is unexpected behavior from a compiler.

--------------------

Doing my homework while writing this, I found out that the following change does away with the problem:

module foobar;
void main(){}


Now "dmd foo-bar.d" compiles ok.

--------------------

This should at least get more prominent in the docs, and if there ever will be a faq, this should be there too.
November 09, 2005
"Georg Wrede" <georg.wrede@nospam.org> wrote in message news:4371B4D9.5000907@nospam.org...
>I have the following file, called foo-bar.d:
>
> void main(){}
>
> Trying to compile this gives the following error message:
>
> $dmd foo-bar.d
> foo-bar.d: module foo-bar has non-identifier characters in filename, use
> module declaration instead
>
>
> I fear this is on purpose, so I didn't post on Bugs.
> But this is unexpected behavior from a compiler.
>
> --------------------
>
> Doing my homework while writing this, I found out that the following change does away with the problem:
>
> module foobar;
> void main(){}
>
>
> Now "dmd foo-bar.d" compiles ok.
>
> --------------------
>
> This should at least get more prominent in the docs, and if there ever will be a faq, this should be there too.

It makes sense if you think about it.  If you don't have a module declaration, it takes the name from the filename; since "foo-bar" is an illegal identifier, it doesn't compile.  Module identifiers have the same naming restrictions as any other entity in D; begin with an alpha or underscore, and then alphanum or underscore for the rest.

Just curious, what would you like it to do instead?


November 09, 2005
In article <4371B4D9.5000907@nospam.org>, Georg Wrede says...
>
>I have the following file, called foo-bar.d:
>
>void main(){}
>
>Trying to compile this gives the following error message:
>
>$dmd foo-bar.d
>foo-bar.d: module foo-bar has non-identifier characters in filename, use
>module declaration instead
>
>
>I fear this is on purpose, so I didn't post on Bugs.
>But this is unexpected behavior from a compiler.
>
>--------------------
>
>Doing my homework while writing this, I found out that the following change does away with the problem:
>
>module foobar;
>void main(){}
>
>
>Now "dmd foo-bar.d" compiles ok.
>
>--------------------
>
>This should at least get more prominent in the docs, and if there ever will be a faq, this should be there too.

I think it's already covered in the docs, but perhaps it should be clearer.

From http://www.digitalmars.com/d/module.html:

Modules have a one-to-one correspondence with source files. The module name is the file name with the path and extension stripped off.

Modules automatically provide a namespace scope for their contents. Modules superficially resemble classes, but differ in that:

..



Module Declaration

The ModuleDeclaration sets the name of the module and what package it belongs to. If absent, the module name is taken to be the same name (stripped of path and extension) of the source file name.

jcc7
November 10, 2005
J C Calvarese wrote:
> In article <4371B4D9.5000907@nospam.org>, Georg Wrede says...
> 
>>I have the following file, called foo-bar.d:
>>
>>void main(){}
>>
>>Trying to compile this gives the following error message:
>>
>>$dmd foo-bar.d
>>foo-bar.d: module foo-bar has non-identifier characters in filename, use module declaration instead
>>
>>
>>I fear this is on purpose, so I didn't post on Bugs.
>>But this is unexpected behavior from a compiler.
>>
>>--------------------
>>
>>Doing my homework while writing this, I found out that the following change does away with the problem:
>>
>>module foobar;
>>void main(){}
>>
>>
>>Now "dmd foo-bar.d" compiles ok.
>>
>>--------------------
>>
>>This should at least get more prominent in the docs, and if there ever will be a faq, this should be there too.
> 
> 
> I think it's already covered in the docs, but perhaps it should be clearer.

Exactly.