@northtalk/ts 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/{binary-value-xvJoGg0C.d.ts → binary-value-M8v567iA.d.ts} +1 -1
  2. package/{checker-CUhn2XaM.js → checker-Coml0Tf9.js} +581 -71
  3. package/{core-BuTAYRm-.d.ts → core-D4qYURer.d.ts} +1 -1
  4. package/{debug-DRhMZAxw.d.ts → debug-C_Ob5rkl.d.ts} +137 -12
  5. package/debug.d.ts +1 -1
  6. package/debug.js +1 -1
  7. package/{driver-CHDcuqUy.d.ts → driver-CLi_OmyQ.d.ts} +1 -1
  8. package/driver.d.ts +1 -1
  9. package/driver.js +1 -1
  10. package/encoding-BL2ECJmg.js +338 -0
  11. package/{engine-Cc3yofGM.d.ts → engine-BBNHy4-F.d.ts} +2 -2
  12. package/{engine-CXf5FCwi.js → engine-DhBk0lTt.js} +6 -6
  13. package/{errors-D11zizZg.js → errors-P3ga1I-9.js} +124 -21
  14. package/{group-BflSou2n.js → group-BqccKTWz.js} +406 -75
  15. package/{http-fetch-DFwVIOQg.js → http-fetch-DA-NbFIM.js} +2 -2
  16. package/http.d.ts +1 -1
  17. package/http.js +5 -5
  18. package/index-CBuczWK0.d.ts +9 -0
  19. package/index.d.ts +6 -12
  20. package/index.js +15 -14
  21. package/{inline-grants-XbX9HL_w.js → inline-grants-BT2nnfLA.js} +4 -5
  22. package/{lean-BebPaTMK.js → lean-BJmLobmd.js} +13 -8
  23. package/{lean-CjWVuOrC.d.ts → lean-CFLJ9VrX.d.ts} +155 -6
  24. package/lean.d.ts +5 -6
  25. package/lean.js +15 -14
  26. package/{manifest-CCfpn0kC.js → manifest-37x-HSxH.js} +4 -3
  27. package/message-layer.d.ts +2 -2
  28. package/message-layer.js +2 -2
  29. package/notify.d.ts +1 -1
  30. package/notify.js +1 -1
  31. package/{objects-DmUc0lha.js → objects-DE6kRk0r.js} +1 -1
  32. package/{objects-DC6HjzBY.d.ts → objects-DVlpWsi0.d.ts} +11 -3
  33. package/{operations-DnCcztkZ.js → operations-CGjDlkGU.js} +73 -15
  34. package/package.json +5 -1
  35. package/peer-capability-elnbQy-J.js +149 -0
  36. package/peer.d.ts +173 -0
  37. package/peer.js +542 -0
  38. package/{readers-MmyZ_d0w.d.ts → readers-ChQ0e92c.d.ts} +1 -1
  39. package/{readers-CsvlahLi.js → readers-yMS1eAOp.js} +1 -1
  40. package/{request-pump-binary-oqjWFqZA.js → request-pump-binary-BS1J8DF2.js} +4 -4
  41. package/{router-BZ-aYeXA.js → router-Bm7A2kjt.js} +4 -4
  42. package/{router-D56rSkU8.d.ts → router-D0rf5SkW.d.ts} +2 -2
  43. package/session.d.ts +2 -2
  44. package/session.js +65 -17
  45. package/setup.d.ts +3 -2
  46. package/setup.js +13 -16
  47. package/sqlite.d.ts +2 -2
  48. package/sqlite.js +5 -5
  49. package/{store-DHlo6fP5.js → store-D80OlpyG.js} +2 -2
  50. package/store-capability-DBLlWaNO.js +187 -0
  51. package/store.d.ts +2 -2
  52. package/store.js +2 -2
  53. package/{user-capability-BcRQyyEw.js → user-capability-D6hGa3eF.js} +3 -4
  54. package/wasm.d.ts +16 -7
  55. package/wasm.js +52 -23
  56. package/encoding-RUuES_e4.js +0 -99
  57. package/manifest-DVrx-pT2.d.ts +0 -122
  58. package/store-capability-BrUUAwVS.js +0 -389
@@ -1,6 +1,6 @@
1
1
 
2
- import { M as literalDigits, an as builtins, at as parseUnit, cn as libraryExports, en as normalizeNFC, lt as unitEntry, on as diagnosticCodes, sn as grammar, tt as UnitError, un as units, ut as unitText } from "./errors-D11zizZg.js";
3
- import { Dt as runTask, Et as RESERVED, Tt as Lexer, gt as acceptsArgumentCount } from "./operations-DnCcztkZ.js";
2
+ import { M as literalDigits, cn as builtins, ct as parseUnit, dn as libraryExports, fn as unitKinds, ft as unitEntry, ln as diagnosticCodes, pn as units, pt as unitText, rn as normalizeNFC, rt as UnitError, un as grammar } from "./errors-P3ga1I-9.js";
3
+ import { At as Lexer, Mt as runTask, _t as acceptsArgumentCount, jt as RESERVED } from "./operations-CGjDlkGU.js";
4
4
  //#region src/constructs.ts
5
5
  /** Chapter 3's kind names. */
