Skip to content

Commit ded219e

Browse files
Merge pull request #116 from fibonacci1729/interface
WIT Syntax: `interface`
2 parents 9784159 + 30720ab commit ded219e

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

design/mvp/WIT.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ token ::= whitespace
3232
| operator
3333
| keyword
3434
| identifier
35+
| strlit
3536
```
3637

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

123+
Concretely, the structure of a `wit` document is:
124+
```
125+
wit-document ::= interface-item*
126+
```
127+
128+
## Item: `interface`
129+
130+
Interfaces can be defined in a `wit` document. Interfaces have a name and a sequence of items and functions.
131+
132+
```wit
133+
interface example {
134+
thunk: func() -> ()
135+
fibonacci: func(n: u32) -> u32
136+
}
137+
```
138+
139+
Specifically interfaces have the structure:
140+
141+
```wit
142+
interface-item ::= 'interface' id strlit? '{' interface-items* '}'
143+
144+
interface-items ::= resource-item
145+
| variant-items
146+
| record-item
147+
| union-items
148+
| flags-items
149+
| enum-items
150+
| type-item
151+
| use-item
152+
| func-item
153+
154+
func-item ::= id ':' 'func' param-list '->' result-list
155+
156+
param-list ::= '(' named-type-list ')'
157+
158+
result-list ::= ty
159+
| '(' named-type-list ')
160+
161+
named-type-list ::= nil
162+
| named-type ( ',' named-type )*
163+
164+
named-type ::= id ':' ty
165+
```
166+
122167
## Item: `use`
123168

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

334-
## Item: `func`
335-
336-
Functions can also be defined in a `wit` document. Functions have a name,
337-
parameters, and results.
338-
339-
```wit
340-
thunk: func() -> ()
341-
fibonacci: func(n: u32) -> u32
342-
```
343-
344-
Specifically functions have the structure:
345-
346-
```wit
347-
func-item ::= id ':' 'func' param-list '->' result-list
348-
349-
param-list ::= '(' named-type-list ')'
350-
351-
result-list ::= ty
352-
| '(' named-type-list ')
353-
354-
named-type-list ::= nil
355-
| named-type ( ',' named-type )*
356-
357-
named-type ::= id ':' ty
358-
```
359-
360379
## Item: `resource`
361380

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

0 commit comments

Comments
 (0)