Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIT Syntax: world #83

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions design/mvp/WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ keyword ::= 'use'
| 'tuple'
| 'future'
| 'stream'
| 'world'
| 'import'
| 'export'
```

## Top-level items
Expand All @@ -122,20 +125,32 @@ readability but this isn't required.

Concretely, the structure of a `wit` document is:
```
wit-document ::= interface-item*
wit-document ::= (interface-item | world-item)*
```

## Item: `interface`
## Item: `world`

Interfaces can be defined in a `wit` document. Interfaces have a name and a sequence of items and functions.
Worlds define a [componenttype](https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#type-definitions) as a collection of imports and exports.

Concretely, the structure of a world is:

```wit
interface example {
thunk: func() -> ()
fibonacci: func(n: u32) -> u32
}
world-item ::= 'world' id '{' world-items* '}'

world-items ::= export-item | import-item

export-item ::= 'export' id ':' extern-type
import-item ::= 'import' id ':' extern-type

extern-type ::= ty | func-type | interface-type

interface-type ::= 'interface' '{' interface-items* '}'
```

## Item: `interface`

Interfaces can be defined in a `wit` document. Interfaces have a name and a sequence of items and functions.

Specifically interfaces have the structure:

```wit
Expand All @@ -151,7 +166,9 @@ interface-items ::= resource-item
| use-item
| func-item

func-item ::= id ':' 'func' param-list '->' result-list
func-item ::= id ':' func-type

func-type ::= 'func' param-list '->' result-list

param-list ::= '(' named-type-list ')'

Expand Down