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