Skip to content
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
71 changes: 45 additions & 26 deletions design/mvp/WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ token ::= whitespace
| operator
| keyword
| identifier
| strlit
```

Whitespace and comments are ignored when parsing structures defined elsewhere
Expand Down Expand Up @@ -119,6 +120,50 @@ A `wit` document is a sequence of items specified at the top level. These items
come one after another and it's recommended to separate them with newlines for
readability but this isn't required.

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

## Item: `interface`

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

```wit
interface example {
thunk: func() -> ()
fibonacci: func(n: u32) -> u32
}
```

Specifically interfaces have the structure:

```wit
interface-item ::= 'interface' id strlit? '{' interface-items* '}'

interface-items ::= resource-item
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could interfaces be nested?

Copy link
Collaborator Author

@fibonacci1729 fibonacci1729 Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mossaka eventually, but currently there isn't an immediate use-case and it's not clear how nested interfaces map onto the component model just yet.

| variant-items
| record-item
| union-items
| flags-items
| enum-items
| type-item
| use-item
| func-item

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

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

result-list ::= ty
| '(' named-type-list ')

named-type-list ::= nil
| named-type ( ',' named-type )*

named-type ::= id ':' ty
```

## Item: `use`

A `use` statement enables importing type or resource definitions from other
Expand Down Expand Up @@ -331,32 +376,6 @@ union-cases ::= ty,
| ty ',' union-cases?
```

## Item: `func`

Functions can also be defined in a `wit` document. Functions have a name,
parameters, and results.

```wit
thunk: func() -> ()
fibonacci: func(n: u32) -> u32
```

Specifically functions have the structure:

```wit
func-item ::= id ':' 'func' param-list '->' result-list

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

result-list ::= ty
| '(' named-type-list ')

named-type-list ::= nil
| named-type ( ',' named-type )*

named-type ::= id ':' ty
```

## Item: `resource`

Resources represent a value that has a hidden representation not known to the
Expand Down