Import form interface folder will not work

Monkey Forums/Monkey Programming/Import form interface folder will not work

Shagwana(Posted 2013) [#1]
I have an application setup with the following structure in the root folder...

main.monkey
incs/interface/example.monkey

The following code throws an incorrect error

Import incs.interface.example

Error : Syntax error - expecting identifier.



This is because the import command is getting mixed up with the keyword interface.


Goodlookinguy(Posted 2013) [#2]
Interface is a reserved keyword. This isn't a bug. You can't use reserved keywords as anything but their functionality.


Shagwana(Posted 2013) [#3]
Yes it is a reserved keyword however its being used in a path for includes.

As it stands at the moment, you are not allowed to import from a folder that shares a keywords.

If this is indeed intended then the above error should be clearer.


Goodlookinguy(Posted 2013) [#4]
The error is pretty clear.

Taking from what you wrote...
Import incs.interface.example
It generates tokens as such...
Keyword Identifier Symbol Keyword Symbol Identifier
Now, when it's compiling, when the parser sees the keyword Import, it looks for (in EBNF)
"Import" { identifier ["."] }
However, with yours it gets
"Import" identifier "." keyword "." identifier
So it's looking for an identifier when it suddenly stumbles upon the keyword and when that happens it then gives you the error...
Error : Syntax error - expecting identifier.



Shinkiro1(Posted 2013) [#5]
The error is pretty clear.

How about: "The keyword interface can not be used in import paths."


DruggedBunny(Posted 2013) [#6]
It's a little bit off the beaten path in the docs, but I think the below (from the Language Reference docs) would apply here, as the module filename forms part of the scope for the module and is considered an identifier:


Modules

A Monkey module corresponds to a single Monkey source file, and provides a named scope for the constants, globals, functions and classes declared in that file. Every Monkey source file declares a module, and every module has an associated source file.

The name of the module scope is the same as the name of the file (minus the directory path and file extension), so the names of Monkey source files must also be valid Monkey identifiers.



The module name (or the path part of it at least) would therefore conflict with the existing Interface identifier. (Also, language keywords are case-insensitive, so 'indentifier' is still the same as 'Identifier'.)


Shagwana(Posted 2013) [#7]
Well that makes sense now I have read it, cheers