|
| 1 | +--- |
| 2 | +applyTo: "**/wit.tmLanguage.json" |
| 3 | +--- |
| 4 | + |
| 5 | +# Instructions for WIT and Official Grammar |
| 6 | + |
| 7 | +## 1. What is WIT? |
| 8 | +- WIT (WebAssembly Interface Types) is a language and specification for describing interfaces between WebAssembly modules and their host environments. |
| 9 | +- It defines types, functions, resources, and modules in a language-agnostic way. |
| 10 | + |
| 11 | +## 2. Official Grammar |
| 12 | +- The official WIT grammar is defined in the `wit.tmLanguage.json` file and is used for syntax highlighting and parsing. |
| 13 | +- Refer to the [WIT specification](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md) for the authoritative grammar and language rules. |
| 14 | +- The grammar covers: |
| 15 | + - Identifiers, keywords, and comments |
| 16 | + - Type definitions (records, variants, enums, flags, etc.) |
| 17 | + - Function and resource declarations |
| 18 | + - Module and world definitions |
| 19 | + - Versioning, namespace, and aliasing |
| 20 | + - Markdown in doc comments |
| 21 | + |
| 22 | +## 3. Best Practices |
| 23 | +- Follow the official WIT grammar for all `.wit` files. |
| 24 | +- Use consistent formatting and indentation for readability. |
| 25 | +- Validate `.wit` files using available tools or language support in your editor. |
| 26 | +- Place WIT grammar and related files in the appropriate `syntaxes/` directory. |
| 27 | +- When updating the grammar, also update or add tests in `tests/grammar/` to cover new features, edge cases, or bug fixes. |
| 28 | +- If the WIT specification changes, update both the grammar and the tests to stay in sync. |
| 29 | +- For complex or non-obvious grammar rules, add or expand comments in `wit.tmLanguage.json` to help future maintainers. |
| 30 | +- Test new or changed grammar rules with both valid and invalid WIT syntax to ensure robust highlighting and error detection. |
| 31 | + |
| 32 | +## 4. Resources |
| 33 | +- [WIT Specification](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md) |
| 34 | +- [wit.tmLanguage.json](syntaxes/wit.tmLanguage.json) (project grammar file) |
| 35 | +- [WebAssembly Component Model](https://github.com/WebAssembly/component-model) |
| 36 | +- [Grammar Tests](tests/grammar/) (test suite for grammar validation) |
| 37 | + |
| 38 | +--- |
| 39 | +For questions about WIT or its grammar, contact project maintainers or refer to the official specification. |
0 commit comments