|
55 | 55 |
|
56 | 56 | ```
|
57 | 57 |
|
58 |
| -WIT packages can be defined in a collection of files and at least one of them |
59 |
| -must specify a package name. Multiple files can specify a `package` and |
60 |
| -they must all agree on what the package name is. |
| 58 | +WIT packages can be defined in a collection of files. At least one of these |
| 59 | +files must specify a package name. Multiple files can specify the `package`, |
| 60 | +though they must all agree on what the package name is. |
| 61 | + |
| 62 | +Alternatively, many packages can be declared consecutively in one or more |
| 63 | +files, if the "explicit" package notation is used: |
| 64 | + |
| 65 | +```wit |
| 66 | +package local:a { |
| 67 | + interface foo {} |
| 68 | +} |
| 69 | +
|
| 70 | +package local:b { |
| 71 | + interface bar {} |
| 72 | +} |
| 73 | +``` |
61 | 74 |
|
62 | 75 | Package names are used to generate the [names of imports and exports]
|
63 | 76 | in the Component Model's representation of [`interface`s][interfaces] and
|
@@ -848,7 +861,34 @@ readability but this isn't required.
|
848 | 861 | Concretely, the structure of a `wit` file is:
|
849 | 862 |
|
850 | 863 | ```ebnf
|
851 |
| -wit-file ::= package-decl? (toplevel-use-item | interface-item | world-item)* |
| 864 | +wit-file ::= explicit-package-list | implicit-package-definition |
| 865 | +``` |
| 866 | + |
| 867 | +Files may be organized in two arrangements. The first of these is as a series |
| 868 | +of multiple consecutive "explicit" `package ... {...}` declarations, with the |
| 869 | +package's contents contained within the brackets. |
| 870 | + |
| 871 | +```ebnf |
| 872 | +explicit-package-list ::= explicit-package-definition* |
| 873 | +
|
| 874 | +explicit-package-definition ::= package-decl '{' package-items* '}' |
| 875 | +``` |
| 876 | + |
| 877 | +Alternatively, a file may "implicitly" consist of an optional `package ...;` |
| 878 | +declaration, followed by a list of package items. |
| 879 | + |
| 880 | +```ebnf |
| 881 | +implicit-package-definition ::= package-decl? package-items* |
| 882 | +``` |
| 883 | + |
| 884 | +These two structures cannot be mixed: a file may be written in either in the |
| 885 | +explicit or implicit styles, but not both at once. |
| 886 | + |
| 887 | +All other declarations in a `wit` document are tied to a package, and defined |
| 888 | +as follows. A package definition consists of one or more such items: |
| 889 | + |
| 890 | +```ebnf |
| 891 | +package-items ::= toplevel-use-item | interface-item | world-item |
852 | 892 | ```
|
853 | 893 |
|
854 | 894 | ## Package declaration
|
|
0 commit comments