Files
fpp/docs/spec/Definitions/Module-Definitions.adoc
bocchino 06cc480d41 Revise parser
Revise unit tests and spec
2020-02-21 14:19:40 -08:00

69 lines
2.0 KiB
Plaintext

=== Module Definitions
A *module definition* provides a named scope that encloses other
definitions, including other module definitions.
==== Syntax
`module`
<<Lexical-Elements_Identifiers,_identifier_>>
`{` _module-member-sequence_ `}`
_module-member-sequence_ is an
<<Element-Sequences,element sequence>> in
which each element is a *module member*,
and the terminating punctuation is a semicolon.
A module member is one of the following:
* A <<Definitions_Component-Definitions,component definition>>
* A <<Definitions_Component-Instance-Definitions,component instance definition>>
* A <<Definitions_Constant-Definitions,constant definition>>
* A <<Definitions_Module-Definitions,module definition>>
* A <<Definitions_Port-Definitions,port definition>>
* A <<Definitions_Struct-Definitions,struct definition>>
* A <<Definitions_Topology-Definitions,topology definition>>
* A <<Specifiers_Location-Specifiers,location specifier>>
* An <<Definitions_Abstract-Type-Definitions,abstract type definition>>
* An <<Definitions_Array-Definitions,array definition>>
* An <<Definitions_Enum-Definitions,enum definition>>
* An <<Specifiers_Include-Specifiers,include specifier>>
* An <<Specifiers_Init-Specifiers,init specifier>>
==== Semantics
A module definition _D_ qualifies the names of all the definitions
inside it with its own name. Inside _D_, you can refer to definitions in
_D_ by their unqualified name (the identifier appearing in the
definition) or by their qualified name. Outside _D_, you have to use the
qualified name. We say that the *scope* of the identifiers in the
definitions in _D_ is limited to the inside of _D_.
For further information about name scoping and qualification, see the
section on
<<Scoping-of-Names,Scoping of Names>>.
==== Example
[source,fpp]
----
module M {
constant a = 0
constant b = a # Inside M, we can refer to M.a as a
constant c = M.a # We can also say M.a here
}
constant d = M.a # Outside M, we have to say M.a
constant e = a # Error: a is not in scope here
----