|
61 | 61 |
|
62 | 62 | ```
|
63 | 63 |
|
64 |
| -WIT packages can be defined in a collection of files and at least one of them |
65 |
| -must specify a package name. Multiple files can specify a `package` and |
66 |
| -they must all agree on what the package name is. |
| 64 | +WIT packages can be defined in a collection of files. At least one of these |
| 65 | +files must specify a package name. Multiple files can specify the `package`, |
| 66 | +though they must all agree on what the package name is. |
| 67 | + |
| 68 | +Alternatively, many packages can be declared consecutively in one or more |
| 69 | +files, if the "explicit" package notation is used: |
| 70 | + |
| 71 | +```wit |
| 72 | +package local:a { |
| 73 | + interface foo {} |
| 74 | +} |
| 75 | +
|
| 76 | +package local:b { |
| 77 | + interface bar {} |
| 78 | +} |
| 79 | +``` |
67 | 80 |
|
68 | 81 | Package names are used to generate the [names of imports and exports]
|
69 | 82 | in the Component Model's representation of [`interface`s][interfaces] and
|
@@ -877,7 +890,34 @@ readability but this isn't required.
|
877 | 890 | Concretely, the structure of a `wit` file is:
|
878 | 891 |
|
879 | 892 | ```ebnf
|
880 |
| -wit-file ::= package-decl? (toplevel-use-item | interface-item | world-item)* |
| 893 | +wit-file ::= explicit-package-list | implicit-package-definition |
| 894 | +``` |
| 895 | + |
| 896 | +Files may be organized in two arrangements. The first of these is as a series |
| 897 | +of multiple consecutive "explicit" `package ... {...}` declarations, with the |
| 898 | +package's contents contained within the brackets. |
| 899 | + |
| 900 | +```ebnf |
| 901 | +explicit-package-list ::= explicit-package-definition* |
| 902 | +
|
| 903 | +explicit-package-definition ::= package-decl '{' package-items* '}' |
| 904 | +``` |
| 905 | + |
| 906 | +Alternatively, a file may "implicitly" consist of an optional `package ...;` |
| 907 | +declaration, followed by a list of package items. |
| 908 | + |
| 909 | +```ebnf |
| 910 | +implicit-package-definition ::= package-decl? package-items* |
| 911 | +``` |
| 912 | + |
| 913 | +These two structures cannot be mixed: a file may be written in either in the |
| 914 | +explicit or implicit styles, but not both at once. |
| 915 | + |
| 916 | +All other declarations in a `wit` document are tied to a package, and defined |
| 917 | +as follows. A package definition consists of one or more such items: |
| 918 | + |
| 919 | +```ebnf |
| 920 | +package-items ::= toplevel-use-item | interface-item | world-item |
881 | 921 | ```
|
882 | 922 |
|
883 | 923 | ### Feature Gates
|
|
0 commit comments