A Stratego program is organized as a collection of modules, which are imported from a main module.
module $ModuleName $Imports* $Section*
A module starts with a module header followed by a list of
The name of a module in the header and imports should correspond to the file name, relative to a 'root' directory.
The rest of a module consists of
strategies sections, in any order, and possibly repeated.
File Name and File Extension¶
A module coincides with the file it resides in. It is not possible to define more than one module in a file, which precludes nested modules. The name of a module coincides with the file name, which should be fully qualified relative to a root directory.
A Stratego is a file with the extension
.str2 for Stratego 2.
Modules for the Stratego 1 version of the language have extension
The file extension does not feature in the module names used in the language.
The following is example module header:
module compilation/translation imports desugaring/desugar
Module names can be hierarchical. For example, consider the following directory structure
- trans - compilation - optimization.str2 - translation.str2 - desugaring - desugar.str2
/to indicate the directory structure, relative to a 'root' directory.
For example, if
trans is declared as a root, then the module names for the modules above are
- compilation/optimization - compilation/translation - desugaring/desugar
A module should import all other modules from which it uses definitions. Imports are non-transitive and may be mutually recursive.
Modules can extend rule and strategy definitions from other modules. This allows the modular extension of a language.
When imported, all definitions in a module are visible. There are currently no mechanisms for hiding definitions.
imports can list multiple modules.
imports A B
is equivalent to
imports A imports B
A signature section introduces sorts, constructors, and overlays.
signature sorts $Sort* constructors $ConstructorDef* overlays $OverlayDef*
Rules and Strategies¶
strategies section headers are indicative only; rule and strategy definitions can actually be mixed.
A Stratego library is a closed collection of modules. A library can be pre-compiled since client programs may not extend its definitions. A library is used by importing a collection of external definitions of the signatures of constructors and transformations it defines. Even if definitions in a library are not included in a libraries external definition, they cannot be redefined, as that produces link errors.
When using concrete syntax in a module, a
.meta file accompanying the module indicates the parse table to use.