Compare commits
12 commits
main
...
feature/si
Author | SHA1 | Date | |
---|---|---|---|
44c5009151 | |||
e13251ed65 | |||
2940595a94 | |||
67e19ac51f | |||
3fe82297b5 | |||
f8550ef836 | |||
5fd8498724 | |||
aab7c2bef3 | |||
5c26a69c8e | |||
15e5536305 | |||
f4e41ad808 | |||
810b2abd20 |
|
@ -6,11 +6,16 @@ Using directives ([Using directives](namespaces.md#using-directives)) are provid
|
|||
|
||||
## Compilation units
|
||||
|
||||
A *compilation_unit* defines the overall structure of a source file. A compilation unit consists of zero or more *using_directive*s followed by zero or more *global_attributes* followed by zero or more *namespace_member_declaration*s.
|
||||
A *compilation_unit* defines the overall structure of a source file. A compilation unit consists of zero or more *using_directive*s followed by zero or more *global_attributes* followed by a *compilation_unit_body*. A *compilation_unit_body* can either be a *single_line_namespace* or zero or more *namespace_member_declaration*s.
|
||||
|
||||
```antlr
|
||||
compilation_unit
|
||||
: extern_alias_directive* using_directive* global_attributes? namespace_member_declaration*
|
||||
: extern_alias_directive* using_directive* global_attributes? compilation_unit_body
|
||||
;
|
||||
|
||||
compilation_unit_body
|
||||
: namespace_member_declaration*
|
||||
| single_line_namespace
|
||||
;
|
||||
```
|
||||
|
||||
|
@ -34,14 +39,21 @@ class B {}
|
|||
|
||||
The two compilation units contribute to the single global namespace, in this case declaring two classes with the fully qualified names `A` and `B`. Because the two compilation units contribute to the same declaration space, it would have been an error if each contained a declaration of a member with the same name.
|
||||
|
||||
A *single_line_namespace* will contribute members corresponding to the *namespace_declaration* it is semantically equivalent to. See ([Namespace Declarations](#namespace-declarations)) for more details.
|
||||
|
||||
## Namespace declarations
|
||||
|
||||
A *namespace_declaration* consists of the keyword `namespace`, followed by a namespace name and body, optionally followed by a semicolon.
|
||||
A *single_line_namespace_declaration* consists of the keyword `namespace`, followed by a namespace name, a semicolon and an optional list of directives and type declarations.
|
||||
|
||||
```antlr
|
||||
namespace_declaration
|
||||
: 'namespace' qualified_identifier namespace_body ';'?
|
||||
;
|
||||
|
||||
single_line_namespace_declaration
|
||||
: 'namespace' qualified_identifier ';' extern_alias_directive* using_directive* type_declaration*
|
||||
;
|
||||
|
||||
qualified_identifier
|
||||
: identifier ('.' identifier)*
|
||||
|
@ -95,6 +107,35 @@ namespace N1.N2
|
|||
```
|
||||
the two namespace declarations above contribute to the same declaration space, in this case declaring two classes with the fully qualified names `N1.N2.A` and `N1.N2.B`. Because the two declarations contribute to the same declaration space, it would have been an error if each contained a declaration of a member with the same name.
|
||||
|
||||
A *single_line_namespace_declaration* permits a namespace declaration to be written without the `{ ... }` block. For example:
|
||||
|
||||
```csharp
|
||||
namespace Name;
|
||||
|
||||
extern alias A;
|
||||
using B;
|
||||
|
||||
class C
|
||||
{
|
||||
}
|
||||
```
|
||||
is semantically equivalent to
|
||||
```csharp
|
||||
namespace Name
|
||||
{
|
||||
extern alias A;
|
||||
using B;
|
||||
|
||||
class C
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Specifically, a *single_line_namespace_declaration* is treated the same as a *namespace_declaration* at the same location in the *compilation_unit* with the same *qualified_identifier*. The *extern_alias_directive*s, *using_directive*s and *type_declaration*s of that *single_line_namespace_declaration* act as if they were declared in the same order inside the *namespace_body* of that *namespace_declaration*.
|
||||
|
||||
A source file cannot contain both a *single_line_namespace_declaration* and a *namespace_declaration*. A source file cannot contain multiple *single_line_namespace_declaration*s. A *compilation_unit* cannot contain both a *single_line_namespace_declaration* and any *statement* at the top level.
|
||||
|
||||
## Extern aliases
|
||||
|
||||
An *extern_alias_directive* introduces an identifier that serves as an alias for a namespace. The specification of the aliased namespace is external to the source code of the program and applies also to nested namespaces of the aliased namespace.
|
||||
|
|
Loading…
Reference in a new issue