|
| 1 | +# Unnamed Libraries |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +Version 1.0 |
| 6 | + |
| 7 | +Specification for issue [#1073](https://github.com/dart-lang/language/issues/1073) |
| 8 | + |
| 9 | +## Motivation |
| 10 | + |
| 11 | +Users would like to both document a library and associate metadata with a |
| 12 | +library without needing to decide on a library name. |
| 13 | + |
| 14 | +Declaring a library with a library declaration has become increasingly rare, |
| 15 | +with the availability of a 'part of' syntax with a URI string, and with the |
| 16 | +decline of the mirror system. Tools such as dartdoc and the test package |
| 17 | +attempt to support "library-level" documentation comments and annotations by |
| 18 | +looking at such elements associated with the first directive in a library, or |
| 19 | +the first declaration. Allowing users to write `library;` without a name gives |
| 20 | +a specific and meaningful syntax for library-level documentation and metadata. |
| 21 | +With this syntax, users do not need to conceive of a unique library naming |
| 22 | +scheme, nor do they need to write out names which are never used. |
| 23 | + |
| 24 | +## Specification |
| 25 | + |
| 26 | +With this feature, library directives are allowed to be written without a name: |
| 27 | + |
| 28 | +```dart |
| 29 | +// Existing named library syntax: |
| 30 | +library qualified.named.separated.by.dots; |
| 31 | +
|
| 32 | +// New unnamed library syntax: |
| 33 | +library; |
| 34 | +``` |
| 35 | + |
| 36 | +Prior to this feature, a library can be _explicitly named_ with a library |
| 37 | +directive, or _implicitly named_ when written without a library directive. An |
| 38 | +implicitly named library has the empty string as its name. With this feature, a |
| 39 | +library with a library directive without a name is an implicitly named library. |
| 40 | + |
| 41 | +### Grammar |
| 42 | + |
| 43 | +The language grammar is changed to allow library directives without name. |
| 44 | + |
| 45 | +The section containin |
| 46 | + |
| 47 | +> ```latex |
| 48 | +> <libraryName> ::= <metadata> \LIBRARY{} <dottedIdentifierList> `;' |
| 49 | +> ``` |
| 50 | +
|
| 51 | +becomes: |
| 52 | +
|
| 53 | +> ```latex |
| 54 | +> <libraryName> ::= <metadata> \LIBRARY{} <dottedIdentifierList>? `;' |
| 55 | +> ``` |
| 56 | +
|
| 57 | +### Parts |
| 58 | +
|
| 59 | +A library part specifies the library to which it belongs using the part-of |
| 60 | +directive, which accepts two ways of referring to a library. A part-of |
| 61 | +directive can specify a library by URI, which is the more common way, and does |
| 62 | +not require the library to be explicitly named. In an older style, a part-of |
| 63 | +directive can instead specify a library by its name. A part-of directive cannot |
| 64 | +refer by name to an implicitly named library. Therefore, with this feature, a |
| 65 | +part-of directive using a library name cannot refer to a library with a library |
| 66 | +directive without a name. |
| 67 | +
|
| 68 | +### `dart:mirrors` |
| 69 | +
|
| 70 | +The mirror system has at least one mechanism that uses a library's name, |
| 71 | +`MirrorSystem.findLibrary`. This function cannot find an implicitly named |
| 72 | +library. Therefore it cannot find a library with a library directive without a |
| 73 | +name. |
| 74 | +
|
| 75 | +## Summary |
| 76 | +
|
| 77 | +We allow library directives without name. |
| 78 | +
|
| 79 | +## Versions |
| 80 | +
|
| 81 | +1.0, 2022-09-14: Initial version |
0 commit comments