1pub struct KeywordInfo {
12 pub word: &'static str,
13 pub meaning: &'static str,
14}
15
16pub const KEYWORDS: &[KeywordInfo] = &[
18 k("Bool", "The boolean base type."),
19 k(
20 "Bytes",
21 "The binary base type — an immutable octet sequence, erased to `Uint8Array` (`Bytes.fromUtf8(s)`).",
22 ),
23 k(
24 "Duration",
25 "The time-span base type, in milliseconds (`5.minutes`).",
26 ),
27 k("Effect", "The effectful-computation type, `Effect[T]`."),
28 k("Err", "The error variant of `Result`."),
29 k("Float", "The floating-point base type."),
30 k(
31 "Instant",
32 "The absolute-time base type, in epoch milliseconds (`Clock.now()`).",
33 ),
34 k("Int", "The integer base type."),
35 k(
36 "JsonError",
37 "The JSON-decode error type, `Result[T, JsonError]` from `Json.decode`.",
38 ),
39 k("None", "The empty variant of `Option`."),
40 k("Ok", "The success variant of `Result`."),
41 k("Option", "The optional-value type, `Option[T]`."),
42 k("Result", "The success-or-error type, `Result[T, E]`."),
43 k("Some", "The present variant of `Option`."),
44 k("String", "The string base type."),
45 k(
46 "ValidationError",
47 "The error type returned by a refined type's `.of`.",
48 ),
49 k(
50 "actor",
51 "Declare an actor — a boundary contract a handler consumes via `by`.",
52 ),
53 k(
54 "adapter",
55 "Declare an adapter — the host boundary (capability contract + binding).",
56 ),
57 k("agent", "Declare a stateful, keyed agent inside a context."),
58 k("and", "Combine refinement predicates (`where A and B`)."),
59 k("as", "Alias a consumed context (`consumes X as Y`)."),
60 k("assert", "Assert a condition inside a test case."),
61 k(
62 "binding",
63 "Name an adapter's TypeScript binding module (`binding \"<module>\"`).",
64 ),
65 k(
66 "by",
67 "Name the actor a handler consumes (`on … by <name>: <Actor>`).",
68 ),
69 k(
70 "capability",
71 "Declare a capability (a dependency interface) in a context.",
72 ),
73 k(
74 "commons",
75 "Declare a pure, stateless module of types and functions.",
76 ),
77 k(
78 "consumes",
79 "Declare a dependency on another context's services.",
80 ),
81 k(
82 "context",
83 "Declare a deployable context (services, agents, capabilities).",
84 ),
85 k(
86 "cron",
87 "The cron protocol on a service header (`from cron`).",
88 ),
89 k("else", "The alternative branch of an `if` expression."),
90 k("enum", "Declare a payloadless sum type (`enum { A, B }`)."),
91 k("expect", "Reserved keyword."),
92 k("exports", "Declare which types a context exposes, and how."),
93 k("false", "The boolean literal `false`."),
94 k("fn", "Declare a function."),
95 k(
96 "from",
97 "Name the protocol a service conforms to (`service X from http`).",
98 ),
99 k("given", "Declare the capabilities a handler requires."),
100 k(
101 "http",
102 "The HTTP protocol on a service header (`from http`).",
103 ),
104 k("if", "A conditional expression."),
105 k(
106 "implies",
107 "Logical implication (`P implies Q` ≡ `!P || Q`), used in invariant predicates.",
108 ),
109 k(
110 "invariant",
111 "Declare an agent invariant — a predicate that must hold of every committed state.",
112 ),
113 k(
114 "is",
115 "Test a value against a variant pattern, yielding a `Bool`.",
116 ),
117 k(
118 "let",
119 "Bind a local value (`let x = …`, or `let x <- …` for an effect).",
120 ),
121 k(
122 "match",
123 "Pattern-match over a sum type, `Result`, or `Option`.",
124 ),
125 k(
126 "mocks",
127 "Provide a mock capability implementation in a test.",
128 ),
129 k(
130 "on",
131 "Begin a handler declaration (`on call`, `on GET(…)`, `on message`, `on open`/`on close`).",
132 ),
133 k(
134 "opaque",
135 "Declare an opaque type, or export a type opaquely.",
136 ),
137 k(
138 "protocol",
139 "Reserved keyword (protocols are a closed, compiler-known set).",
140 ),
141 k("provides", "Provide an implementation of a capability."),
142 k(
143 "queue",
144 "The queue protocol on a service header (`from queue(\"name\")`).",
145 ),
146 k(
147 "record",
148 "Reserved keyword (records are written `type X = { … }`).",
149 ),
150 k("self", "The current agent instance, inside a handler."),
151 k(
152 "service",
153 "Declare a service (a group of handlers) in a context.",
154 ),
155 k("test", "Declare a test block or a test case."),
156 k(
157 "transparent",
158 "Export a type with its structure visible (`exports transparent { … }`).",
159 ),
160 k("true", "The boolean literal `true`."),
161 k(
162 "type",
163 "Declare a type: alias, record, sum, opaque, or refined.",
164 ),
165 k("uses", "Bring a commons into scope."),
166 k("where", "Attach refinement predicates to a base type."),
167 k(
168 "wires",
169 "List the contexts a `test integration` stands up as Workers.",
170 ),
171];
172
173const fn k(word: &'static str, meaning: &'static str) -> KeywordInfo {
174 KeywordInfo { word, meaning }
175}
176
177pub fn render_markdown() -> String {
179 let mut out = String::new();
180 out.push_str("# Keywords\n\n");
181 out.push_str(
182 "<!-- GENERATED FILE — do not edit by hand.\n \
183 Source: bynkc/src/keywords.rs (`render_markdown`).\n \
184 Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test keywords_reference -->\n\n",
185 );
186 out.push_str(
187 "Every reserved keyword, with a one-line description. Reserved words cannot \
188 be used as identifiers.\n\n",
189 );
190 out.push_str(&format!(
191 "There are **{}** reserved keywords.\n\n",
192 KEYWORDS.len()
193 ));
194 out.push_str("| Keyword | Meaning |\n|---|---|\n");
195 for info in KEYWORDS {
196 out.push_str(&format!("| `{}` | {} |\n", info.word, info.meaning));
197 }
198 out
199}