Skip to main content

Module Declaration

rascal-0.34.0

Synopsis

Declare a module.

Syntax

module Package::Name        

Import₁
Extend₁
...
Importₙ
Extendₙ

SyntaxDefinition₁
...
SyntaxDefinition₂

Declaration₁
...
Declarationₙ

Description

A module declaration consists of:

The Import, Extend and Syntax Definition are positioned at the top of the module because they are used internally to generate parsers for the Concrete Syntax, Patterns and Expressions used in Variables, Functions and Algebraic Data Types.

The module name Name will be used when the current module is imported in another module. A module name is in general a qualified name of the form:

_Name₁_::_Name₂_:: ... ::_Nameₙ_

which corresponds to a path relative to the root of the current workspace.

The constituents of a module are shown in the figure below.

module-parts.png

An Import declares other modules that are used by the current module. Following imports, a module may contain declarations (in arbitrary order, but a Syntax Definition can occur directly following the imports) for:

Each declaration may contain a private or public keyword that determines the visibility of the declared entity.

The entities that are visible inside a module are

  • The private or public entities declared in the module itself.

  • The public entities declared in any imported module.

The only entities that are visible outside the module, are the public entities declared in the module itself. If different imported modules declare the same visible name, it can be disambiguated by explicitly qualifying it with its module name:

_Module_ :: _Name_

Each module resides in a separate file with extension .rsc.

Examples

Here is the Hello module:

module demo::basic::Hello

import IO;

void hello() {
println("Hello world!");
}

It defines a module with the name demo::basic::Hello and imports the IO library. Finally, it declares the hello function.