Skip to content

Commit 3986855

Browse files
committed
Describe "explicit"-style WIT package grammar
This enables the inclusion of multiple package definitions in a sngle `.wit` file, as discussed in WebAssembly#313.
1 parent 4bafd01 commit 3986855

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
@@ -55,9 +55,22 @@ or
5555
package wasi:[email protected];
5656
```
5757

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

6275
Package names are used to generate the [names of imports and exports]
6376
in the Component Model's representation of [`interface`s][interfaces] and
@@ -848,7 +861,34 @@ readability but this isn't required.
848861
Concretely, the structure of a `wit` file is:
849862

850863
```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
852892
```
853893

854894
## Package declaration

0 commit comments

Comments
 (0)