Previous: Systems, Up: Dezyne Language Reference [Contents][Index]
All component, interface, and type definitions are defined in a
namespace
, which provides name scoping. The scope is used as a
prefix when referring to the name from another scope.
namespace ::= "namespace" compound-identifier "{" namespace-root "}" namespace-root ::= (namespace | type | interface | component)* compound-identifier ::= scope* identifier scope ::= identifier "."
For example:
namespace space { extern string $std::string$; interface ihello { enum result {FALSE, TRUE, ERROR}; in result hello (string s); out void world (); behavior { on hello (s): reply (result.TRUE); } } }
It is allowed to spread the definition of types, interfaces, components, and sub-namespaces over multiple instances of a namespace scope. This is most useful since in a ’real’ project definitions are spread over multiple files.
So
namespace space { extern string $std::string$; interface ihello { ... } }
is equivalent to
namespace space { extern string $std::string$; } namespace space { interface ihello { ... } }
When within namespace space
the type string
is defined,
then outside that namespace it is referred to by prefixing it with the
name of that namespace and a dot, as in: space.string
.
Within its own namespace the short name string
is also accepted.
In complex cases it may be necessary to refer to the default global namespace which has an empty name; this results in a namespace prefix starting with a dot, as can be seen in the following (somewhat convoluted) example.
namespace foo { interface I { enum Bool {F,T}; in Bool e(); out void a(); behavior { on e: {a; reply (Bool.T); } } } } namespace inner { namespace foo { interface I { enum Bool {f,t}; in Bool e(); out void a(); behavior { } } } component space { provides foo.I inner; provides .foo.I fooi; behavior { foo.I.Bool inner_state = foo.I.Bool.t; .foo.I.Bool foo_state = .foo.I.Bool.T; on inner.e(): { } on fooi.e(): { } } } } namespace bar { component c { provides foo.I i; behavior { foo.I.Bool state = foo.I.Bool.T; on i.e(): { } } } }
which defines:
foo.I
with local enum foo.I.Bool
inner.foo.I
with local enum inner.foo.I.Bool
inner.space
bar.c
The two variables defined in component inner.space
have types
foo.I.Bool
and .foo.I.Bool
respectively. The first type
expands to inner.foo.I.Bool
since it is defined in namespace
inner
. The starting dot in the second definition prevents this
expansion.
Previous: Systems, Up: Dezyne Language Reference [Contents][Index]