@@ -32,6 +32,7 @@ token ::= whitespace
32
32
| operator
33
33
| keyword
34
34
| identifier
35
+ | strlit
35
36
```
36
37
37
38
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
119
120
come one after another and it's recommended to separate them with newlines for
120
121
readability but this isn't required.
121
122
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
+
122
167
## Item: ` use `
123
168
124
169
A ` use ` statement enables importing type or resource definitions from other
@@ -331,32 +376,6 @@ union-cases ::= ty,
331
376
| ty ',' union-cases?
332
377
```
333
378
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
-
360
379
## Item: ` resource `
361
380
362
381
Resources represent a value that has a hidden representation not known to the
0 commit comments