6
6
  const kindNames = /* @__PURE__ */ new Set([
@@ -33,13 +33,13 @@ const unconvertibleKinds = /* @__PURE__ */ new Set([
33
33
  ]);
34
34
  const unitNames = new Set(units.flatMap((unit) => "plural" in unit && unit.plural ? [unit.name, unit.plural] : [unit.name]));
35
35
  const anchors = new Set(grammar.text_patterns.anchors);
36
- const nodes$1 = (node) => node.children.filter((child) => child.kind === "node");
37
- const leaves$1 = (node) => node.children.filter((child) => child.kind !== "node");
36
+ const nodes$2 = (node) => node.children.filter((child) => child.kind === "node");
37
+ const leaves$2 = (node) => node.children.filter((child) => child.kind !== "node");
38
38
  const firstLeaf$3 = (element) => {
39
39
  while (element.kind === "node") element = element.children[0];
40
40
  return element;
41
41
  };
42
- const text = (node) => leaves$1(node).map((leaf) => leaf.text).join(" ");
42
+ const text = (node) => leaves$2(node).map((leaf) => leaf.text).join(" ");
43
43
  /** Descend through single-child productions to the construct they wrap. */
44
44
  const unwrap$1 = (node) => {
45
45
  while (node.children.length === 1 && node.children[0].kind === "node") node = node.children[0];
@@ -47,22 +47,32 @@ const unwrap$1 = (node) => {
47
47
  };
48
48
  const isOp = (element, op) => element?.kind === "token" && element.type === "op" && element.text === op;
49
49
  /** The kind after `is a`, `as` or `can be`: chapter 3 decides which names each allows. */
50
- const checkKind = (kind, position, report) => {
50
+ const checkKind = (kind, position, report, isShape = () => false) => {
51
51
  const name = text(kind);
52
- if (!(kindNames.has(name) || (position === "is" ? name === "integer" : unitNames.has(name)))) {
52
+ if (!(kindNames.has(name) || (position === "is" ? name === "integer" || isShape(name) : unitNames.has(name)))) {
53
53
  report("unknown kind", firstLeaf$3(kind));
54
54
  return null;
55
55
  }
56
56
  return name;
57
57
  };
58
- const checkComparison = (node, report) => {
59
- const words = leaves$1(node).map((leaf) => leaf.text);
60
- const kind = nodes$1(node).find((child) => child.rule === "Kind");
58
+ const checkComparison = (node, report, isShape) => {
59
+ const words = leaves$2(node).map((leaf) => leaf.text);
60
+ const kind = nodes$2(node).find((child) => child.rule === "Kind");
61
61
  const is = words.includes("is");
62
- if (kind) checkKind(kind, is ? "is" : "can be", report);
63
- const folding = nodes$1(node).find((child) => child.rule === "IgnoringCase");
62
+ if (kind) checkKind(kind, is ? "is" : "can be", report, isShape);
63
+ const folding = nodes$2(node).find((child) => child.rule === "IgnoringCase");
64
64
  if (folding && (kind || is && words.includes("empty"))) report("nothing to fold", firstLeaf$3(folding));
65
65
  };
66
+ const checkClauseShapes = (node, report, isShape) => {
67
+ const { children } = node;
68
+ for (let i = 0; i < children.length; i++) {
69
+ const child = children[i];
70
+ if (child.kind !== "node" || child.rule !== "Kind") continue;
71
+ const not = children[i - 2];
72
+ if (not?.kind === "token" && not.text === "not") report("negated shape", not);
73
+ checkKind(child, "is", report, isShape);
74
+ }
75
+ };
66
76
  const checkConversion = (node, report) => {
67
77
  const { children } = node;
68
78
  for (let index = 1; index < children.length; index++) {
@@ -75,7 +85,7 @@ const checkConversion = (node, report) => {
75
85
  };
76
86
  const checkMap = (node, report) => {
77
87
  const seen = /* @__PURE__ */ new Set();
78
- for (const key of nodes$1(node).filter((child) => child.rule === "MapKey")) {
88
+ for (const key of nodes$2(node).filter((child) => child.rule === "MapKey")) {
79
89
  const leaf = firstLeaf$3(key);
80
90
  const name = leaf.kind === "token" ? normalizeNFC(leaf.text) : leaf.text;
81
91
  if (seen.has(name)) report("duplicate key", leaf);
@@ -90,14 +100,14 @@ const checkDelimited = (node, report) => {
90
100
  const delimited = node.children.find((child) => child.kind !== "node" && child.text === "delimited");
91
101
  if (!delimited) return;
92
102
  const head = node.rule === "EveryHead";
93
- if (head && leaves$1(node)[1]?.text === "item") return;
103
+ if (head && leaves$2(node)[1]?.text === "item") return;
94
104
  let base = unwrap$1(node.children[head ? node.children.indexOf(delimited) - 1 : 0]);
95
105
  while (base) {
96
- const words = leaves$1(base).map((leaf) => leaf.text);
106
+ const words = leaves$2(base).map((leaf) => leaf.text);
97
107
  if (base.rule === "Chunk") {
98
108
  if (words[0] === "item" || words[0] === "items") return;
99
109
  } else if (base.rule === "The") {
100
- const key = nodes$1(base).find((child) => child.rule === "Key");
110
+ const key = nodes$2(base).find((child) => child.rule === "Key");
101
111
  if (key) {
102
112
  if (text(key) === "items") return;
103
113
  break;
@@ -105,7 +115,7 @@ const checkDelimited = (node, report) => {
105
115
  if (!(base.children[1]?.kind === "token" && base.children[1].type === "word" && words[1] !== "target")) break;
106
116
  if (words[2] === "item") return;
107
117
  } else if (base.rule === "Postfix") {
108
- const key = nodes$1(base).at(-1);
118
+ const key = nodes$2(base).at(-1);
109
119
  if (key?.rule === "Key" && text(key) === "items") return;
110
120
  break;
111
121
  } else break;
@@ -129,9 +139,9 @@ const checkRest = (node, report) => {
129
139
  /** Each run of consecutive bit fields must add up to whole bytes. */
130
140
  const checkBits = (node, report) => {
131
141
  const fields = [];
132
- if (node.rule === "BinaryPattern") for (const field of nodes$1(node)) fields.push({
142
+ if (node.rule === "BinaryPattern") for (const field of nodes$2(node)) fields.push({
133
143
  first: firstLeaf$3(field),
134
- type: nodes$1(field).find((child) => child.rule === "FieldType")
144
+ type: nodes$2(field).find((child) => child.rule === "FieldType")
135
145
  });
136
146
  else for (const child of node.children) {
137
147
  if (child.kind !== "node") continue;
@@ -143,7 +153,7 @@ const checkBits = (node, report) => {
143
153
  }
144
154
  /** A bit field's width, null when it isn't an integer literal, or undefined. */
145
155
  const bits = (field) => {
146
- const unit = field.type && leaves$1(field.type).at(-1);
156
+ const unit = field.type && leaves$2(field.type).at(-1);
147
157
  if (unit?.text !== "bit" && unit?.text !== "bits") return;
148
158
  const size = field.type.children[0];
149
159
  const digits = size?.kind === "token" && size.type === "num" ? literalDigits(size.text) : null;
@@ -171,7 +181,7 @@ const anything = {
171
181
  /** Combine one production's digit facts from its children's. */
172
182
  const digitsAt = (node, of) => {
173
183
  const [head] = node.children;
174
- const children = nodes$1(node);
184
+ const children = nodes$2(node);
175
185
  switch (node.rule) {
176
186
  case "TextPattern": {
177
187
  const parts = children.map(of);
@@ -191,7 +201,7 @@ const digitsAt = (node, of) => {
191
201
  case "Atom": break;
192
202
  default: return anything;
193
203
  }
194
- const words = leaves$1(node).map((leaf) => leaf.text);
204
+ const words = leaves$2(node).map((leaf) => leaf.text);
195
205
  if (isOp(head, "(")) return anything;
196
206
  if (head?.kind === "token" && head.type === "str") return {
197
207
  only: /^\d*$/.test(head.text),
@@ -224,24 +234,24 @@ const atomDigits = (atom, cache) => {
224
234
  const node = stack.pop();
225
235
  if (!cache.has(node)) {
226
236
  order.push(node);
227
- if (node.rule !== "Expression") stack.push(...nodes$1(node));
237
+ if (node.rule !== "Expression") stack.push(...nodes$2(node));
228
238
  }
229
239
  }
230
240
  for (const node of order.reverse()) cache.set(node, digitsAt(node, (child) => cache.get(child)));
231
241
  return cache.get(atom);
232
242
  };
233
243
  const isTypedNumber = (atom) => {
234
- const kind = nodes$1(atom).find((child) => child.rule === "Kind");
235
- return Boolean(kind && text(kind) === "number" && leaves$1(atom).length === 1);
244
+ const kind = nodes$2(atom).find((child) => child.rule === "Kind");
245
+ return Boolean(kind && text(kind) === "number" && leaves$2(atom).length === 1);
236
246
  };
237
247
  const checkAtom = (atom, repeated, report) => {
238
248
  const [head, colon] = atom.children;
239
249
  if (repeated && head?.kind === "name" && isOp(colon, ":")) report("capture in repetition", head);
240
- const kind = nodes$1(atom).find((child) => child.rule === "Kind");
241
- if (kind && leaves$1(atom).length === 1 && text(kind) !== "number") report("unknown kind", firstLeaf$3(kind));
250
+ const kind = nodes$2(atom).find((child) => child.rule === "Kind");
251
+ if (kind && leaves$2(atom).length === 1 && text(kind) !== "number") report("unknown kind", firstLeaf$3(kind));
242
252
  };
243
253
  const checkElement = (element, cache, report) => {
244
- const atom = nodes$1(element)[0];
254
+ const atom = nodes$2(element)[0];
245
255
  const { children } = element;
246
256
  for (let index = 1; index < children.length; index++) {
247
257
  const as = children[index - 1];
@@ -261,7 +271,7 @@ const checkElement = (element, cache, report) => {
261
271
  * kinds and conversions, `ignoring case` and `delimited by`, and the
262
272
  * structure of Text and Binary Patterns.
263
273
  */
264
- const checkConstructs = (root, report) => {
274
+ const checkConstructs = (root, report, isShape = () => false) => {
265
275
  const work = [{
266
276
  node: root,
267
277
  repeated: false
@@ -272,7 +282,10 @@ const checkConstructs = (root, report) => {
272
282
  let inner = repeated;
273
283
  switch (node.rule) {
274
284
  case "Comparison":
275
- checkComparison(node, report);
285
+ checkComparison(node, report, isShape);
286
+ break;
287
+ case "Handler":
288
+ checkClauseShapes(node, report, isShape);
276
289
  break;
277
290
  case "Conversion":
278
291
  checkConversion(node, report);
@@ -296,7 +309,7 @@ const checkConstructs = (root, report) => {
296
309
  break;
297
310
  case "Atom":
298
311
  checkAtom(node, repeated, report);
299
- inner ||= nodes$1(node).some((child) => child.rule === "Atom");
312
+ inner ||= nodes$2(node).some((child) => child.rule === "Atom");
300
313
  break;
301
314
  case "Element":
302
315
  checkElement(node, digits, report);
@@ -314,6 +327,203 @@ const checkConstructs = (root, report) => {
314
327
  }
315
328
  };
316
329
  //#endregion
330
+ //#region src/shapes.ts
331
+ /** Each loadable Shape declaration's data, by its Declaration node. */
332
+ const shapeData = /* @__PURE__ */ new WeakMap();
333
+ const scalarNames = /* @__PURE__ */ new Set([
334
+ ...kindNames,
335
+ "any",
336
+ "value"
337
+ ]);
338
+ const unitKindNames = new Set(unitKinds);
339
+ const nodes$1 = (node) => node.children.filter((child) => child.kind === "node");
340
+ const leaves$1 = (node) => node.children.flatMap((child) => child.kind === "node" ? leaves$1(child) : [child]);
341
+ const isToken$1 = (element, text) => element?.kind === "token" && element.text === text;
342
+ /** A Shape declaration, unwrapped from `private`, or null. */
343
+ const shapeDeclaration = (node) => {
344
+ if (node.rule !== "Declaration") return null;
345
+ const [first, second] = node.children;
346
+ if (isToken$1(first, "private") && second?.kind === "node") return shapeDeclaration(second);
347
+ return isToken$1(first, "shape") ? node : null;
348
+ };
349
+ const expression = (node) => {
350
+ const terms = nodes$1(node).map(term);
351
+ return terms.length === 1 ? terms[0] : {
352
+ k: "oneOf",
353
+ of: terms
354
+ };
355
+ };
356
+ const term = (node) => {
357
+ if (node.rule === "ShapeExpr") return expression(node);
358
+ const [first, second] = node.children;
359
+ if (first?.kind === "node") {
360
+ if (first.rule === "ShapeMap") return map(first);
361
+ const words = leaves$1(first);
362
+ return {
363
+ k: "name",
364
+ at: words[0],
365
+ name: words.map((word) => word.text).join(" ")
366
+ };
367
+ }
368
+ if (first?.kind === "token" && first.type === "unit") return {
369
+ k: "unit",
370
+ unit: first.text
371
+ };
372
+ if (isToken$1(first, "(")) return expression(second);
373
+ if (isToken$1(first, "optional")) return {
374
+ k: "optional",
375
+ of: term(second)
376
+ };
377
+ const last = node.children.at(-1);
378
+ const name = last.kind === "node" ? leaves$1(last)[0] : last;
379
+ if (isToken$1(first, "list")) return {
380
+ k: "list",
381
+ of: term(last)
382
+ };
383
+ if (isToken$1(first, "object")) return {
384
+ k: "object",
385
+ kind: name.text
386
+ };
387
+ return {
388
+ k: "unitKind",
389
+ at: name,
390
+ kind: name.text
391
+ };
392
+ };
393
+ const map = (node) => ({
394
+ k: "map",
395
+ open: node.children.some((child) => isToken$1(child, "...")),
396
+ fields: nodes$1(node).map((field) => {
397
+ const [key, ...rest] = field.children;
398
+ const at = leaves$1(key)[0];
399
+ return {
400
+ at,
401
+ key: at.text,
402
+ optional: isToken$1(rest[0], "optional"),
403
+ shape: expression(rest.at(-1))
404
+ };
405
+ })
406
+ });
407
+ /**
408
+ * Check every Shape declaration in a unit, report `bad shape` at each
409
+ * offending token, and record the data of each one that loads.
410
+ */
411
+ const checkShapes = (root, lookup, report) => {
412
+ const declared = /* @__PURE__ */ new Map();
413
+ const order = [];
414
+ for (const child of nodes$1(root)) {
415
+ const node = shapeDeclaration(child);
416
+ if (!node) continue;
417
+ const name = leaves$1(node.children[1])[0];
418
+ const shape = term(node.children[3]);
419
+ order.push({
420
+ name,
421
+ node,
422
+ term: shape
423
+ });
424
+ if (!declared.has(name.text)) declared.set(name.text, {
425
+ node,
426
+ term: shape
427
+ });
428
+ if (scalarNames.has(name.text) || unitNames.has(name.text) || unitKindNames.has(name.text)) report("bad shape", name);
429
+ }
430
+ if (!order.length) return;
431
+ const edges = /* @__PURE__ */ new Map();
432
+ let failed = false;
433
+ const resolve = (from, t) => {
434
+ switch (t.k) {
435
+ case "name": {
436
+ if (scalarNames.has(t.name) || unitNames.has(t.name)) return;
437
+ const binding = lookup(t.name);
438
+ const local = declared.get(t.name);
439
+ if (local && binding?.shape && !binding.importedFrom) edges.get(from).push({
440
+ at: t.at,
441
+ to: local.node
442
+ });
443
+ else if (!binding?.shape) {
444
+ report("bad shape", t.at);
445
+ failed = true;
446
+ }
447
+ return;
448
+ }
449
+ case "unitKind":
450
+ if (!unitKindNames.has(t.kind)) {
451
+ report("bad shape", t.at);
452
+ failed = true;
453
+ }
454
+ return;
455
+ case "list":
456
+ case "optional": return resolve(from, t.of);
457
+ case "oneOf": return t.of.forEach((alternative) => resolve(from, alternative));
458
+ case "map": {
459
+ const keys = /* @__PURE__ */ new Set();
460
+ for (const field of t.fields) {
461
+ if (keys.has(field.key)) {
462
+ report("bad shape", field.at);
463
+ failed = true;
464
+ }
465
+ keys.add(field.key);
466
+ resolve(from, field.shape);
467
+ }
468
+ }
469
+ }
470
+ };
471
+ for (const { node, term: t } of order) {
472
+ edges.set(node, []);
473
+ resolve(node, t);
474
+ }
475
+ const reaches = (from, to) => {
476
+ const seen = /* @__PURE__ */ new Set();
477
+ const work = [from];
478
+ while (work.length) {
479
+ const node = work.pop();
480
+ if (node === to) return true;
481
+ if (!seen.has(node)) {
482
+ seen.add(node);
483
+ work.push(...edges.get(node).map((edge) => edge.to));
484
+ }
485
+ }
486
+ return false;
487
+ };
488
+ const cyclic = /* @__PURE__ */ new Set();
489
+ const firstOnCycle = /* @__PURE__ */ new Map();
490
+ for (const [from, list] of edges) for (const edge of list) {
491
+ if (!reaches(edge.to, from)) continue;
492
+ cyclic.add(from);
493
+ const members = order.filter(({ node }) => node === from || reaches(from, node) && reaches(node, from)).map(({ name }) => name.text).join(" ");
494
+ const seen = firstOnCycle.get(members);
495
+ if (!seen || edge.at.span.start < seen.span.start) firstOnCycle.set(members, edge.at);
496
+ }
497
+ for (const at of firstOnCycle.values()) report("bad shape", at);
498
+ if (failed || cyclic.size) return;
499
+ const lower = (t) => {
500
+ switch (t.k) {
501
+ case "name": {
502
+ if (scalarNames.has(t.name)) return t.name;
503
+ if (unitNames.has(t.name)) return { quantity: t.name };
504
+ const local = declared.get(t.name);
505
+ const binding = lookup(t.name);
506
+ return local && !binding.importedFrom ? lower(local.term) : { ref: binding };
507
+ }
508
+ case "unit": return { quantity: t.unit };
509
+ case "unitKind": return { unitKind: t.kind };
510
+ case "object": return { object: t.kind };
511
+ case "list": return { list: lower(t.of) };
512
+ case "optional": return { optional: lower(t.of) };
513
+ case "oneOf": return { oneOf: t.of.map(lower) };
514
+ case "map": return {
515
+ map: t.fields.map((field) => ({
516
+ key: field.key,
517
+ optional: field.optional,
518
+ shape: lower(field.shape)
519
+ })),
520
+ open: t.open
521
+ };
522
+ }
523
+ };
524
+ for (const { node, term: t } of order) shapeData.set(node, lower(t));
525
+ };
526
+ //#endregion
317
527
  //#region src/semantic.ts
318
528
  /**
319
529
  * The `tell` block lines the checker called as `tell`, because their
@@ -325,6 +535,12 @@ const toldLines = /* @__PURE__ */ new WeakSet();
325
535
  * `SimpleStatement`, with the Grant and Operation each calls (ADR 0094). One
326
536
  * that is also in `toldLines` is called as `tell`; any other as `ask`.
327
537
  */
538
+ /**
539
+ * The declared position of each argument of an Operation call whose labels
540
+ * leave out an Optional argument before a later one, by the call's node
541
+ * (ADR 0160). Every position not listed is passed as Nothing.
542
+ */
543
+ const argumentPositions = /* @__PURE__ */ new WeakMap();
328
544
  const hostCommands = /* @__PURE__ */ new WeakMap();
329
545
  //#endregion
330
546
  //#region src/view.ts
@@ -376,6 +592,20 @@ const labelsOf = (list) => {
376
592
  const labels = list?.kind === "node" ? list.children.flatMap((child) => child.kind === "node" && child.rule === "Label" ? [child.children[0].text] : []) : [];
377
593
  return labels.length ? { labels } : {};
378
594
  };
595
+ const positioned = (node, args, at) => {
596
+ const positions = argumentPositions.get(node);
597
+ if (!positions) return args;
598
+ const out = [];
599
+ positions.forEach((position, i) => {
600
+ while (out.length < position) out.push({
601
+ k: "literal",
602
+ pos: at,
603
+ value: "nothing"
604
+ });
605
+ out.push(args[i]);
606
+ });
607
+ return out;
608
+ };
379
609
  const words$1 = (node) => node.children.map((child) => child.kind === "node" ? "" : child.text).join(" ");
380
610
  /**
381
611
  * Convert a checked Source tree into its declarations. A selection inspects
@@ -422,6 +652,10 @@ const convert = (node, built) => {
422
652
  switch (node.rule) {
423
653
  case "Source": return children.flatMap((child) => child.kind === "node" ? [of(child)] : []);
424
654
  case "Declaration": return declaration(node, of);
655
+ case "ShapeExpr":
656
+ case "ShapeTerm":
657
+ case "ShapeMap":
658
+ case "ShapeField": return null;
425
659
  case "Use": {
426
660
  const from = children.findIndex((child) => isToken(child, "from"));
427
661
  const names = children.slice(0, from).filter((child) => child.kind === "node").map((child) => of(child));
@@ -487,7 +721,7 @@ const convert = (node, built) => {
487
721
  pos: at,
488
722
  grant: target.name.text,
489
723
  operation: children[3].text,
490
- args: list >= 0 ? of(children[list]) : [],
724
+ args: positioned(node, list >= 0 ? of(children[list]) : [], at),
491
725
  ...labelsOf(children[list]),
492
726
  ...into >= 0 && { into: of(children[into]) },
493
727
  wait: nodeAt(4, "AndWait") >= 0
@@ -508,7 +742,7 @@ const convert = (node, built) => {
508
742
  pos: pos(child),
509
743
  grant: target.name.text,
510
744
  operation: child.children[0].text,
511
- args: list >= 0 ? of(child.children[list]) : [],
745
+ args: positioned(child, list >= 0 ? of(child.children[list]) : [], pos(child)),
512
746
  ...labelsOf(child.children[list]),
513
747
  ...resultInto(child.children, of),
514
748
  wait: child.children.some((c) => c.kind === "node" && c.rule === "AndWait")
@@ -906,6 +1140,21 @@ const declaration = (node, of) => {
906
1140
  name: of(node.children[1]),
907
1141
  value: of(fourth)
908
1142
  };
1143
+ if (isToken(first, "shape")) {
1144
+ const at = pos(node);
1145
+ const data = shapeData.get(node);
1146
+ return {
1147
+ k: "constant",
1148
+ pos: at,
1149
+ name: of(node.children[1]),
1150
+ shape: true,
1151
+ value: data ? shapeExpr(data, at) : {
1152
+ k: "literal",
1153
+ pos: at,
1154
+ value: "nothing"
1155
+ }
1156
+ };
1157
+ }
909
1158
  return {
910
1159
  k: "variable",
911
1160
  pos: pos(node),
@@ -913,6 +1162,65 @@ const declaration = (node, of) => {
913
1162
  init: fifth ? of(fifth) : null
914
1163
  };
915
1164
  };
1165
+ const shapeExpr = (data, at) => {
1166
+ const text = (value) => ({
1167
+ k: "text",
1168
+ pos: at,
1169
+ value
1170
+ });
1171
+ const map = (entries) => ({
1172
+ k: "map",
1173
+ pos: at,
1174
+ entries: entries.map(([key, value]) => ({
1175
+ key,
1176
+ value
1177
+ }))
1178
+ });
1179
+ const list = (items) => ({
1180
+ k: "list",
1181
+ pos: at,
1182
+ items: items.map((e) => ({
1183
+ e,
1184
+ spread: false
1185
+ }))
1186
+ });
1187
+ const yes = {
1188
+ k: "literal",
1189
+ pos: at,
1190
+ value: "true"
1191
+ };
1192
+ if (typeof data === "string") return text(data);
1193
+ if ("ref" in data) {
1194
+ const binding = data.ref;
1195
+ return {
1196
+ k: "name",
1197
+ pos: at,
1198
+ name: {
1199
+ kind: "name",
1200
+ role: "value",
1201
+ text: binding.name,
1202
+ binding,
1203
+ span: {
1204
+ line: at.line,
1205
+ col: at.col,
1206
+ start: 0,
1207
+ end: 0
1208
+ }
1209
+ }
1210
+ };
1211
+ }
1212
+ if ("quantity" in data) return map([["quantity", text(data.quantity)]]);
1213
+ if ("unitKind" in data) return map([["unitKind", text(data.unitKind)]]);
1214
+ if ("object" in data) return map([["object", text(data.object)]]);
1215
+ if ("list" in data) return map([["list", shapeExpr(data.list, at)]]);
1216
+ if ("optional" in data) return map([["optional", shapeExpr(data.optional, at)]]);
1217
+ if ("oneOf" in data) return map([["oneOf", list(data.oneOf.map((s) => shapeExpr(s, at)))]]);
1218
+ return map([["map", list(data.map.map((field) => map([
1219
+ ["key", text(field.key)],
1220
+ ["shape", shapeExpr(field.shape, at)],
1221
+ ...field.optional ? [["optional", yes]] : []
1222
+ ])))], ...data.open ? [["open", yes]] : []]);
1223
+ };
916
1224
  const blockAt = (node, i, of) => {
917
1225
  const child = node.children[i];
918
1226
  return child?.kind === "node" && (child.rule === "Block" || child.rule === "Body") ? of(child) : [];
@@ -921,6 +1229,7 @@ const handler = (node, of) => {
921
1229
  const { children } = node;
922
1230
  const fallback = isToken(children[1], "any");
923
1231
  const params = [];
1232
+ const shapes = [];
924
1233
  let guard = null;
925
1234
  let during = null;
926
1235
  let body = [];
@@ -930,8 +1239,16 @@ const handler = (node, of) => {
930
1239
  for (let i = 2; i < children.length; i++) {
931
1240
  const child = children[i];
932
1241
  if (child.kind === "node") {
933
- if (child.rule === "Pattern") params.push(of(child));
934
- else if (child.rule === "Block") body = of(child);
1242
+ if (child.rule === "Pattern") {
1243
+ params.push(of(child));
1244
+ shapes.push(null);
1245
+ } else if (child.rule === "Kind") {
1246
+ const is = isToken(children[i - 2], "is") ? i - 2 : i - 3;
1247
+ shapes[shapes.length - 1] = {
1248
+ kind: of(child),
1249
+ pos: pos(children[is])
1250
+ };
1251
+ } else if (child.rule === "Block") body = of(child);
935
1252
  } else if (child.text === "during") during = children[++i];
936
1253
  else if (child.text === "where") guard = guardAt(children[++i], of);
937
1254
  else if (child.text === "finally" && child.kind === "token") {
@@ -957,6 +1274,7 @@ const handler = (node, of) => {
957
1274
  fallback,
958
1275
  scope: node.scope,
959
1276
  params,
1277
+ shapes,
960
1278
  guard,
961
1279
  body,
962
1280
  finally: fin,
@@ -1017,7 +1335,7 @@ const simpleStatement = (node, of) => {
1017
1335
  pos: at,
1018
1336
  grant: command.grant,
1019
1337
  operation: command.operation,
1020
- args: list >= 0 ? of(children[list]) : [],
1338
+ args: positioned(node, list >= 0 ? of(children[list]) : [], at),
1021
1339
  ...resultInto(children, of),
1022
1340
  wait: children.some((child) => child.kind === "node" && child.rule === "AndWait")
1023
1341
  };
@@ -2269,12 +2587,20 @@ const isElementRead$1 = (node) => {
2269
2587
  return node.rule === "The" && (word$1(second) && word$1(third, "element") || second?.kind === "node" && second.rule === "Key" && keyText(second) === "number" && word$1(fourth, "elements"));
2270
2588
  };
2271
2589
  const isOptionalRead = (node) => node.rule === "The" && word$1(node.children[1], "optional");
2590
+ /** An optional read's key as its plain read spells it, or null when computed from anything but a Text literal. */
2591
+ const optionalKey = (node) => objectKey({
2592
+ ...node,
2593
+ children: node.children.filter((_, index) => index !== 1)
2594
+ })?.key ?? null;
2272
2595
  /** A Guard may call only Built-ins, holds no Lambda and reads no Host property but `id`. */
2273
2596
  const checkGuard = (guard, report) => {
2274
2597
  const work = [guard];
2275
2598
  while (work.length) {
2276
2599
  const node = work.pop();
2277
2600
  const [head] = node.children;
2601
+ if (isOptionalRead(node) && isHostObject(node.children.at(-1))) {
2602
+ if (optionalKey(node) !== "id") report("not in a guard", head);
2603
+ }
2278
2604
  if (node.rule === "Lambda") {
2279
2605
  report("not in a guard", head);
2280
2606
  continue;
@@ -2641,29 +2967,52 @@ const checkEffectCall = (use, grants, report) => {
2641
2967
  }
2642
2968
  const list = nodesOf(node, "ExpressionList")[0];
2643
2969
  const args = list ? nodesOf(list, "Expression") : [];
2644
- if (say && args.length !== 1 || !acceptsArgumentCount(decl.args, args.length)) {
2970
+ const labels = list ? nodesOf(list, "Label") : [];
2971
+ const labelled = labels.length ? labelledPositions(decl, labels) : null;
2972
+ const positions = Array.isArray(labelled) ? labelled : args.map((_, i) => i);
2973
+ if (say && args.length !== 1 || !acceptsArgumentCount(decl.args, (positions.at(-1) ?? -1) + 1)) {
2645
2974
  report("wrong argument count", op);
2646
2975
  return;
2647
2976
  }
2648
- const declared = decl.labels ?? [];
2649
- const wrong = (list ? nodesOf(list, "Label") : []).find((label, i) => firstLeaf$1(label)?.text !== declared[i]);
2650
- if (wrong) report("wrong labels", firstLeaf$1(wrong));
2977
+ if (labelled && !Array.isArray(labelled)) report("wrong labels", firstLeaf$1(labelled.wrong));
2978
+ if (positions.some((position, i) => position !== i)) argumentPositions.set(node, positions);
2651
2979
  args.forEach((arg, i) => {
2652
2980
  const literal = literalOf(arg);
2653
- if (literal && !fits(literal, decl.args[i])) report("wrong argument", firstLeaf$1(arg));
2981
+ if (literal && !fits(literal, decl.args[positions[i] ?? i])) report("wrong argument", firstLeaf$1(arg));
2654
2982
  });
2655
2983
  };
2656
2984
  /**
2985
+ * Each argument's declared position. A labelled call writes the declared
2986
+ * labels in order, and may leave out an Optional argument with its label:
2987
+ * each label takes the first declared position after the previous
2988
+ * argument's with that word (ADR 0115, ADR 0160). A label with no such
2989
+ * position, or one that skips a required argument, is wrong.
2990
+ */
2991
+ const labelledPositions = (decl, labels) => {
2992
+ const declared = decl.labels ?? [];
2993
+ const positions = [0];
2994
+ for (const label of labels) {
2995
+ const previous = positions.at(-1);
2996
+ const at = declared.indexOf(firstLeaf$1(label)?.text ?? "", previous);
2997
+ if (at < 0 || decl.args.slice(previous + 1, at + 1).some((shape) => shape.k !== "optional")) return { wrong: label };
2998
+ positions.push(at + 1);
2999
+ }
3000
+ return positions;
3001
+ };
3002
+ /**
2657
3003
  * The Selectors a Host Command answers: its name, and for an Operation with
2658
- * `labels`, its name and the labels of each argument count it accepts past
2659
- * the first, so `move` with `labels = ["to"]` answers `move` and `move:to:`
2660
- * (ADR 0115).
3004
+ * `labels`, one for each set of labels a call may write, leaving out only
3005
+ * Optional arguments, so `move` with `labels = ["to"]` answers `move` and
3006
+ * `move:to:` (ADR 0115, ADR 0160).
2661
3007
  */
2662
3008
  const commandSelectors = (operation, decl) => {
2663
- const selectors = [operation];
3009
+ const selectors = /* @__PURE__ */ new Set([operation]);
2664
3010
  const labels = decl.labels ?? [];
2665
- for (let n = 2; n <= labels.length + 1; n++) if (acceptsArgumentCount(decl.args, n)) selectors.push(`${[operation, ...labels.slice(0, n - 1)].join(":")}:`);
2666
- return selectors;
3011
+ for (let mask = 1; mask < 2 ** labels.length; mask++) {
3012
+ const written = labels.filter((_, i) => mask & 2 ** i);
3013
+ if (!decl.args.filter((shape, i) => i > 0 && !(mask & 2 ** (i - 1)) && shape.k !== "optional").length) selectors.add(`${[operation, ...written].join(":")}:`);
3014
+ }
3015
+ return [...selectors];
2667
3016
  };
2668
3017
  /**
2669
3018
  * Resolve each Command Call that names no Handler of the unit, local or
@@ -3003,7 +3352,8 @@ const DECLARATION_WORDS = [
3003
3352
  "function",
3004
3353
  "private",
3005
3354
  "use",
3006
- "constant"
3355
+ "constant",
3356
+ "shape"
3007
3357
  ];
3008
3358
  const STATEMENT_WORDS = /* @__PURE__ */ new Set([
3009
3359
  ...BLOCK_KEYWORDS,
@@ -3327,22 +3677,28 @@ var Parser = class Parser {
3327
3677
  if (!this.isOp(t, v)) this.fail(t, `\`${v}\``);
3328
3678
  return this.next(mode);
3329
3679
  }
3330
- *name(what = "a name", mode = "operand") {
3680
+ reservedName(t, role) {
3681
+ if (t.t === "word" && RESERVED.has(t.v)) throw new ParseError(t, "reserved word", `\`${t.v}\` is a Reserved Word, so it can't name ${role}`);
3682
+ }
3683
+ *name(what = "a name", mode = "operand", role = "a variable") {
3331
3684
  const frame = this.enter("Name");
3332
3685
  try {
3333
3686
  const t = this.peek(0, mode);
3334
- if (!this.isName(t)) this.fail(t, what);
3687
+ if (!this.isName(t)) {
3688
+ this.reservedName(t, role);
3689
+ this.fail(t, what);
3690
+ }
3335
3691
  return this.next(mode).v;
3336
3692
  } finally {
3337
3693
  this.leave(frame);
3338
3694
  }
3339
3695
  }
3340
- *messageName(what) {
3696
+ *messageName(what, role = "a message") {
3341
3697
  const frame = this.enter("MessageName");
3342
3698
  try {
3343
3699
  const t = this.peek(0);
3344
3700
  if (this.isWord(t, "all")) this.fail(t, `${what} (\`all\` can't name a message)`);
3345
- return yield this.name(what);
3701
+ return yield this.name(what, "operand", role);
3346
3702
  } finally {
3347
3703
  this.leave(frame);
3348
3704
  }
@@ -3443,7 +3799,7 @@ var Parser = class Parser {
3443
3799
  if (this.isWord(t, "private")) {
3444
3800
  this.next();
3445
3801
  const u = this.peek(0);
3446
- if (!this.isWord(u, "on", "function", "constant")) this.fail(u, "`on`, `function` or `constant` after `private`");
3802
+ if (!this.isWord(u, "on", "function", "constant", "shape")) this.fail(u, "`on`, `function`, `constant` or `shape` after `private`");
3447
3803
  return {
3448
3804
  ...yield this.declaration(),
3449
3805
  private: true
@@ -3464,6 +3820,18 @@ var Parser = class Parser {
3464
3820
  value
3465
3821
  };
3466
3822
  }
3823
+ if (this.isWord(t, "shape")) {
3824
+ this.next();
3825
+ const name = yield this.name("a Shape name");
3826
+ this.expectWord("is", "operator");
3827
+ const shape = yield this.shapeExpr();
3828
+ this.endOfStatement();
3829
+ return {
3830
+ k: "ShapeDecl",
3831
+ name,
3832
+ shape
3833
+ };
3834
+ }
3467
3835
  if (this.isWord(t, "script") && this.isWord(this.la2("script-variable"), "variable")) {
3468
3836
  this.next();
3469
3837
  this.next();
@@ -3480,7 +3848,117 @@ var Parser = class Parser {
3480
3848
  init
3481
3849
  };
3482
3850
  }
3483
- this.fail(t, "`on`, `function`, `script variable`, `constant`, `use` or `private`");
3851
+ this.fail(t, "`on`, `function`, `script variable`, `constant`, `shape`, `use` or `private`");
3852
+ } finally {
3853
+ this.leave(frame);
3854
+ }
3855
+ }
3856
+ *shapeExpr() {
3857
+ const frame = this.enter("ShapeExpr");
3858
+ try {
3859
+ const alternatives = [yield this.shapeTerm()];
3860
+ while (this.atOperatorWord("or")) {
3861
+ this.next("operator");
3862
+ alternatives.push(yield this.shapeTerm());
3863
+ }
3864
+ return alternatives.length === 1 ? alternatives[0] : {
3865
+ k: "ShapeOneOf",
3866
+ alternatives
3867
+ };
3868
+ } finally {
3869
+ this.leave(frame);
3870
+ }
3871
+ }
3872
+ *shapeTerm() {
3873
+ const frame = this.enter("ShapeTerm");
3874
+ try {
3875
+ const t = this.peek(0, "type");
3876
+ if (t.t === "unit" || t.t === "error") return {
3877
+ k: "ShapeUnit",
3878
+ unit: this.next("type").v
3879
+ };
3880
+ if (this.isOp(t, "(")) {
3881
+ this.next();
3882
+ const e = yield this.nested(() => this.shapeExpr());
3883
+ this.expectOp(")");
3884
+ return e;
3885
+ }
3886
+ if (this.isOp(t, "{")) return yield this.shapeMap();
3887
+ if (this.isWord(t, "optional")) {
3888
+ this.next();
3889
+ return {
3890
+ k: "ShapeOptional",
3891
+ shape: yield this.shapeTerm()
3892
+ };
3893
+ }
3894
+ if (this.isWord(t, "list", "object", "a", "an")) {
3895
+ const n = this.la2("shape-of", "operator");
3896
+ if (this.isWord(t, "list", "object") && this.isWord(n, "of")) {
3897
+ this.next();
3898
+ this.next("operator");
3899
+ return t.v === "list" ? {
3900
+ k: "ShapeList",
3901
+ shape: yield this.shapeTerm()
3902
+ } : {
3903
+ k: "ShapeObject",
3904
+ kind: yield this.name("an Object Kind")
3905
+ };
3906
+ }
3907
+ if (this.isWord(t, "a", "an") && this.isWord(n, "quantity")) {
3908
+ this.next();
3909
+ this.next("operator");
3910
+ this.expectWord("of", "operator");
3911
+ return {
3912
+ k: "ShapeUnitKind",
3913
+ kind: yield this.name("a Unit Kind")
3914
+ };
3915
+ }
3916
+ }
3917
+ return {
3918
+ k: "ShapeName",
3919
+ name: yield this.kind()
3920
+ };
3921
+ } finally {
3922
+ this.leave(frame);
3923
+ }
3924
+ }
3925
+ *shapeMap() {
3926
+ const frame = this.enter("ShapeMap");
3927
+ try {
3928
+ this.next();
3929
+ const fields = [];
3930
+ let open = false;
3931
+ if (!this.isOp(this.peek(0), "}")) do {
3932
+ if (fields.length || open) this.next("operator");
3933
+ if (this.isOp(this.peek(0), "...")) {
3934
+ this.next();
3935
+ open = true;
3936
+ break;
3937
+ }
3938
+ fields.push(yield this.shapeField());
3939
+ } while (this.isOp(this.peek(0, "operator"), ","));
3940
+ this.expectOp("}");
3941
+ return {
3942
+ k: "ShapeMap",
3943
+ fields,
3944
+ open
3945
+ };
3946
+ } finally {
3947
+ this.leave(frame);
3948
+ }
3949
+ }
3950
+ *shapeField() {
3951
+ const frame = this.enter("ShapeField");
3952
+ try {
3953
+ const key = yield this.mapKey();
3954
+ const optional = this.isWord(this.peek(0, "type"), "optional");
3955
+ if (optional) this.next("type");
3956
+ return {
3957
+ k: "ShapeField",
3958
+ key,
3959
+ optional,
3960
+ shape: yield this.nested(() => this.shapeExpr())
3961
+ };
3484
3962
  } finally {
3485
3963
  this.leave(frame);
3486
3964
  }
@@ -3521,17 +3999,17 @@ var Parser = class Parser {
3521
3999
  this.next();
3522
4000
  this.next();
3523
4001
  }
3524
- const name = fallback ? FALLBACK : yield this.messageName("a Handler name");
4002
+ const name = fallback ? FALLBACK : yield this.messageName("a Handler name", "a Handler");
3525
4003
  const params = [];
3526
4004
  let guard = null;
3527
4005
  const suffixes = [];
3528
4006
  let during = null;
3529
4007
  const t = this.peek(0);
3530
4008
  const labels = [];
3531
- if (fallback) params.push(yield this.pattern());
4009
+ if (fallback) params.push(yield this.headParam());
3532
4010
  else if (!(t.t === "nl" || t.t === "eof" || this.isWord(t, "where") || this.isOp(t, ","))) {
3533
- params.push(yield this.pattern());
3534
- yield this.labelled(() => this.pattern(), labels, params);
4011
+ params.push(yield this.headParam());
4012
+ yield this.labelled(() => this.headParam(), labels, params);
3535
4013
  }
3536
4014
  let inParams = params.length > 0 && !fallback;
3537
4015
  let canGuard = true;
@@ -3555,7 +4033,7 @@ var Parser = class Parser {
3555
4033
  during = this.next().v;
3556
4034
  inParams = canGuard = false;
3557
4035
  } else if (inParams && labels.length) this.fail(w, "a suffix (no commas between labelled parameters)");
3558
- else if (inParams) params.push(yield this.pattern());
4036
+ else if (inParams) params.push(yield this.headParam());
3559
4037
  else this.fail(w, "`queued`, `dropping`, `replacing`, `deciding` or `during`");
3560
4038
  }
3561
4039
  this.endOfStatement();
@@ -3588,10 +4066,21 @@ var Parser = class Parser {
3588
4066
  this.leave(frame);
3589
4067
  }
3590
4068
  }
4069
+ *headParam() {
4070
+ const p = yield this.pattern();
4071
+ if (!this.atOperatorWord("is")) return p;
4072
+ this.next("operator");
4073
+ if (this.atWord("not")) this.next();
4074
+ const a = this.peek(0);
4075
+ if (!this.isWord(a, "a", "an")) this.fail(a, "`a` or `an` and a kind or Shape name");
4076
+ this.next();
4077
+ yield this.kind();
4078
+ return p;
4079
+ }
3591
4080
  *parameter() {
3592
4081
  const frame = this.enter("Parameter");
3593
4082
  try {
3594
- const name = yield this.name("a parameter name");
4083
+ const name = yield this.name("a parameter name", "operand", "a parameter");
3595
4084
  let dflt = null;
3596
4085
  if (this.isOp(this.peek(0, "operator"), "=")) {
3597
4086
  this.next("operator");
@@ -3609,7 +4098,7 @@ var Parser = class Parser {
3609
4098
  const frame = this.enter("Function");
3610
4099
  try {
3611
4100
  const fn = this.next();
3612
- const name = yield this.name("a function name");
4101
+ const name = yield this.name("a function name", "operand", "a function");
3613
4102
  const params = [];
3614
4103
  if (!this.atEnd("operand")) {
3615
4104
  params.push(yield this.parameter());
@@ -3913,6 +4402,7 @@ var Parser = class Parser {
3913
4402
  const frame = this.enter("Container");
3914
4403
  try {
3915
4404
  const t = this.peek(0);
4405
+ if (!this.isWord(t, "the", "me", "it", "true", "false", "nothing")) this.reservedName(t, "a variable");
3916
4406
  if (!this.startsExpr(t)) this.fail(t, "a Container");
3917
4407
  const e = yield this.chunkLevel();
3918
4408
  let root = e;
@@ -4303,6 +4793,11 @@ var Parser = class Parser {
4303
4793
  this.leave(frame);
4304
4794
  }
4305
4795
  }
4796
+ repeatWith(t) {
4797
+ if (!this.isWord(t, "with")) return;
4798
+ const n = this.la2("repeat-with", "operator");
4799
+ if (this.isName(n) && !FOLLOW.has(n.v)) throw new ParseError(t, "repeat with", `NorthTalk has no \`repeat with\`; count with \`repeat for each i in 1..n\``);
4800
+ }
4306
4801
  *repeat() {
4307
4802
  const frame = this.enter("Repeat");
4308
4803
  try {
@@ -4329,6 +4824,7 @@ var Parser = class Parser {
4329
4824
  this.next();
4330
4825
  head = { k: "Forever" };
4331
4826
  } else {
4827
+ this.repeatWith(t);
4332
4828
  const n = yield this.expr();
4333
4829
  this.expectWord("times", "operator");
4334
4830
  head = {
@@ -4660,7 +5156,9 @@ var Parser = class Parser {
4660
5156
  }
4661
5157
  }
4662
5158
  *whoseCondition() {
4663
- this.whoseKeyAt = this.peek(0).pos;
5159
+ const t = this.peek(0);
5160
+ if (!this.startsExpr(t)) this.reservedName(t, "a key");
5161
+ this.whoseKeyAt = t.pos;
4664
5162
  return yield this.expr();
4665
5163
  }
4666
5164
  *lambda() {
@@ -5690,6 +6188,7 @@ var Parser = class Parser {
5690
6188
  name: t.v
5691
6189
  };
5692
6190
  }
6191
+ this.reservedName(t, "a variable");
5693
6192
  this.fail(t, "a pattern");
5694
6193
  } finally {
5695
6194
  this.leave(frame);
@@ -5799,7 +6298,10 @@ var Parser = class Parser {
5799
6298
  if (t.t !== "word") this.fail(t, "a Text Pattern element");
5800
6299
  const n = this.la2("capture", "pattern");
5801
6300
  if (this.isOp(n, ":")) {
5802
- if (!this.isName(t)) this.fail(t, "a Capture name (a Reserved Word can't name one)");
6301
+ if (!this.isName(t)) {
6302
+ this.reservedName(t, "a Capture");
6303
+ this.fail(t, "a Capture name");
6304
+ }
5803
6305
  this.next("pattern");
5804
6306
  this.next("pattern");
5805
6307
  return {
@@ -6391,7 +6893,8 @@ const checkParsed = (syntax, options) => {
6391
6893
  unit.bindings.set(name, {
6392
6894
  ...makeBinding(name, previous.kind, unit, null),
6393
6895
  contract: previous.contract,
6394
- importedFrom: previous.importedFrom
6896
+ importedFrom: previous.importedFrom,
6897
+ ...previous.shape ? { shape: true } : {}
6395
6898
  });
6396
6899
  const handler = previous.kind === "handler" ? previous : previous.handler;
6397
6900
  if (handler) handlers.set(name, previous.kind === "handler" ? unit.bindings.get(name) : {
@@ -6403,14 +6906,15 @@ const checkParsed = (syntax, options) => {
6403
6906
  for (const name of options.objects ?? []) unit.bindings.set(name, makeBinding(name, "object", unit, null));
6404
6907
  for (const scope of scopes.slice(1)) scope.bindings.set("it", makeBinding("it", "local", scope, null));
6405
6908
  const declarationSites = [];
6406
- const declaration = (token, kind, importedFrom, contract) => {
6909
+ const declaration = (token, kind, importedFrom, contract, shape) => {
6407
6910
  const site = mark(token, importedFrom ? "import" : "declaration");
6408
6911
  site.scope = unit;
6409
6912
  declarationSites.push({
6410
6913
  site,
6411
6914
  kind,
6412
6915
  importedFrom,
6413
- contract
6916
+ contract,
6917
+ shape
6414
6918
  });
6415
6919
  };
6416
6920
  const importInfo = (library, name) => {
@@ -6434,6 +6938,9 @@ const checkParsed = (syntax, options) => {
6434
6938
  if (head.v === "constant" || head.v === "script") {
6435
6939
  const name = context.get(ns().find((node) => node.rule === "Name"))?.first;
6436
6940
  if (name) declaration(name, head.v === "constant" ? "constant" : "script variable");
6941
+ } else if (head.v === "shape") {
6942
+ const name = context.get(ns().find((node) => node.rule === "Name"))?.first;
6943
+ if (name) declaration(name, "constant", void 0, void 0, true);
6437
6944
  }
6438
6945
  break;
6439
6946
  case "Handler":
@@ -6467,7 +6974,7 @@ const checkParsed = (syntax, options) => {
6467
6974
  if (info) declaration(rename ?? name, info.kind, {
6468
6975
  library: library.v,
6469
6976
  name: name.v
6470
- }, info.contract);
6977
+ }, info.contract, info.shape);
6471
6978
  else {
6472
6979
  mark(rename ?? name, "import");
6473
6980
  report("unknown import", options.libraries && Object.hasOwn(options.libraries, library.v) || libraryExports.some((entry) => entry.library === library.v) && (options.stdlib?.has(library.v) ?? true) ? name : library);
@@ -6597,7 +7104,7 @@ const checkParsed = (syntax, options) => {
6597
7104
  };
6598
7105
  let firstTokens;
6599
7106
  const firstTokenAt = { get: (pos) => (firstTokens ??= new Map(ordered.map((info) => info.element).filter((element) => element.kind === "token").map((token) => [token.pos, token]))).get(pos) };
6600
- for (const { site, kind, importedFrom, contract } of declarationSites) {
7107
+ for (const { site, kind, importedFrom, contract, shape } of declarationSites) {
6601
7108
  const old = unit.bindings.get(site.name.text);
6602
7109
  const handler = handlers.get(site.name.text);
6603
7110
  const canShare = (previous) => !previous.importedFrom && !importedFrom && (kind === "handler" && [
@@ -6611,6 +7118,7 @@ const checkParsed = (syntax, options) => {
6611
7118
  const binding = (previous?.kind === kind ? previous : void 0) ?? makeBinding(site.name.text, kind, unit, site.token);
6612
7119
  if (importedFrom && !previous) binding.importedFrom = importedFrom;
6613
7120
  if (contract && !previous) binding.contract = contract;
7121
+ if (shape && !previous) binding.shape = true;
6614
7122
  if (kind === "handler") handlers.set(site.name.text, binding);
6615
7123
  if (kind !== "handler" || !old || old.kind === "handler") unit.bindings.set(site.name.text, binding);
6616
7124
  site.name.binding = binding;
@@ -6713,7 +7221,7 @@ const checkParsed = (syntax, options) => {
6713
7221
  const earlier = (site.binary ? binaryBindings.get(site.binary)?.get(site.name.text) : void 0)?.find((candidate) => (context.get(candidate.token)?.parent?.end ?? candidate.token.end) <= site.token.pos);
6714
7222
  site.name.binding = earlier?.name.binding ?? null;
6715
7223
  if (!site.name.binding) report("unknown name", site.token);
6716
- } else if (!binding) report("unknown name", site.token, inWhoseCondition(site.token) ? `unknown name: ${site.token.v}; a key of the chunk is \`it's ${site.token.v}\`` : void 0);
7224
+ } else if (!binding) report("unknown name", site.token, inWhoseCondition(site.token) ? `unknown name: ${site.token.v}; only a Whose condition's first name is a key, so write \`it's ${site.token.v}\`` : void 0);
6717
7225
  else {
6718
7226
  site.name.binding = binding;
6719
7227
  if (site.name.role === "value" && (binding.kind === "handler" || binding.kind === "builtin function")) report("not a value", site.token);
@@ -6820,7 +7328,9 @@ const checkParsed = (syntax, options) => {
6820
7328
  message: `${code}: ${at.text}`
6821
7329
  });
6822
7330
  checkControl(root, options.unit ?? "script", reportAt, options.objectProperties, options.ownerProperties);
6823
- checkConstructs(root, reportAt);
7331
+ const unitBinding = (name) => unit.bindings.get(name);
7332
+ checkConstructs(root, reportAt, (name) => unitBinding(name)?.shape === true);
7333
+ checkShapes(root, unitBinding, reportAt);
6824
7334
  const commands = options.grants ? resolveHostCommands(root, options.grants, reportAt) : [];
6825
7335
  if (options.grants) checkEffects(root, options.grants, reportAt);
6826
7336
  const importedSuspension = (binding) => {
@@ -6863,4 +7373,4 @@ const checkSource = (source, options = {}) => checkParsedSource(parseSource(sour
6863
7373
  /** Internal compilation path; public semantic trees retain all productions. */
6864
7374
  const checkSourceForLoad = (source, options = {}) => checkParsedSource(parseSourceForLoad(source), options);
6865
7375
  //#endregion
6866
- export { viewSource as _, syntaxText as a, parseSource as c, operationUses as d, declarationDocs as f, checkDecisionCalls as g, leadingDoc as h, syntaxSelector as i, parseSourceRecovering as l, functionDoc as m, checkSourceForLoad as n, ParseError as o, declarationStart as p, checkSyntax as r, parseEntry as s, checkSource as t, checkEffectCall as u, kindNames as v };
7376
+ export { viewSource as _, syntaxText as a, parseSource as c, operationUses as d, declarationDocs as f, checkDecisionCalls as g, leadingDoc as h, syntaxSelector as i, parseSourceRecovering as l, functionDoc as m, checkSourceForLoad as n, ParseError as o, declarationStart as p, checkSyntax as r, parseEntry as s, checkSource as t, checkEffectCall as u, shapeData as v, kindNames as y };