Skip to main content

bynk_syntax/
keywords.rs

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