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("as", "Alias a consumed context (`consumes X as Y`)."),
59 k(
60 "binding",
61 "Name an adapter's TypeScript binding module (`binding \"<module>\"`).",
62 ),
63 k(
64 "by",
65 "Name the actor a handler consumes, after the return type — or a service-level default on the header (`… -> T by <name>: <Actor>`).",
66 ),
67 k(
68 "capability",
69 "Declare a capability (a dependency interface) in a context.",
70 ),
71 k(
72 "case",
73 "Declare a test case inside a `suite` (`case \"…\" { … }`).",
74 ),
75 k(
76 "commons",
77 "Declare a pure, stateless module of types and functions.",
78 ),
79 k(
80 "consumes",
81 "Declare a dependency on another context's services.",
82 ),
83 k(
84 "context",
85 "Declare a deployable context (services, agents, capabilities).",
86 ),
87 k(
88 "cron",
89 "The cron protocol on a service header (`from cron`).",
90 ),
91 k(
92 "do",
93 "Perform a unit effect as a statement (`do e` — the binder-free `let _ <- e`).",
94 ),
95 k("else", "The alternative branch of an `if` expression."),
96 k(
97 "ensures",
98 "Declare a function postcondition — a pure `Bool` clause over the parameters and `result` (`ensures <name>: <pred>`).",
99 ),
100 k("enum", "Declare a payloadless sum type (`enum { A, B }`)."),
101 k(
102 "expect",
103 "Assert a predicate inside a test case (`expect <bool-predicate>`).",
104 ),
105 k("exports", "Declare which types a context exposes, and how."),
106 k("false", "The boolean literal `false`."),
107 k("fn", "Declare a function."),
108 k(
109 "from",
110 "Name the protocol a service conforms to (`service X from http`).",
111 ),
112 k("given", "Declare the capabilities a handler requires."),
113 k(
114 "http",
115 "The HTTP protocol on a service header (`from http`).",
116 ),
117 k("if", "A conditional expression."),
118 k(
119 "implies",
120 "Logical implication (`P implies Q` ≡ `!P || Q`), used in invariant predicates.",
121 ),
122 k(
123 "invariant",
124 "Declare an agent invariant — a predicate that must hold of every committed state.",
125 ),
126 k(
127 "is",
128 "Test a value against a variant pattern, yielding a `Bool`.",
129 ),
130 k(
131 "let",
132 "Bind a local value (`let x = …`, or `let x <- …` for an effect).",
133 ),
134 k(
135 "match",
136 "Pattern-match over a sum type, `Result`, or `Option`.",
137 ),
138 k(
139 "on",
140 "Begin a handler declaration (`on call`, `on GET(…)`, `on message`, `on open`/`on close`).",
141 ),
142 k(
143 "opaque",
144 "Declare an opaque type, or export a type opaquely.",
145 ),
146 k(
147 "property",
148 "Declare a generative test inside a `suite` (`property \"…\" { for all … }`).",
149 ),
150 k(
151 "protocol",
152 "Reserved keyword (protocols are a closed, compiler-known set).",
153 ),
154 k("provides", "Provide an implementation of a capability."),
155 k(
156 "queue",
157 "The queue protocol on a service header (`from queue(\"name\")`).",
158 ),
159 k(
160 "record",
161 "Reserved keyword (records are written `type X = { … }`).",
162 ),
163 k(
164 "requires",
165 "Declare a function precondition — a pure `Bool` clause over the parameters (`requires <name>: <pred>`).",
166 ),
167 k("self", "The current agent instance, inside a handler."),
168 k(
169 "service",
170 "Declare a service (a group of handlers) in a context.",
171 ),
172 k(
173 "stub",
174 "Stub a consumed capability operation at a test seam (`stub Cap.op(…) returns <v>` / `fails`).",
175 ),
176 k(
177 "suite",
178 "Declare a test suite targeting a unit (`suite <target> { case … }`).",
179 ),
180 k(
181 "transition",
182 "Declare an agent step invariant over the `old`/`new` state pair (`transition <name>: …`).",
183 ),
184 k(
185 "transparent",
186 "Export a type with its structure visible (`exports transparent { … }`).",
187 ),
188 k("true", "The boolean literal `true`."),
189 k(
190 "type",
191 "Declare a type: alias, record, sum, opaque, or refined.",
192 ),
193 k("uses", "Bring a commons into scope."),
194 k("where", "Attach refinement predicates to a base type."),
195];
196
197pub const CONTEXTUAL_KEYWORDS: &[KeywordInfo] = &[
205 k(
206 "key",
207 "The agent's identity field — one per agent; keys the store.",
208 ),
209 k("store", "A persisted agent-state field."),
210];
211
212const fn k(word: &'static str, meaning: &'static str) -> KeywordInfo {
213 KeywordInfo { word, meaning }
214}
215
216pub fn render_markdown() -> String {
218 let mut out = String::new();
219 out.push_str("# Keywords\n\n");
220 out.push_str(
221 "<!-- GENERATED FILE — do not edit by hand.\n \
222 Source: bynkc/src/keywords.rs (`render_markdown`).\n \
223 Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test keywords_reference -->\n\n",
224 );
225 out.push_str(
226 "Every reserved keyword, with a one-line description. Reserved words cannot \
227 be used as identifiers.\n\n",
228 );
229 out.push_str(&format!(
230 "There are **{}** reserved keywords.\n\n",
231 KEYWORDS.len()
232 ));
233 out.push_str("| Keyword | Meaning |\n|---|---|\n");
234 for info in KEYWORDS {
235 out.push_str(&format!("| `{}` | {} |\n", info.word, info.meaning));
236 }
237 out
238}