Skip to content

Commit 736660c

Browse files
azaslavskylukewagner
authored andcommitted
Describe "explicit"-style WIT package grammar
This enables the inclusion of multiple package definitions in a sngle `.wit` file, as discussed in #313.
1 parent 8ba643f commit 736660c

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

design/mvp/WIT.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,22 @@ or
6161
package wasi:[email protected];
6262
```
6363

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+
```
6780

6881
Package names are used to generate the [names of imports and exports]
6982
in the Component Model's representation of [`interface`s][interfaces] and
@@ -877,7 +890,34 @@ readability but this isn't required.
877890
Concretely, the structure of a `wit` file is:
878891

879892
```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
881921
```
882922

883923
### Feature Gates

0 commit comments

Comments
 (0)