@northtalk/ts 0.6.0 → 0.8.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.
- package/{binary-value-C4ZiXVjv.d.ts → binary-value-B93hEK7l.d.ts} +1 -1
- package/{checker-CUhn2XaM.js → checker-Q4w7rLXk.js} +600 -85
- package/{core-egHbNmve.d.ts → core-BBPI6EhG.d.ts} +1 -1
- package/{debug--Of4MSLw.d.ts → debug-s6QIovKS.d.ts} +142 -10
- package/debug.d.ts +1 -1
- package/debug.js +1 -1
- package/{driver-BIm1mL77.d.ts → driver-D5yrK3Nu.d.ts} +1 -1
- package/driver.d.ts +1 -1
- package/driver.js +1 -1
- package/encoding-B7MCQ4ii.js +338 -0
- package/{engine-DbDcopGM.d.ts → engine-Dy-BCoiw.d.ts} +2 -2
- package/{engine-CXf5FCwi.js → engine-OL1BveVZ.js} +6 -6
- package/{errors-D11zizZg.js → errors-VuwK669R.js} +157 -23
- package/{group-BpzTo0k4.js → group-Ccuqwq12.js} +477 -110
- package/{http-fetch-DFwVIOQg.js → http-fetch--O27xjSW.js} +2 -2
- package/http.d.ts +1 -1
- package/http.js +4 -4
- package/index.d.ts +6 -6
- package/index.js +15 -14
- package/{inline-grants-XbX9HL_w.js → inline-grants-DmOdgSoK.js} +4 -5
- package/{lean-aCvN6y52.js → lean-BjhQvHyr.js} +13 -8
- package/{lean-DiS9rUcn.d.ts → lean-D6DQfbqH.d.ts} +42 -7
- package/lean.d.ts +6 -6
- package/lean.js +15 -14
- package/{manifest-CCfpn0kC.js → manifest-BeViDIoy.js} +4 -3
- package/{manifest-mpivREn-.d.ts → manifest-l07K7nW-.d.ts} +4 -2
- package/message-layer.d.ts +2 -2
- package/message-layer.js +2 -2
- package/notify.d.ts +1 -1
- package/notify.js +1 -1
- package/{objects-DmUc0lha.js → objects-TarIKBL8.js} +1 -1
- package/{objects-DYq_YvaQ.d.ts → objects-q0lnCK-4.d.ts} +8 -3
- package/{operations-DnCcztkZ.js → operations-BAELnqwf.js} +133 -58
- package/package.json +5 -1
- package/peer-capability-B8eKbljR.js +151 -0
- package/peer.d.ts +180 -0
- package/peer.js +559 -0
- package/{readers-8WCimMop.d.ts → readers-AeB1bJ--.d.ts} +1 -1
- package/{readers-CsvlahLi.js → readers-BG8g59qS.js} +1 -1
- package/{request-pump-binary-oqjWFqZA.js → request-pump-binary-87klb6sX.js} +9 -4
- package/{router-BZ-aYeXA.js → router-DXmPA-qi.js} +4 -4
- package/{router-BQsO8aPV.d.ts → router-DXoJ_2Z4.d.ts} +2 -2
- package/session.d.ts +2 -2
- package/session.js +64 -16
- package/setup.d.ts +3 -2
- package/setup.js +14 -16
- package/sqlite.d.ts +2 -2
- package/sqlite.js +5 -5
- package/{store-DHlo6fP5.js → store-DzpyWjt2.js} +2 -2
- package/store-capability-CxQJ_Huz.js +187 -0
- package/store.d.ts +2 -2
- package/store.js +2 -2
- package/{user-capability-BcRQyyEw.js → user-capability-ClYd8Vln.js} +3 -4
- package/wasm.d.ts +13 -6
- package/wasm.js +47 -19
- package/encoding-RUuES_e4.js +0 -99
- package/store-capability-BrUUAwVS.js +0 -389
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { I as literalDigits, _n as unitKinds, _t as unitText, ft as parseUnit, gn as libraryExports, gt as unitEntry, hn as grammar, mn as diagnosticCodes, pn as builtins, sn as normalizeNFC, st as UnitError, vn as units } from "./errors-VuwK669R.js";
|
|
3
|
+
import { Mt as Lexer, Nt as RESERVED, Pt as runTask, _t as acceptsArgumentCount } from "./operations-BAELnqwf.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$
|
|
37
|
-
const leaves$
|
|
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$
|
|
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$
|
|
60
|
-
const kind = nodes$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
142
|
+
if (node.rule === "BinaryPattern") for (const field of nodes$2(node)) fields.push({
|
|
133
143
|
first: firstLeaf$3(field),
|
|
134
|
-
type: nodes$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
235
|
-
return Boolean(kind && text(kind) === "number" && leaves$
|
|
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$
|
|
241
|
-
if (kind && leaves$
|
|
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$
|
|
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$
|
|
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")
|
|
934
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2649
|
-
|
|
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`,
|
|
2659
|
-
*
|
|
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
|
|
2666
|
-
|
|
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
|
|
@@ -2748,13 +3097,14 @@ const firstLeaf = (e) => {
|
|
|
2748
3097
|
while (!isLeaf(current)) current = current.children[0];
|
|
2749
3098
|
return current;
|
|
2750
3099
|
};
|
|
3100
|
+
const isJoin = (n) => n.rule === "Wait" && word(n.children[1], "for") && word(n.children[2], "all");
|
|
2751
3101
|
const WAITING_RULES = /* @__PURE__ */ new Set([
|
|
2752
3102
|
"Send",
|
|
2753
3103
|
"AskTell",
|
|
2754
3104
|
"OperationLine",
|
|
2755
3105
|
"SimpleStatement"
|
|
2756
3106
|
]);
|
|
2757
|
-
const factsOf = (root, report, lambdas) => {
|
|
3107
|
+
const factsOf = (root, report, lambdas, forbid) => {
|
|
2758
3108
|
const facts = {
|
|
2759
3109
|
commands: [],
|
|
2760
3110
|
calls: [],
|
|
@@ -2762,17 +3112,18 @@ const factsOf = (root, report, lambdas) => {
|
|
|
2762
3112
|
};
|
|
2763
3113
|
const work = root.children.flatMap((c) => c.kind === "node" ? [{
|
|
2764
3114
|
node: c,
|
|
2765
|
-
cleanup: false
|
|
3115
|
+
cleanup: false,
|
|
3116
|
+
join: false
|
|
2766
3117
|
}] : []);
|
|
2767
3118
|
while (work.length) {
|
|
2768
|
-
const { node, cleanup } = work.pop();
|
|
3119
|
+
const { node, cleanup, join } = work.pop();
|
|
2769
3120
|
if (node.rule === "Lambda") {
|
|
2770
3121
|
lambdas.push(node);
|
|
2771
3122
|
continue;
|
|
2772
3123
|
}
|
|
2773
3124
|
const point = (leaf) => {
|
|
2774
3125
|
facts.points.push(leaf);
|
|
2775
|
-
if (cleanup) report("can't suspend here", leaf);
|
|
3126
|
+
if (cleanup || forbid) report("can't suspend here", leaf);
|
|
2776
3127
|
};
|
|
2777
3128
|
const waits = WAITING_RULES.has(node.rule) && has(node, "AndWait");
|
|
2778
3129
|
switch (node.rule) {
|
|
@@ -2781,11 +3132,11 @@ const factsOf = (root, report, lambdas) => {
|
|
|
2781
3132
|
break;
|
|
2782
3133
|
case "Send":
|
|
2783
3134
|
if (has(node, "ResultTarget") && !waits) report("missing and wait", firstLeaf(node));
|
|
2784
|
-
if (waits) point(firstLeaf(node));
|
|
3135
|
+
if (waits && !join) point(firstLeaf(node));
|
|
2785
3136
|
break;
|
|
2786
3137
|
case "AskTell":
|
|
2787
3138
|
case "OperationLine":
|
|
2788
|
-
if (waits) point(firstLeaf(node));
|
|
3139
|
+
if (waits && !join) point(firstLeaf(node));
|
|
2789
3140
|
break;
|
|
2790
3141
|
case "SimpleStatement": {
|
|
2791
3142
|
const [head] = node.children;
|
|
@@ -2799,7 +3150,7 @@ const factsOf = (root, report, lambdas) => {
|
|
|
2799
3150
|
binding,
|
|
2800
3151
|
name: head,
|
|
2801
3152
|
wait: waits,
|
|
2802
|
-
restricted: cleanup
|
|
3153
|
+
restricted: cleanup || forbid
|
|
2803
3154
|
});
|
|
2804
3155
|
if (waits && cleanup) report("can't suspend here", head);
|
|
2805
3156
|
} else if (has(node, "ResultTarget") && !waits && !hostCommands.has(node)) report("missing and wait", head);
|
|
@@ -2812,7 +3163,7 @@ const factsOf = (root, report, lambdas) => {
|
|
|
2812
3163
|
if (name?.kind === "name" && (name.binding?.kind === "function" || name.binding?.kind === "handler")) facts.calls.push({
|
|
2813
3164
|
binding: name.binding,
|
|
2814
3165
|
name,
|
|
2815
|
-
restricted: cleanup
|
|
3166
|
+
restricted: cleanup || forbid
|
|
2816
3167
|
});
|
|
2817
3168
|
break;
|
|
2818
3169
|
}
|
|
@@ -2823,7 +3174,8 @@ const factsOf = (root, report, lambdas) => {
|
|
|
2823
3174
|
const inFinally = cleanup || word(node.children[i - 1], "finally") || recoveryBody(node, i);
|
|
2824
3175
|
work.push({
|
|
2825
3176
|
node: child,
|
|
2826
|
-
cleanup: inFinally
|
|
3177
|
+
cleanup: inFinally,
|
|
3178
|
+
join: join || isJoin(node)
|
|
2827
3179
|
});
|
|
2828
3180
|
}
|
|
2829
3181
|
}
|
|
@@ -2832,9 +3184,11 @@ const factsOf = (root, report, lambdas) => {
|
|
|
2832
3184
|
};
|
|
2833
3185
|
/**
|
|
2834
3186
|
* Check a unit's Suspension Points, and give whether each of its Handlers
|
|
2835
|
-
* may suspend, by name, for the Libraries that export them.
|
|
3187
|
+
* may suspend, by name, for the Libraries that export them. With `forbid`,
|
|
3188
|
+
* every Suspension Point, and every call to a Handler that may reach one, is
|
|
3189
|
+
* `can't suspend here`.
|
|
2836
3190
|
*/
|
|
2837
|
-
const checkSuspension = (root, imported, reportTo) => {
|
|
3191
|
+
const checkSuspension = (root, imported, reportTo, forbid = false) => {
|
|
2838
3192
|
const seen = /* @__PURE__ */ new Set();
|
|
2839
3193
|
const report = (code, at) => {
|
|
2840
3194
|
if (!seen.has(at)) {
|
|
@@ -2853,7 +3207,7 @@ const checkSuspension = (root, imported, reportTo) => {
|
|
|
2853
3207
|
bodies.push({
|
|
2854
3208
|
kind: node.rule === "Handler" ? "handler" : "function",
|
|
2855
3209
|
name: named ? firstLeaf(named).text : node.rule === "Handler" ? "any message" : "",
|
|
2856
|
-
facts: factsOf(node, report, lambdas)
|
|
3210
|
+
facts: factsOf(node, report, lambdas, forbid)
|
|
2857
3211
|
});
|
|
2858
3212
|
}
|
|
2859
3213
|
}
|
|
@@ -2861,7 +3215,7 @@ const checkSuspension = (root, imported, reportTo) => {
|
|
|
2861
3215
|
while (lambdas.length) bodies.push({
|
|
2862
3216
|
kind: "lambda",
|
|
2863
3217
|
name: "",
|
|
2864
|
-
facts: factsOf(lambdas.pop(), report, lambdas)
|
|
3218
|
+
facts: factsOf(lambdas.pop(), report, lambdas, forbid)
|
|
2865
3219
|
});
|
|
2866
3220
|
const may = /* @__PURE__ */ new Map();
|
|
2867
3221
|
for (const b of bodies) if (b.kind === "handler") may.set(b.name, (may.get(b.name) ?? false) || b.facts.points.length > 0);
|
|
@@ -3003,7 +3357,8 @@ const DECLARATION_WORDS = [
|
|
|
3003
3357
|
"function",
|
|
3004
3358
|
"private",
|
|
3005
3359
|
"use",
|
|
3006
|
-
"constant"
|
|
3360
|
+
"constant",
|
|
3361
|
+
"shape"
|
|
3007
3362
|
];
|
|
3008
3363
|
const STATEMENT_WORDS = /* @__PURE__ */ new Set([
|
|
3009
3364
|
...BLOCK_KEYWORDS,
|
|
@@ -3327,22 +3682,28 @@ var Parser = class Parser {
|
|
|
3327
3682
|
if (!this.isOp(t, v)) this.fail(t, `\`${v}\``);
|
|
3328
3683
|
return this.next(mode);
|
|
3329
3684
|
}
|
|
3330
|
-
|
|
3685
|
+
reservedName(t, role) {
|
|
3686
|
+
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}`);
|
|
3687
|
+
}
|
|
3688
|
+
*name(what = "a name", mode = "operand", role = "a variable") {
|
|
3331
3689
|
const frame = this.enter("Name");
|
|
3332
3690
|
try {
|
|
3333
3691
|
const t = this.peek(0, mode);
|
|
3334
|
-
if (!this.isName(t))
|
|
3692
|
+
if (!this.isName(t)) {
|
|
3693
|
+
this.reservedName(t, role);
|
|
3694
|
+
this.fail(t, what);
|
|
3695
|
+
}
|
|
3335
3696
|
return this.next(mode).v;
|
|
3336
3697
|
} finally {
|
|
3337
3698
|
this.leave(frame);
|
|
3338
3699
|
}
|
|
3339
3700
|
}
|
|
3340
|
-
*messageName(what) {
|
|
3701
|
+
*messageName(what, role = "a message") {
|
|
3341
3702
|
const frame = this.enter("MessageName");
|
|
3342
3703
|
try {
|
|
3343
3704
|
const t = this.peek(0);
|
|
3344
3705
|
if (this.isWord(t, "all")) this.fail(t, `${what} (\`all\` can't name a message)`);
|
|
3345
|
-
return yield this.name(what);
|
|
3706
|
+
return yield this.name(what, "operand", role);
|
|
3346
3707
|
} finally {
|
|
3347
3708
|
this.leave(frame);
|
|
3348
3709
|
}
|
|
@@ -3443,7 +3804,7 @@ var Parser = class Parser {
|
|
|
3443
3804
|
if (this.isWord(t, "private")) {
|
|
3444
3805
|
this.next();
|
|
3445
3806
|
const u = this.peek(0);
|
|
3446
|
-
if (!this.isWord(u, "on", "function", "constant")) this.fail(u, "`on`, `function` or `
|
|
3807
|
+
if (!this.isWord(u, "on", "function", "constant", "shape")) this.fail(u, "`on`, `function`, `constant` or `shape` after `private`");
|
|
3447
3808
|
return {
|
|
3448
3809
|
...yield this.declaration(),
|
|
3449
3810
|
private: true
|
|
@@ -3464,6 +3825,18 @@ var Parser = class Parser {
|
|
|
3464
3825
|
value
|
|
3465
3826
|
};
|
|
3466
3827
|
}
|
|
3828
|
+
if (this.isWord(t, "shape")) {
|
|
3829
|
+
this.next();
|
|
3830
|
+
const name = yield this.name("a Shape name");
|
|
3831
|
+
this.expectWord("is", "operator");
|
|
3832
|
+
const shape = yield this.shapeExpr();
|
|
3833
|
+
this.endOfStatement();
|
|
3834
|
+
return {
|
|
3835
|
+
k: "ShapeDecl",
|
|
3836
|
+
name,
|
|
3837
|
+
shape
|
|
3838
|
+
};
|
|
3839
|
+
}
|
|
3467
3840
|
if (this.isWord(t, "script") && this.isWord(this.la2("script-variable"), "variable")) {
|
|
3468
3841
|
this.next();
|
|
3469
3842
|
this.next();
|
|
@@ -3480,7 +3853,117 @@ var Parser = class Parser {
|
|
|
3480
3853
|
init
|
|
3481
3854
|
};
|
|
3482
3855
|
}
|
|
3483
|
-
this.fail(t, "`on`, `function`, `script variable`, `constant`, `use` or `private`");
|
|
3856
|
+
this.fail(t, "`on`, `function`, `script variable`, `constant`, `shape`, `use` or `private`");
|
|
3857
|
+
} finally {
|
|
3858
|
+
this.leave(frame);
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
*shapeExpr() {
|
|
3862
|
+
const frame = this.enter("ShapeExpr");
|
|
3863
|
+
try {
|
|
3864
|
+
const alternatives = [yield this.shapeTerm()];
|
|
3865
|
+
while (this.atOperatorWord("or")) {
|
|
3866
|
+
this.next("operator");
|
|
3867
|
+
alternatives.push(yield this.shapeTerm());
|
|
3868
|
+
}
|
|
3869
|
+
return alternatives.length === 1 ? alternatives[0] : {
|
|
3870
|
+
k: "ShapeOneOf",
|
|
3871
|
+
alternatives
|
|
3872
|
+
};
|
|
3873
|
+
} finally {
|
|
3874
|
+
this.leave(frame);
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
*shapeTerm() {
|
|
3878
|
+
const frame = this.enter("ShapeTerm");
|
|
3879
|
+
try {
|
|
3880
|
+
const t = this.peek(0, "type");
|
|
3881
|
+
if (t.t === "unit" || t.t === "error") return {
|
|
3882
|
+
k: "ShapeUnit",
|
|
3883
|
+
unit: this.next("type").v
|
|
3884
|
+
};
|
|
3885
|
+
if (this.isOp(t, "(")) {
|
|
3886
|
+
this.next();
|
|
3887
|
+
const e = yield this.nested(() => this.shapeExpr());
|
|
3888
|
+
this.expectOp(")");
|
|
3889
|
+
return e;
|
|
3890
|
+
}
|
|
3891
|
+
if (this.isOp(t, "{")) return yield this.shapeMap();
|
|
3892
|
+
if (this.isWord(t, "optional")) {
|
|
3893
|
+
this.next();
|
|
3894
|
+
return {
|
|
3895
|
+
k: "ShapeOptional",
|
|
3896
|
+
shape: yield this.shapeTerm()
|
|
3897
|
+
};
|
|
3898
|
+
}
|
|
3899
|
+
if (this.isWord(t, "list", "object", "a", "an")) {
|
|
3900
|
+
const n = this.la2("shape-of", "operator");
|
|
3901
|
+
if (this.isWord(t, "list", "object") && this.isWord(n, "of")) {
|
|
3902
|
+
this.next();
|
|
3903
|
+
this.next("operator");
|
|
3904
|
+
return t.v === "list" ? {
|
|
3905
|
+
k: "ShapeList",
|
|
3906
|
+
shape: yield this.shapeTerm()
|
|
3907
|
+
} : {
|
|
3908
|
+
k: "ShapeObject",
|
|
3909
|
+
kind: yield this.name("an Object Kind")
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
if (this.isWord(t, "a", "an") && this.isWord(n, "quantity")) {
|
|
3913
|
+
this.next();
|
|
3914
|
+
this.next("operator");
|
|
3915
|
+
this.expectWord("of", "operator");
|
|
3916
|
+
return {
|
|
3917
|
+
k: "ShapeUnitKind",
|
|
3918
|
+
kind: yield this.name("a Unit Kind")
|
|
3919
|
+
};
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
return {
|
|
3923
|
+
k: "ShapeName",
|
|
3924
|
+
name: yield this.kind()
|
|
3925
|
+
};
|
|
3926
|
+
} finally {
|
|
3927
|
+
this.leave(frame);
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
*shapeMap() {
|
|
3931
|
+
const frame = this.enter("ShapeMap");
|
|
3932
|
+
try {
|
|
3933
|
+
this.next();
|
|
3934
|
+
const fields = [];
|
|
3935
|
+
let open = false;
|
|
3936
|
+
if (!this.isOp(this.peek(0), "}")) do {
|
|
3937
|
+
if (fields.length || open) this.next("operator");
|
|
3938
|
+
if (this.isOp(this.peek(0), "...")) {
|
|
3939
|
+
this.next();
|
|
3940
|
+
open = true;
|
|
3941
|
+
break;
|
|
3942
|
+
}
|
|
3943
|
+
fields.push(yield this.shapeField());
|
|
3944
|
+
} while (this.isOp(this.peek(0, "operator"), ","));
|
|
3945
|
+
this.expectOp("}");
|
|
3946
|
+
return {
|
|
3947
|
+
k: "ShapeMap",
|
|
3948
|
+
fields,
|
|
3949
|
+
open
|
|
3950
|
+
};
|
|
3951
|
+
} finally {
|
|
3952
|
+
this.leave(frame);
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
*shapeField() {
|
|
3956
|
+
const frame = this.enter("ShapeField");
|
|
3957
|
+
try {
|
|
3958
|
+
const key = yield this.mapKey();
|
|
3959
|
+
const optional = this.isWord(this.peek(0, "type"), "optional");
|
|
3960
|
+
if (optional) this.next("type");
|
|
3961
|
+
return {
|
|
3962
|
+
k: "ShapeField",
|
|
3963
|
+
key,
|
|
3964
|
+
optional,
|
|
3965
|
+
shape: yield this.nested(() => this.shapeExpr())
|
|
3966
|
+
};
|
|
3484
3967
|
} finally {
|
|
3485
3968
|
this.leave(frame);
|
|
3486
3969
|
}
|
|
@@ -3521,17 +4004,17 @@ var Parser = class Parser {
|
|
|
3521
4004
|
this.next();
|
|
3522
4005
|
this.next();
|
|
3523
4006
|
}
|
|
3524
|
-
const name = fallback ? FALLBACK : yield this.messageName("a Handler name");
|
|
4007
|
+
const name = fallback ? FALLBACK : yield this.messageName("a Handler name", "a Handler");
|
|
3525
4008
|
const params = [];
|
|
3526
4009
|
let guard = null;
|
|
3527
4010
|
const suffixes = [];
|
|
3528
4011
|
let during = null;
|
|
3529
4012
|
const t = this.peek(0);
|
|
3530
4013
|
const labels = [];
|
|
3531
|
-
if (fallback) params.push(yield this.
|
|
4014
|
+
if (fallback) params.push(yield this.headParam());
|
|
3532
4015
|
else if (!(t.t === "nl" || t.t === "eof" || this.isWord(t, "where") || this.isOp(t, ","))) {
|
|
3533
|
-
params.push(yield this.
|
|
3534
|
-
yield this.labelled(() => this.
|
|
4016
|
+
params.push(yield this.headParam());
|
|
4017
|
+
yield this.labelled(() => this.headParam(), labels, params);
|
|
3535
4018
|
}
|
|
3536
4019
|
let inParams = params.length > 0 && !fallback;
|
|
3537
4020
|
let canGuard = true;
|
|
@@ -3555,7 +4038,7 @@ var Parser = class Parser {
|
|
|
3555
4038
|
during = this.next().v;
|
|
3556
4039
|
inParams = canGuard = false;
|
|
3557
4040
|
} else if (inParams && labels.length) this.fail(w, "a suffix (no commas between labelled parameters)");
|
|
3558
|
-
else if (inParams) params.push(yield this.
|
|
4041
|
+
else if (inParams) params.push(yield this.headParam());
|
|
3559
4042
|
else this.fail(w, "`queued`, `dropping`, `replacing`, `deciding` or `during`");
|
|
3560
4043
|
}
|
|
3561
4044
|
this.endOfStatement();
|
|
@@ -3588,10 +4071,21 @@ var Parser = class Parser {
|
|
|
3588
4071
|
this.leave(frame);
|
|
3589
4072
|
}
|
|
3590
4073
|
}
|
|
4074
|
+
*headParam() {
|
|
4075
|
+
const p = yield this.pattern();
|
|
4076
|
+
if (!this.atOperatorWord("is")) return p;
|
|
4077
|
+
this.next("operator");
|
|
4078
|
+
if (this.atWord("not")) this.next();
|
|
4079
|
+
const a = this.peek(0);
|
|
4080
|
+
if (!this.isWord(a, "a", "an")) this.fail(a, "`a` or `an` and a kind or Shape name");
|
|
4081
|
+
this.next();
|
|
4082
|
+
yield this.kind();
|
|
4083
|
+
return p;
|
|
4084
|
+
}
|
|
3591
4085
|
*parameter() {
|
|
3592
4086
|
const frame = this.enter("Parameter");
|
|
3593
4087
|
try {
|
|
3594
|
-
const name = yield this.name("a parameter name");
|
|
4088
|
+
const name = yield this.name("a parameter name", "operand", "a parameter");
|
|
3595
4089
|
let dflt = null;
|
|
3596
4090
|
if (this.isOp(this.peek(0, "operator"), "=")) {
|
|
3597
4091
|
this.next("operator");
|
|
@@ -3609,7 +4103,7 @@ var Parser = class Parser {
|
|
|
3609
4103
|
const frame = this.enter("Function");
|
|
3610
4104
|
try {
|
|
3611
4105
|
const fn = this.next();
|
|
3612
|
-
const name = yield this.name("a function name");
|
|
4106
|
+
const name = yield this.name("a function name", "operand", "a function");
|
|
3613
4107
|
const params = [];
|
|
3614
4108
|
if (!this.atEnd("operand")) {
|
|
3615
4109
|
params.push(yield this.parameter());
|
|
@@ -3913,6 +4407,7 @@ var Parser = class Parser {
|
|
|
3913
4407
|
const frame = this.enter("Container");
|
|
3914
4408
|
try {
|
|
3915
4409
|
const t = this.peek(0);
|
|
4410
|
+
if (!this.isWord(t, "the", "me", "it", "true", "false", "nothing")) this.reservedName(t, "a variable");
|
|
3916
4411
|
if (!this.startsExpr(t)) this.fail(t, "a Container");
|
|
3917
4412
|
const e = yield this.chunkLevel();
|
|
3918
4413
|
let root = e;
|
|
@@ -4303,6 +4798,11 @@ var Parser = class Parser {
|
|
|
4303
4798
|
this.leave(frame);
|
|
4304
4799
|
}
|
|
4305
4800
|
}
|
|
4801
|
+
repeatWith(t) {
|
|
4802
|
+
if (!this.isWord(t, "with")) return;
|
|
4803
|
+
const n = this.la2("repeat-with", "operator");
|
|
4804
|
+
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\``);
|
|
4805
|
+
}
|
|
4306
4806
|
*repeat() {
|
|
4307
4807
|
const frame = this.enter("Repeat");
|
|
4308
4808
|
try {
|
|
@@ -4329,6 +4829,7 @@ var Parser = class Parser {
|
|
|
4329
4829
|
this.next();
|
|
4330
4830
|
head = { k: "Forever" };
|
|
4331
4831
|
} else {
|
|
4832
|
+
this.repeatWith(t);
|
|
4332
4833
|
const n = yield this.expr();
|
|
4333
4834
|
this.expectWord("times", "operator");
|
|
4334
4835
|
head = {
|
|
@@ -4660,7 +5161,9 @@ var Parser = class Parser {
|
|
|
4660
5161
|
}
|
|
4661
5162
|
}
|
|
4662
5163
|
*whoseCondition() {
|
|
4663
|
-
|
|
5164
|
+
const t = this.peek(0);
|
|
5165
|
+
if (!this.startsExpr(t)) this.reservedName(t, "a key");
|
|
5166
|
+
this.whoseKeyAt = t.pos;
|
|
4664
5167
|
return yield this.expr();
|
|
4665
5168
|
}
|
|
4666
5169
|
*lambda() {
|
|
@@ -5690,6 +6193,7 @@ var Parser = class Parser {
|
|
|
5690
6193
|
name: t.v
|
|
5691
6194
|
};
|
|
5692
6195
|
}
|
|
6196
|
+
this.reservedName(t, "a variable");
|
|
5693
6197
|
this.fail(t, "a pattern");
|
|
5694
6198
|
} finally {
|
|
5695
6199
|
this.leave(frame);
|
|
@@ -5799,7 +6303,10 @@ var Parser = class Parser {
|
|
|
5799
6303
|
if (t.t !== "word") this.fail(t, "a Text Pattern element");
|
|
5800
6304
|
const n = this.la2("capture", "pattern");
|
|
5801
6305
|
if (this.isOp(n, ":")) {
|
|
5802
|
-
if (!this.isName(t))
|
|
6306
|
+
if (!this.isName(t)) {
|
|
6307
|
+
this.reservedName(t, "a Capture");
|
|
6308
|
+
this.fail(t, "a Capture name");
|
|
6309
|
+
}
|
|
5803
6310
|
this.next("pattern");
|
|
5804
6311
|
this.next("pattern");
|
|
5805
6312
|
return {
|
|
@@ -6391,7 +6898,8 @@ const checkParsed = (syntax, options) => {
|
|
|
6391
6898
|
unit.bindings.set(name, {
|
|
6392
6899
|
...makeBinding(name, previous.kind, unit, null),
|
|
6393
6900
|
contract: previous.contract,
|
|
6394
|
-
importedFrom: previous.importedFrom
|
|
6901
|
+
importedFrom: previous.importedFrom,
|
|
6902
|
+
...previous.shape ? { shape: true } : {}
|
|
6395
6903
|
});
|
|
6396
6904
|
const handler = previous.kind === "handler" ? previous : previous.handler;
|
|
6397
6905
|
if (handler) handlers.set(name, previous.kind === "handler" ? unit.bindings.get(name) : {
|
|
@@ -6403,14 +6911,15 @@ const checkParsed = (syntax, options) => {
|
|
|
6403
6911
|
for (const name of options.objects ?? []) unit.bindings.set(name, makeBinding(name, "object", unit, null));
|
|
6404
6912
|
for (const scope of scopes.slice(1)) scope.bindings.set("it", makeBinding("it", "local", scope, null));
|
|
6405
6913
|
const declarationSites = [];
|
|
6406
|
-
const declaration = (token, kind, importedFrom, contract) => {
|
|
6914
|
+
const declaration = (token, kind, importedFrom, contract, shape) => {
|
|
6407
6915
|
const site = mark(token, importedFrom ? "import" : "declaration");
|
|
6408
6916
|
site.scope = unit;
|
|
6409
6917
|
declarationSites.push({
|
|
6410
6918
|
site,
|
|
6411
6919
|
kind,
|
|
6412
6920
|
importedFrom,
|
|
6413
|
-
contract
|
|
6921
|
+
contract,
|
|
6922
|
+
shape
|
|
6414
6923
|
});
|
|
6415
6924
|
};
|
|
6416
6925
|
const importInfo = (library, name) => {
|
|
@@ -6434,6 +6943,9 @@ const checkParsed = (syntax, options) => {
|
|
|
6434
6943
|
if (head.v === "constant" || head.v === "script") {
|
|
6435
6944
|
const name = context.get(ns().find((node) => node.rule === "Name"))?.first;
|
|
6436
6945
|
if (name) declaration(name, head.v === "constant" ? "constant" : "script variable");
|
|
6946
|
+
} else if (head.v === "shape") {
|
|
6947
|
+
const name = context.get(ns().find((node) => node.rule === "Name"))?.first;
|
|
6948
|
+
if (name) declaration(name, "constant", void 0, void 0, true);
|
|
6437
6949
|
}
|
|
6438
6950
|
break;
|
|
6439
6951
|
case "Handler":
|
|
@@ -6467,7 +6979,7 @@ const checkParsed = (syntax, options) => {
|
|
|
6467
6979
|
if (info) declaration(rename ?? name, info.kind, {
|
|
6468
6980
|
library: library.v,
|
|
6469
6981
|
name: name.v
|
|
6470
|
-
}, info.contract);
|
|
6982
|
+
}, info.contract, info.shape);
|
|
6471
6983
|
else {
|
|
6472
6984
|
mark(rename ?? name, "import");
|
|
6473
6985
|
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 +7109,7 @@ const checkParsed = (syntax, options) => {
|
|
|
6597
7109
|
};
|
|
6598
7110
|
let firstTokens;
|
|
6599
7111
|
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) {
|
|
7112
|
+
for (const { site, kind, importedFrom, contract, shape } of declarationSites) {
|
|
6601
7113
|
const old = unit.bindings.get(site.name.text);
|
|
6602
7114
|
const handler = handlers.get(site.name.text);
|
|
6603
7115
|
const canShare = (previous) => !previous.importedFrom && !importedFrom && (kind === "handler" && [
|
|
@@ -6611,6 +7123,7 @@ const checkParsed = (syntax, options) => {
|
|
|
6611
7123
|
const binding = (previous?.kind === kind ? previous : void 0) ?? makeBinding(site.name.text, kind, unit, site.token);
|
|
6612
7124
|
if (importedFrom && !previous) binding.importedFrom = importedFrom;
|
|
6613
7125
|
if (contract && !previous) binding.contract = contract;
|
|
7126
|
+
if (shape && !previous) binding.shape = true;
|
|
6614
7127
|
if (kind === "handler") handlers.set(site.name.text, binding);
|
|
6615
7128
|
if (kind !== "handler" || !old || old.kind === "handler") unit.bindings.set(site.name.text, binding);
|
|
6616
7129
|
site.name.binding = binding;
|
|
@@ -6713,7 +7226,7 @@ const checkParsed = (syntax, options) => {
|
|
|
6713
7226
|
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
7227
|
site.name.binding = earlier?.name.binding ?? null;
|
|
6715
7228
|
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
|
|
7229
|
+
} 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
7230
|
else {
|
|
6718
7231
|
site.name.binding = binding;
|
|
6719
7232
|
if (site.name.role === "value" && (binding.kind === "handler" || binding.kind === "builtin function")) report("not a value", site.token);
|
|
@@ -6820,7 +7333,9 @@ const checkParsed = (syntax, options) => {
|
|
|
6820
7333
|
message: `${code}: ${at.text}`
|
|
6821
7334
|
});
|
|
6822
7335
|
checkControl(root, options.unit ?? "script", reportAt, options.objectProperties, options.ownerProperties);
|
|
6823
|
-
|
|
7336
|
+
const unitBinding = (name) => unit.bindings.get(name);
|
|
7337
|
+
checkConstructs(root, reportAt, (name) => unitBinding(name)?.shape === true);
|
|
7338
|
+
checkShapes(root, unitBinding, reportAt);
|
|
6824
7339
|
const commands = options.grants ? resolveHostCommands(root, options.grants, reportAt) : [];
|
|
6825
7340
|
if (options.grants) checkEffects(root, options.grants, reportAt);
|
|
6826
7341
|
const importedSuspension = (binding) => {
|
|
@@ -6829,7 +7344,7 @@ const checkParsed = (syntax, options) => {
|
|
|
6829
7344
|
const existing = options.existing?.[binding.name];
|
|
6830
7345
|
return (binding.kind === "handler" && existing?.handler ? existing.handler : existing)?.maySuspend === true || typeof exp === "object" && exp.maySuspend === true;
|
|
6831
7346
|
};
|
|
6832
|
-
const may = checkSuspension(root, importedSuspension, reportAt);
|
|
7347
|
+
const may = checkSuspension(root, importedSuspension, reportAt, options.forbidSuspension === true);
|
|
6833
7348
|
checkDecisions(root, (binding) => binding.importedFrom ? importedSuspension(binding) : may.get(binding.name) ?? false, reportAt);
|
|
6834
7349
|
diagnostics.sort((a, b) => a.span.start - b.span.start || diagnosticCodes.indexOf(a.code) - diagnosticCodes.indexOf(b.code));
|
|
6835
7350
|
return {
|
|
@@ -6863,4 +7378,4 @@ const checkSource = (source, options = {}) => checkParsedSource(parseSource(sour
|
|
|
6863
7378
|
/** Internal compilation path; public semantic trees retain all productions. */
|
|
6864
7379
|
const checkSourceForLoad = (source, options = {}) => checkParsedSource(parseSourceForLoad(source), options);
|
|
6865
7380
|
//#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,
|
|
7381
|
+
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 };
|