Anvil | Smiths Smiths | Register Register | Login Login |
Search:
Show links Show tools Show tree | Previous document Next document | njet.org > Anvil > Documentation > Language reference > Statements > Definition statements > Import

Import

Locates, compiles (if necessary) and initializes (..) module, and makes it, or named entities from it, available in enclosing scope.

Imports may be declared inside modules, namespaces, classes, interfaces and functions.

Libraries (they are actually namespaces) are referenced using dotted name, such as ``anvil.sql创, libraries are searched for from lists of modules given in configuration and from default modules. Error is raised if a library could not be found. Function ``anvil.runtime.getLibraryRoot创 is used to return the root module of library namespaces. Root of libraries can also be retrieved with ``import("$$native")创 expression.

Script is referenced using string literal containing path to script. Path can be either absolute, starting from domains container, or relative to importing script. Script is parsed, compiled and initialized, if necessary. This operation might generate errors.

After scope is loaded there is choice:

If import statement does not contain list of entities then the scope is exported to declaring scope using the last part of its name, or name of from path, or altenate name if it is given with ``as创 expression.

If there is a list of entities to import, then these entities are looked up from imported scope, and exported to enclosing scope, with original name or given altenate name from import statement.

If import list is a star, ``*创, then all the entities in imported scoped are exported to enclosing scope, with their original names.

If name in import list ends with star, ``*创, then the entities in referred scope are exported to enclosing scope, with their original names.

In all situations it is an error if names of two entities clash.

Already declared or exported entities cannot be overwritten; it is an error to do so. Also note that any entities that import statement exports are not visible outside the current module.

  import        := "import" import-source [ import-as ] ";" 
  import        := "import" import-source ":" import-list ";" 
  import-name   := symbol ( "." symbol )* 
  import-source := ( string-literalpath | import-name ) 
  import-as     := "as" symbolnewname 
  import-list   := "*" 
  import-list   := import-entity  ( "," import-entity )* 
  import-entity := import-name ["." "*"] [ import-as ] 
Contributes notes:
Add a note
What's new | Anvil