Language Reference/Namespaces
Namespaces can be used to avoid name clashes, without having to use long strange names. The names in two different namespaces will never clash, but it may be necessary to qualify references with the namespace (or part of it) to resolve ambiguities.
A namespaces are declared and defined implicitly using NamespaceEntrance'es:
NamespaceEntrance: namespace NamespaceIdentifier
NamespaceIdentifier: one of LowercaseIdentifier LowercaseIdentifier \ NamespaceIdentifier
In short a NamespaceIdentifier is a sequence of lowercase identifiers separated by backslashes.
Namespace Entrances and Regions
Namespace entrances divide source files into namespace regions.
A namespace entrance marks the beginning of a namespace region, which ends ends at the next namespace entrance or the end of the file.
Every file starts in the root namespace.
Namespace regions are not influenced by #include directives, meaning:
- Namespace entrances in an #include-file does not change the namespace region in the including file
- Any file starts in the root namespace (also if it is included inside a namespace region in another file).
Any interface, class and implementation that is meet inside a namespace region belongs to that namespace.
Example
class aaa end class aaa namespace xxx class bbb end class bbb namespace xxx\yyy class ccc end class ccc
This file is divided in three regions (assuming that it is a complete file). The first region is in the root namespace (\), the second region belongs to the xxx namespace and the third region belongs to the xxx\yyy namespace.
Subsequently, the class aaa belongs to the root namespace, the class bbb belongs to the namespace xxx and finally the class ccc belongs to the namespace xxx\yyy.