Skip to content

Commit f92a3df

Browse files
committed
WIP
1 parent c687905 commit f92a3df

File tree

9 files changed

+1382
-36
lines changed

9 files changed

+1382
-36
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "ref/wit-bindgen"]
1111
path = ref/wit-bindgen
1212
url = https://github.com/bytecodealliance/wit-bindgen.git
13+
[submodule "ref/vscode-wit"]
14+
path = ref/vscode-wit
15+
url = https://github.com/bytecodealliance/vscode-wit.git

.vitepress/config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'vitepress'
2+
import { witLang } from '../grammar/dist/index.js'
23

34
// https://vitepress.dev/reference/site-config
45
export default defineConfig({
@@ -7,6 +8,12 @@ export default defineConfig({
78
base: '/component-model-cpp',
89
srcExclude: ["./build/**", "./grammar/**", "./node_modules/**", "./ref/**", "./vcpkg/**", "./vcpkg_overlays/**"],
910

11+
markdown: {
12+
languages: [
13+
witLang()
14+
]
15+
},
16+
1017
themeConfig: {
1118
editLink: {
1219
pattern: 'https://github.com/GordonSmith/component-model-cpp/edit/main/docs/:path',
@@ -27,7 +34,8 @@ export default defineConfig({
2734
items: [
2835
{ text: 'Generated Files Structure', link: '/docs/generated-files-structure' },
2936
{ text: 'Generated WAMR Helpers', link: '/docs/generated-wamr-helpers' },
30-
{ text: 'Packaging', link: '/docs/PACKAGING' }
37+
{ text: 'Packaging', link: '/docs/PACKAGING' },
38+
{ text: 'WIT Syntax Examples', link: '/docs/wit-syntax-example' }
3139
]
3240
},
3341
{

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# Component Model C++ (Developer Reference)
1212

13+
> **Under Construction:** The documentation is being reorganized and some sections may change without notice.
14+
1315
This repository provides a header-only C++20 implementation of the WebAssembly Component Model canonical ABI. The code mirrors the official [Python Reference](https://github.com/GordonSmith/component-model-cpp/blob/main/ref/component-model/design/mvp/canonical-abi/definitions.py) and the [Specification](https://github.com/GordonSmith/component-model-cpp/blob/main/ref/component-model/design/mvp/CanonicalABI.md). All behavior (naming, state transitions, error conditions) should remain aligned with the reference.
1416

1517
## Official Documentation, Issues, and Discussions
@@ -37,7 +39,7 @@ include/ -> Header-only implementation (public surface via cmcpp.
3739
cmcpp.hpp -> Aggregate public include (pulls in full cmcpp namespace)
3840
wamr.hpp -> WAMR host integration helpers
3941
pfr.hpp -> Boost.PFR lightweight reflection shim used internally
40-
grammar/ -> ANTLR WIT grammar and generation targets
42+
grammar/ -> ANTLR WIT grammar and Shiki syntax highlighting for docs
4143
tools/wit-codegen/ -> Binding generation utilities (WIT -> C++ host stubs)
4244
test/ -> doctest suites + ICU-backed string conversion helpers
4345
samples/ -> Optional WAMR host sample (ENABLE via BUILD_SAMPLES)

docs/wit-syntax-example.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# WIT Syntax Highlighting Example
2+
3+
This page demonstrates WIT (WebAssembly Interface Types) syntax highlighting in VitePress.
4+
5+
## Basic Package Definition
6+
7+
```wit
8+
package example:[email protected];
9+
10+
interface types {
11+
/// A person with name and age
12+
record person {
13+
name: string,
14+
age: u32,
15+
}
16+
17+
/// Get a greeting for a person
18+
greet: func(p: person) -> string;
19+
}
20+
21+
world hello {
22+
export types;
23+
}
24+
```
25+
26+
## Resource Example
27+
28+
```wit
29+
package example:[email protected];
30+
31+
interface database {
32+
/// A database connection resource
33+
resource connection {
34+
/// Create a new connection
35+
constructor(url: string);
36+
37+
/// Execute a query
38+
query: func(sql: string) -> result<list<string>, string>;
39+
40+
/// Close the connection
41+
close: func();
42+
}
43+
}
44+
```
45+
46+
## Async Operations
47+
48+
```wit
49+
package example:[email protected];
50+
51+
interface io {
52+
use wasi:io/[email protected].{input-stream, output-stream};
53+
54+
/// Read data asynchronously
55+
read-async: func(stream: borrow<input-stream>) -> future<result<list<u8>, error-code>>;
56+
57+
/// Write data asynchronously
58+
write-async: func(stream: borrow<output-stream>, data: list<u8>) -> future<result<_, error-code>>;
59+
}
60+
```
61+
62+
## Complex Types
63+
64+
```wit
65+
package example:[email protected];
66+
67+
interface types {
68+
/// Boolean values
69+
type flag = bool;
70+
71+
/// Variant type
72+
variant color {
73+
rgb(u8, u8, u8),
74+
rgba(u8, u8, u8, u8),
75+
named(string),
76+
}
77+
78+
/// Flags for permissions
79+
flags permissions {
80+
read,
81+
write,
82+
execute,
83+
}
84+
85+
/// Enum for log levels
86+
enum log-level {
87+
debug,
88+
info,
89+
warning,
90+
error,
91+
}
92+
93+
/// Option type
94+
type maybe-string = option<string>;
95+
96+
/// Result type
97+
type io-result = result<u32, string>;
98+
}
99+
```
100+
101+
## World with Imports and Exports
102+
103+
```wit
104+
package example:[email protected];
105+
106+
world application {
107+
import wasi:filesystem/[email protected];
108+
import wasi:http/[email protected];
109+
import wasi:clocks/[email protected];
110+
111+
export run: func() -> result<_, string>;
112+
}
113+
```
114+
115+
## Feature Gates
116+
117+
```wit
118+
package example:[email protected];
119+
120+
interface experimental {
121+
@since(version = 0.2.0)
122+
@unstable(feature = new-api)
123+
new-function: func() -> string;
124+
125+
@deprecated(since = 0.3.0)
126+
old-function: func() -> string;
127+
}
128+
```
129+
130+
The WIT syntax highlighting is provided by the grammar built from the [vscode-wit](https://github.com/bytecodealliance/vscode-wit) TextMate grammar, making it consistent with VS Code's WIT extension.

grammar/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { LanguageInput } from "shiki";
2+
3+
import wit_lang from "../ref/vscode-wit/syntaxes/wit.tmLanguage.json" with { type: "json" };
4+
5+
export function witLang(): LanguageInput {
6+
const retVal = {
7+
...wit_lang,
8+
name: "wit"
9+
} as unknown as LanguageInput;
10+
return retVal;
11+
}
12+

index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ features:
2626
details: 🚧 Under construction 🚧
2727
- title: WasmEdge Support
2828
details: 🚧 Under construction 🚧
29+
2930
---
31+
> **Under Construction:** Content on this site is evolving quickly; expect placeholders and frequent updates.
3032

0 commit comments

Comments
 (0)