Skip to content

format: EBNF Syntax Highlighting, comments as whitespace, relax some reserved keywords #156

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

Merged
merged 3 commits into from
Feb 24, 2023
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
56 changes: 21 additions & 35 deletions design/mvp/WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,8 @@ or codepoints that Unicode officially deprecates or strongly discourages.

The current structure of tokens are:

```wit
```ebnf
token ::= whitespace
| comment
| operator
| keyword
| identifier
Expand All @@ -579,11 +578,11 @@ here.

### Whitespace

A `whitespace` token in `wit` is a space, a newline, a carriage return, or a
tab character:
A `whitespace` token in `wit` is a space, a newline, a carriage return, a
tab character, or a comment:

```wit
whitespace ::= ' ' | '\n' | '\r' | '\t'
```ebnf
whitespace ::= ' ' | '\n' | '\r' | '\t' | comment
```

### Comments
Expand All @@ -593,7 +592,7 @@ ends at the next newline (`\n`) character or it's a block comment which starts
with `/*` and ends with `*/`. Note that block comments are allowed to be nested
and their delimiters must be balanced

```wit
```ebnf
comment ::= '//' character-that-isnt-a-newline*
| '/*' any-unicode-character* '*/'
```
Expand All @@ -604,7 +603,7 @@ newline (`\n`) character or it's a block comment which starts with `/**` and end
with `*/`. Note that block comments are allowed to be nested and their delimiters
must be balanced

```wit
```ebnf
doc-comment ::= '///' character-that-isnt-a-newline*
| '/**' any-unicode-character* '*/'
```
Expand All @@ -615,7 +614,7 @@ There are some common operators in the lexical structure of `wit` used for
various constructs. Note that delimiters such as `{` and `(` must all be
balanced.

```wit
```ebnf
operator ::= '=' | ',' | ':' | ';' | '(' | ')' | '{' | '}' | '<' | '>' | '*' | '->'
```

Expand All @@ -625,31 +624,18 @@ Certain identifiers are reserved for use in `wit` documents and cannot be used
bare as an identifier. These are used to help parse the format, and the list of
keywords is still in flux at this time but the current set is:

```wit
```ebnf
keyword ::= 'use'
| 'type'
| 'resource'
| 'func'
| 'u8' | 'u16' | 'u32' | 'u64'
| 's8' | 's16' | 's32' | 's64'
| 'float32' | 'float64'
| 'char'
| 'record'
| 'enum'
| 'flags'
| 'variant'
| 'union'
| 'bool'
| 'string'
| 'option'
| 'list'
| 'result'
| 'as'
| 'static'
| 'interface'
| 'tuple'
| 'future'
| 'stream'
| 'world'
| 'import'
| 'export'
Expand All @@ -663,7 +649,7 @@ 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:
```
```ebnf
wit-document ::= (interface-item | world-item)*
```

Expand All @@ -673,7 +659,7 @@ Worlds define a [componenttype](https://github.com/WebAssembly/component-model/b

Concretely, the structure of a world is:

```wit
```ebnf
world-item ::= 'default'? 'world' id '{' world-items* '}'

world-items ::= export-item | import-item | use-item | typedef-item
Expand All @@ -697,7 +683,7 @@ sequence of items and functions.

Specifically interfaces have the structure:

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

interface-items ::= typedef-item
Expand Down Expand Up @@ -741,7 +727,7 @@ use my-dependency.document.other-type

Specifically the structure of this is:

```wit
```ebnf
use-item ::= 'use' use-path '.' '{' use-names-list '}'

use-names-list ::= use-names-item
Expand Down Expand Up @@ -774,7 +760,7 @@ type my-complicated-tuple = tuple<u32, s32, string>

Specifically the structure of this is:

```wit
```ebnf
type-item ::= 'type' id '=' ty
```

Expand All @@ -799,7 +785,7 @@ record person {

Specifically the structure of this is:

```wit
```ebnf
record-item ::= 'record' id '{' record-fields '}'

record-fields ::= record-field
Expand All @@ -824,7 +810,7 @@ flags properties {

Specifically the structure of this is:

```wit
```ebnf
flags-items ::= 'flags' id '{' flags-fields '}'

flags-fields ::= id
Expand Down Expand Up @@ -853,7 +839,7 @@ variant filter {

Specifically the structure of this is:

```wit
```ebnf
variant-items ::= 'variant' id '{' variant-cases '}'

variant-cases ::= variant-case
Expand Down Expand Up @@ -882,7 +868,7 @@ enum color {

Specifically the structure of this is:

```wit
```ebnf
enum-items ::= 'enum' id '{' enum-cases '}'

enum-cases ::= id
Expand All @@ -905,7 +891,7 @@ union configuration {

Specifically the structure of this is:

```wit
```ebnf
union-items ::= 'union' id '{' union-cases '}'

union-cases ::= ty
Expand All @@ -927,7 +913,7 @@ type headers = list<string>

Specifically the following types are available:

```wit
```ebnf
ty ::= 'u8' | 'u16' | 'u32' | 'u64'
| 's8' | 's16' | 's32' | 's64'
| 'float32' | 'float64'
Expand Down Expand Up @@ -990,7 +976,7 @@ resource is destroyed. In contrast, a borrowed handle represents a temporary
loan of a handle from the caller to the callee for the duration of the call.

The syntax for handles is:
```
```ebnf
handle ::= id
| 'borrow' '<' id '>'
```
Expand Down