@northtalk/ts 0.2.0 → 0.4.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 (55) hide show
  1. package/README.md +16 -14
  2. package/{base64-DORMd3Hv.js → base64-Dtqaz_0A.js} +880 -409
  3. package/{binary-value-CEmh60GC.d.ts → binary-value-Bb6HPDtM.d.ts} +2 -2
  4. package/{capabilities-CH0FkRMq.js → capabilities-Bi5Qm6Fr.js} +39 -20
  5. package/{checker-Dc1jl2WH.js → checker-DMI4LiRm.js} +321 -112
  6. package/core-BzGUgjL6.d.ts +22 -0
  7. package/{debug-CQBxKnJB.d.ts → debug-C72o2pZy.d.ts} +506 -50
  8. package/debug.d.ts +3 -3
  9. package/debug.js +1 -1
  10. package/driver-ClV_UDEK.d.ts +63 -0
  11. package/driver.d.ts +2 -40
  12. package/driver.js +24 -4
  13. package/{encoding-nlrpj-Pb.js → encoding-C3Q7pIC9.js} +2 -2
  14. package/{engine-BGaJ9dAk.js → engine-BpdGfAND.js} +6 -6
  15. package/{engine-vbYInVYF.d.ts → engine-Dtby_FkE.d.ts} +3 -3
  16. package/{errors-LYJZ_c8h.js → errors-BKJES3Zu.js} +1060 -751
  17. package/{group-B742gg4T.js → group-vuUL2tq-.js} +6526 -1725
  18. package/http.d.ts +2 -2
  19. package/http.js +3 -3
  20. package/index-ByF5j53i.d.ts +779 -0
  21. package/index.d.ts +6 -651
  22. package/index.js +23 -15
  23. package/{http-capability-CSTkw1Yt.js → inline-grants-Cx0Z9XAt.js} +109 -24
  24. package/manifest-Dw-8Unmf.js +256 -0
  25. package/message-layer.d.ts +3 -3
  26. package/message-layer.js +2 -2
  27. package/notify.d.ts +2 -2
  28. package/notify.js +1 -1
  29. package/{objects-Db7IB5vQ.js → objects-BC4fS0vq.js} +1 -1
  30. package/{objects-DJ3QtCCs.d.ts → objects-Dnqor7Gn.d.ts} +12 -4
  31. package/{operation-promises-EgZXG5N_.js → operation-promises-ClA1BTaS.js} +10 -5
  32. package/package.json +2 -2
  33. package/{readers-CjJHKHvH.js → readers-B5e5bBrY.js} +2 -2
  34. package/{readers-BFPuosPk.d.ts → readers-DAFVvvq4.d.ts} +2 -2
  35. package/{request-pump-binary-DdY3X-yl.js → request-pump-binary-BjnyqXV5.js} +4 -4
  36. package/{router--71qvxtY.js → router-BCHEfs4x.js} +5 -5
  37. package/{router-Zhrw5l__.d.ts → router-BspOCPA0.d.ts} +3 -3
  38. package/session.d.ts +41 -3
  39. package/session.js +260 -179
  40. package/setup.d.ts +2 -2
  41. package/setup.js +4 -4
  42. package/sha256-9CGf5BS_.js +168 -0
  43. package/sqlite.d.ts +5 -5
  44. package/sqlite.js +27 -21
  45. package/{store-hJrRULMx.js → store-DTQa0lyE.js} +2 -2
  46. package/{store-capability-OZp4hXmj.js → store-capability-BxXgiRM7.js} +4 -4
  47. package/store.d.ts +3 -3
  48. package/store.js +2 -2
  49. package/{user-capability-BK4Asg7D.js → user-capability-5-IvCeZI.js} +5 -5
  50. package/wasm.d.ts +12 -8
  51. package/wasm.js +67 -39
  52. package/core-DptnvQT9.d.ts +0 -14
  53. package/manifest-BscyH_rW.d.ts +0 -70
  54. package/manifest-DjsxDSuB.js +0 -129
  55. package/sha256-B_kyYw3Z.js +0 -124
@@ -1,6 +1,6 @@
1
1
 
2
- import { J as UnitError, Q as parseUnit, at as diagnosticCodes, ht as normalizeNFC, it as builtins, j as literalDigits, lt as units, nt as unitEntry, ot as grammar, rt as unitText, st as libraryExports } from "./errors-LYJZ_c8h.js";
3
- import { g as runTask, h as RESERVED, m as Lexer, n as acceptsArgumentCount } from "./capabilities-CH0FkRMq.js";
2
+ import { M as literalDigits, at as parseUnit, dt as builtins, ft as diagnosticCodes, gt as units, lt as unitEntry, mt as libraryExports, on as normalizeNFC, pt as grammar, tt as UnitError, ut as unitText } from "./errors-BKJES3Zu.js";
3
+ import { _ as runTask, g as RESERVED, h as Lexer, n as acceptsArgumentCount } from "./capabilities-Bi5Qm6Fr.js";
4
4
  //#region src/constructs.ts
5
5
  /** Chapter 3's kind names. */
6
6
  const kindNames = /* @__PURE__ */ new Set([
@@ -589,6 +589,16 @@ const convert = (node, built) => {
589
589
  const whose = pos(children[1]);
590
590
  if (first?.kind !== "node" || first.rule !== "EveryHead") {
591
591
  const head = of(first);
592
+ if (head.k === "element" && typeof head.index === "number") return {
593
+ k: "whose",
594
+ pos: whose,
595
+ at: head.pos,
596
+ kind: "element",
597
+ index: head.index,
598
+ src: head.base,
599
+ delimiter: null,
600
+ cond
601
+ };
592
602
  if (head.k !== "chunk" || typeof head.index !== "number") return shape(node);
593
603
  return {
594
604
  k: "whose",
@@ -614,7 +624,7 @@ const convert = (node, built) => {
614
624
  const kind = children.slice(1, ofAt).map((child) => child.text).join(" ");
615
625
  return {
616
626
  at: pos(children[1]),
617
- kind: singular.get(kind) ?? shape(node),
627
+ kind: kind === "element" ? kind : singular.get(kind) ?? shape(node),
618
628
  src: of(children[ofAt + 1]),
619
629
  delimiter: children[ofAt + 4] ? of(children[ofAt + 4]) : null
620
630
  };
@@ -1945,10 +1955,6 @@ const decisionFacts = (root) => {
1945
1955
  const current = work.pop();
1946
1956
  const { element } = current;
1947
1957
  let { deciding, handler } = current;
1948
- if (element.kind !== "node") {
1949
- if (element.kind === "token" && (element.text === "veto" || element.text === "pass")) leaves.set(`${element.span.line}:${element.span.col}`, element);
1950
- continue;
1951
- }
1952
1958
  if (element.rule === "Handler") {
1953
1959
  deciding = element.children.some((c) => c.kind === "token" && c.text === "deciding");
1954
1960
  const named = element.children.find((c) => c.kind === "node" && c.rule === "MessageName");
@@ -1970,11 +1976,12 @@ const decisionFacts = (root) => {
1970
1976
  const head = element.children[0];
1971
1977
  if (head?.kind === "name" && head.binding?.kind === "handler" && (!head.binding.importedFrom || head.binding.importedFrom.library.startsWith("@"))) called.add(head.binding.name);
1972
1978
  }
1973
- for (const child of element.children) work.push({
1979
+ for (const child of element.children) if (child.kind === "node") work.push({
1974
1980
  element: child,
1975
1981
  deciding,
1976
1982
  handler
1977
1983
  });
1984
+ else if (child.kind === "token" && (child.text === "veto" || child.text === "pass")) leaves.set(`${child.span.line}:${child.span.col}`, child);
1978
1985
  }
1979
1986
  return {
1980
1987
  leaves,
@@ -2085,9 +2092,12 @@ const leadingDoc = (entry) => {
2085
2092
  * for any other value. A Lambda's is empty, and a stale Function Value keeps
2086
2093
  * its code's documentation, through save and restore too.
2087
2094
  */
2088
- const functionDoc = (value) => {
2095
+ const functionDoc = (value, retained) => {
2089
2096
  const fn = value.asFunction();
2090
- return fn ? codeDoc(fn.code) : null;
2097
+ if (!fn) return null;
2098
+ const doc = codeDoc(fn.code);
2099
+ const stale = fn.code;
2100
+ return doc || !stale.unit || !stale.head?.name ? doc : retained?.get(stale.unit)?.get(stale.head.name) ?? "";
2091
2101
  };
2092
2102
  const codeDoc = (code) => {
2093
2103
  const c = code;
@@ -2249,6 +2259,10 @@ const hostKey = (key) => key !== "id" && !properties.has(key);
2249
2259
  * Host state: `element s of x`, `the first element of x` and
2250
2260
  * `the number of elements of x`.
2251
2261
  */
2262
+ const isCollectionWalk$1 = (node) => {
2263
+ const [first, second] = node.children;
2264
+ return node.rule === "EveryHead" && word$1(second, "element") || node.rule === "The" && second?.kind === "node" && second.rule === "Key" && keyText(second) === "elements" && word$1(first, "the");
2265
+ };
2252
2266
  const isElementRead$1 = (node) => {
2253
2267
  const [first, second, third, fourth] = node.children;
2254
2268
  if (node.rule === "Chunk") return word$1(first, "element") || word$1(first, "elements");
@@ -2266,7 +2280,7 @@ const checkGuard = (guard, report) => {
2266
2280
  continue;
2267
2281
  }
2268
2282
  if (node.rule === "Call" && head?.kind === "name" && head.binding?.kind !== "builtin function") report("not in a guard", head);
2269
- if (isElementRead$1(node)) report("not in a guard", head);
2283
+ if (isElementRead$1(node) || isCollectionWalk$1(node)) report("not in a guard", head);
2270
2284
  else if (node.rule === "The" && !isOptionalRead(node) && isHostObject(node.children.at(-1))) {
2271
2285
  const key = node.children.find((child) => child.kind === "node" && child.rule === "Key");
2272
2286
  const literal = node.children[1];
@@ -2454,13 +2468,14 @@ const checkControl = (root, unit, report, objectProperties, ownerProperties) =>
2454
2468
  if (child.rule === "Expression" && word$1(children[index - 1], "where")) checkGuard(child, report);
2455
2469
  if (child.rule === "Expression" && node.rule === "Whose") checkWhose(child, report);
2456
2470
  const cleanup = word$1(children[index - 1], "finally");
2471
+ const recovery = recoveryBody(node, index);
2457
2472
  work.push({
2458
2473
  node: child,
2459
- context: {
2474
+ context: cleanup || recovery ? {
2460
2475
  ...context,
2461
2476
  ...cleanup ? { finally: context.loops } : {},
2462
- ...recoveryBody(node, index) ? { recovery: context.loops } : {}
2463
- }
2477
+ ...recovery ? { recovery: context.loops } : {}
2478
+ } : context
2464
2479
  });
2465
2480
  }
2466
2481
  }
@@ -2733,6 +2748,12 @@ const firstLeaf = (e) => {
2733
2748
  while (!isLeaf(current)) current = current.children[0];
2734
2749
  return current;
2735
2750
  };
2751
+ const WAITING_RULES = /* @__PURE__ */ new Set([
2752
+ "Send",
2753
+ "AskTell",
2754
+ "OperationLine",
2755
+ "SimpleStatement"
2756
+ ]);
2736
2757
  const factsOf = (root, report, lambdas) => {
2737
2758
  const facts = {
2738
2759
  commands: [],
@@ -2753,7 +2774,7 @@ const factsOf = (root, report, lambdas) => {
2753
2774
  facts.points.push(leaf);
2754
2775
  if (cleanup) report("can't suspend here", leaf);
2755
2776
  };
2756
- const waits = has(node, "AndWait");
2777
+ const waits = WAITING_RULES.has(node.rule) && has(node, "AndWait");
2757
2778
  switch (node.rule) {
2758
2779
  case "Wait":
2759
2780
  point(firstLeaf(node));
@@ -3004,8 +3025,44 @@ const STATEMENT_WORDS = /* @__PURE__ */ new Set([
3004
3025
  "throw",
3005
3026
  "veto"
3006
3027
  ]);
3028
+ const TRANSPARENT_EXPRESSIONS = /* @__PURE__ */ new Set([
3029
+ "Default",
3030
+ "Or",
3031
+ "And",
3032
+ "Not",
3033
+ "Comparison",
3034
+ "Concat",
3035
+ "Range",
3036
+ "Additive",
3037
+ "Multiplicative",
3038
+ "Power",
3039
+ "Unary",
3040
+ "Conversion",
3041
+ "ChunkLevel",
3042
+ "Postfix"
3043
+ ]);
3044
+ const LEVEL_RULES = [
3045
+ "Default",
3046
+ "Or",
3047
+ "And",
3048
+ "Not",
3049
+ "Comparison",
3050
+ "Concat",
3051
+ "Range",
3052
+ "Additive",
3053
+ "Multiplicative",
3054
+ "Power",
3055
+ "Unary"
3056
+ ];
3057
+ const OTHERWISE = 0;
3058
+ const NOT = 3;
3059
+ const COMPARISON = 4;
3060
+ const RANGE = 6;
3061
+ const POWER = 9;
3062
+ const UNARY = 10;
3007
3063
  var Parser = class Parser {
3008
3064
  recovering;
3065
+ compact;
3009
3066
  lx;
3010
3067
  tree;
3011
3068
  frames = [];
@@ -3023,7 +3080,8 @@ var Parser = class Parser {
3023
3080
  }
3024
3081
  leave(frame) {
3025
3082
  this.frames.pop();
3026
- const node = {
3083
+ const only = frame.children[0];
3084
+ const node = this.compact && TRANSPARENT_EXPRESSIONS.has(frame.rule) && frame.children.length === 1 && only?.kind === "node" ? only : {
3027
3085
  kind: "node",
3028
3086
  rule: frame.rule,
3029
3087
  children: frame.children,
@@ -3042,8 +3100,9 @@ var Parser = class Parser {
3042
3100
  whoseKeyAt = -1;
3043
3101
  nlBase = [0];
3044
3102
  site = "";
3045
- constructor(src, recovering = false) {
3103
+ constructor(src, recovering = false, compact = false) {
3046
3104
  this.recovering = recovering;
3105
+ this.compact = compact;
3047
3106
  this.lx = typeof src === "string" ? new Lexer(src) : src;
3048
3107
  }
3049
3108
  record(error) {
@@ -3146,10 +3205,10 @@ var Parser = class Parser {
3146
3205
  start = tok.end;
3147
3206
  continue;
3148
3207
  }
3149
- return {
3208
+ return trivia.length ? {
3150
3209
  ...tok,
3151
3210
  leadingTrivia: [...trivia, ...tok.leadingTrivia]
3152
- };
3211
+ } : tok;
3153
3212
  }
3154
3213
  }
3155
3214
  peek(k, mode = "operand") {
@@ -3205,8 +3264,13 @@ var Parser = class Parser {
3205
3264
  }
3206
3265
  fail(t, expected) {
3207
3266
  if (t.t === "error") this.lexicalFailure(t);
3267
+ if (this.unitWithoutNumber(t)) throw new ParseError(t, "unit without number", `a Unit follows only a number: write \`x as ${t.v}\`, \`x * 1 ${t.v}\`, or the Unit in the Constant`);
3208
3268
  throw new ParseError(t, "unexpected token", `expected ${expected}, found ${t.t === "nl" ? "end of line" : t.t === "eof" ? "end of source" : `\`${t.v}\``}`);
3209
3269
  }
3270
+ unitWithoutNumber(t) {
3271
+ const p = this.prev;
3272
+ return t.t === "word" && unitEntry(t.v) !== void 0 && p !== null && p.line === t.line && (this.isName(p) || p.t === "op" && (p.v === ")" || p.v === "]"));
3273
+ }
3210
3274
  at(t, n) {
3211
3275
  if (n.line === void 0) {
3212
3276
  n.line = t.line;
@@ -3859,11 +3923,13 @@ var Parser = class Parser {
3859
3923
  "Group"
3860
3924
  ];
3861
3925
  if (propertyTarget) path.push("ObjectElement");
3862
- while (root && path.includes(root.k)) root = root.k === "Group" ? root.e : root.of ?? root.base;
3863
- let outer = e;
3864
- while (outer.k === "Group") outer = outer.e;
3926
+ let keyed = false;
3927
+ while (root && path.includes(root.k)) {
3928
+ keyed ||= root.k === "Key";
3929
+ root = root.k === "Group" ? root.e : root.of ?? root.base;
3930
+ }
3865
3931
  const implicitRoot = root?.k === "Target" || root?.k === "Const" && (root.v === "me" || root.v === "it");
3866
- if (!root || root.k !== "Name" && !(propertyTarget && outer.k === "Key" && implicitRoot)) throw new ParseError(t, "not a container", "a Container is a name, or a chunk or key rooted in one");
3932
+ if (!root || root.k !== "Name" && !(propertyTarget && keyed && implicitRoot)) throw new ParseError(t, "not a container", "a Container is a name, or a chunk or key rooted in one");
3867
3933
  return e;
3868
3934
  } finally {
3869
3935
  this.leave(frame);
@@ -4534,7 +4600,7 @@ var Parser = class Parser {
4534
4600
  const t = this.peek(0);
4535
4601
  if (this.isWord(t, "every")) {
4536
4602
  const n = this.la2("every-chunk", "operator");
4537
- if (this.isWord(n) && (SINGULAR.has(n.v) || n.v === "code")) {
4603
+ if (this.isWord(n) && (SINGULAR.has(n.v) || n.v === "code" || n.v === "element")) {
4538
4604
  const frame = this.enter("Whose");
4539
4605
  try {
4540
4606
  const head = yield this.everyHead();
@@ -4551,7 +4617,7 @@ var Parser = class Parser {
4551
4617
  }
4552
4618
  }
4553
4619
  const e = yield this.defaultExpression();
4554
- if (e.k === "OrdinalChunk" && this.atOperatorWord("whose")) {
4620
+ if ((e.k === "OrdinalChunk" || e.k === "ObjectElement" && e.ord) && this.atOperatorWord("whose")) {
4555
4621
  const frame = this.enter("Whose", 1);
4556
4622
  try {
4557
4623
  const op = this.next("operator");
@@ -4578,7 +4644,7 @@ var Parser = class Parser {
4578
4644
  this.expectWord("of", "operator");
4579
4645
  const src = yield this.postfix();
4580
4646
  let delimiter;
4581
- if (this.atOperatorWord("delimited") && this.isWord(this.la2("delimited-by", "operator"), "by")) {
4647
+ if (kind !== "element" && this.atOperatorWord("delimited") && this.isWord(this.la2("delimited-by", "operator"), "by")) {
4582
4648
  this.next("operator");
4583
4649
  this.next();
4584
4650
  delimiter = yield this.postfix();
@@ -4648,6 +4714,7 @@ var Parser = class Parser {
4648
4714
  };
4649
4715
  }
4650
4716
  *defaultExpression() {
4717
+ if (this.compact) return yield this.climb(OTHERWISE);
4651
4718
  const frame = this.enter("Default");
4652
4719
  try {
4653
4720
  let l = yield this.or();
@@ -4665,6 +4732,7 @@ var Parser = class Parser {
4665
4732
  }
4666
4733
  }
4667
4734
  *or() {
4735
+ if (this.compact) return yield this.climb(1);
4668
4736
  const frame = this.enter("Or");
4669
4737
  try {
4670
4738
  let l = yield this.and();
@@ -4682,6 +4750,7 @@ var Parser = class Parser {
4682
4750
  }
4683
4751
  }
4684
4752
  *and() {
4753
+ if (this.compact) return yield this.climb(2);
4685
4754
  const frame = this.enter("And");
4686
4755
  try {
4687
4756
  let l = yield this.not();
@@ -4699,6 +4768,7 @@ var Parser = class Parser {
4699
4768
  }
4700
4769
  }
4701
4770
  *not() {
4771
+ if (this.compact) return yield this.climb(NOT);
4702
4772
  const frame = this.enter("Not");
4703
4773
  try {
4704
4774
  if (this.atWord("not")) {
@@ -4714,9 +4784,16 @@ var Parser = class Parser {
4714
4784
  }
4715
4785
  }
4716
4786
  *comparison() {
4787
+ if (this.compact) return yield this.climb(COMPARISON);
4717
4788
  const frame = this.enter("Comparison");
4718
4789
  try {
4719
- const l = yield this.concat();
4790
+ return yield this.comparisonRest(yield this.concat());
4791
+ } finally {
4792
+ this.leave(frame);
4793
+ }
4794
+ }
4795
+ *comparisonRest(l) {
4796
+ {
4720
4797
  const t = this.peek(0, "operator");
4721
4798
  let node = null;
4722
4799
  if (t.t === "op" && COMPARISONS.has(t.v)) {
@@ -4821,11 +4898,108 @@ var Parser = class Parser {
4821
4898
  this.at(t, node);
4822
4899
  if (yield this.ignoringCase()) node.ignoringCase = true;
4823
4900
  return node;
4824
- } finally {
4825
- this.leave(frame);
4826
4901
  }
4827
4902
  }
4903
+ *climb(min) {
4904
+ const start = this.offset;
4905
+ let left;
4906
+ let cap;
4907
+ if (min <= NOT && this.atWord("not")) {
4908
+ const frame = this.enter("Not");
4909
+ try {
4910
+ const op = this.next();
4911
+ left = this.at(op, {
4912
+ k: "not",
4913
+ e: yield this.climb(NOT)
4914
+ });
4915
+ } finally {
4916
+ this.leave(frame);
4917
+ }
4918
+ cap = 2;
4919
+ } else if (min <= UNARY && this.isOp(this.peek(0), "-")) {
4920
+ const frame = this.enter("Unary");
4921
+ try {
4922
+ const op = this.next();
4923
+ left = this.at(op, {
4924
+ k: "neg",
4925
+ e: yield this.climb(UNARY)
4926
+ });
4927
+ } finally {
4928
+ this.leave(frame);
4929
+ }
4930
+ cap = 9;
4931
+ } else {
4932
+ left = yield this.conversion();
4933
+ cap = 9;
4934
+ }
4935
+ for (;;) {
4936
+ const level = this.operatorLevel(min, cap);
4937
+ if (level < 0) return left;
4938
+ const frame = this.enter(LEVEL_RULES[level], 1);
4939
+ frame.start = start;
4940
+ try {
4941
+ if (level === COMPARISON) left = yield this.comparisonRest(left);
4942
+ else if (level === RANGE || level === POWER) {
4943
+ const op = this.next("operator");
4944
+ const r = yield this.climb(level === POWER ? POWER : 7);
4945
+ left = this.at(op, {
4946
+ k: op.v,
4947
+ l: left,
4948
+ r
4949
+ });
4950
+ } else do {
4951
+ const op = this.next("operator");
4952
+ const r = yield this.climb(level + 1);
4953
+ left = this.at(op, {
4954
+ k: level === OTHERWISE ? "otherwise" : op.v,
4955
+ l: left,
4956
+ r
4957
+ });
4958
+ } while (this.operatorLevel(level, level) === level);
4959
+ } finally {
4960
+ this.leave(frame);
4961
+ }
4962
+ cap = level - 1;
4963
+ }
4964
+ }
4965
+ operatorLevel(min, cap) {
4966
+ for (let level = cap; level >= min; level--) {
4967
+ const t = this.peek(0, "operator");
4968
+ switch (level) {
4969
+ case POWER:
4970
+ if (this.isOp(t, "^")) return level;
4971
+ break;
4972
+ case 8:
4973
+ if (this.isOp(t, "*", "/") || this.isWord(t, "mod", "div")) return level;
4974
+ break;
4975
+ case 7:
4976
+ if (this.isOp(t, "+", "-")) return level;
4977
+ break;
4978
+ case RANGE:
4979
+ if (this.isOp(t, "..")) return level;
4980
+ break;
4981
+ case 5:
4982
+ if (this.isOp(t, "&")) return level;
4983
+ break;
4984
+ case COMPARISON:
4985
+ if (this.startsComparison(t)) return level;
4986
+ break;
4987
+ case 2:
4988
+ if (this.atOperatorWord("and") && !this.isWord(this.la2("and-wait"), "wait")) return level;
4989
+ break;
4990
+ case 1:
4991
+ if (this.atOperatorWord("or")) return level;
4992
+ break;
4993
+ case OTHERWISE: if (this.atOperatorWord("otherwise")) return level;
4994
+ }
4995
+ }
4996
+ return -1;
4997
+ }
4998
+ startsComparison(t) {
4999
+ return t.t === "op" && COMPARISONS.has(t.v) || this.isWord(t, "is", "contains", "matches") || this.isWord(t, "can") && this.isWord(this.la2("can-be", "operator"), "be") || this.isWord(t, "begins", "ends") && this.isWord(this.la2("begins-with", "operator"), "with") || this.isWord(t, "comes") && this.isWord(this.la2("comes", "operator"), "before", "after") || this.isWord(t, "does") && this.isWord(this.la2("does-not", "operator"), "not");
5000
+ }
4828
5001
  *concat() {
5002
+ if (this.compact) return yield this.climb(5);
4829
5003
  const frame = this.enter("Concat");
4830
5004
  try {
4831
5005
  let l = yield this.range();
@@ -4843,6 +5017,7 @@ var Parser = class Parser {
4843
5017
  }
4844
5018
  }
4845
5019
  *range() {
5020
+ if (this.compact) return yield this.climb(RANGE);
4846
5021
  const frame = this.enter("Range");
4847
5022
  try {
4848
5023
  const l = yield this.additive();
@@ -4860,6 +5035,7 @@ var Parser = class Parser {
4860
5035
  }
4861
5036
  }
4862
5037
  *additive() {
5038
+ if (this.compact) return yield this.climb(7);
4863
5039
  const frame = this.enter("Additive");
4864
5040
  try {
4865
5041
  let l = yield this.multiplicative();
@@ -4878,6 +5054,7 @@ var Parser = class Parser {
4878
5054
  }
4879
5055
  }
4880
5056
  *multiplicative() {
5057
+ if (this.compact) return yield this.climb(8);
4881
5058
  const frame = this.enter("Multiplicative");
4882
5059
  try {
4883
5060
  let l = yield this.power();
@@ -4896,6 +5073,7 @@ var Parser = class Parser {
4896
5073
  }
4897
5074
  }
4898
5075
  *power() {
5076
+ if (this.compact) return yield this.climb(POWER);
4899
5077
  const frame = this.enter("Power");
4900
5078
  try {
4901
5079
  const l = yield this.unary();
@@ -4913,6 +5091,7 @@ var Parser = class Parser {
4913
5091
  }
4914
5092
  }
4915
5093
  *unary() {
5094
+ if (this.compact) return yield this.climb(UNARY);
4916
5095
  const frame = this.enter("Unary");
4917
5096
  try {
4918
5097
  if (this.isOp(this.peek(0), "-")) {
@@ -5840,8 +6019,8 @@ var Parser = class Parser {
5840
6019
  }
5841
6020
  };
5842
6021
  /** Parse a Script or Library. Invalid scalar source throws HostError. */
5843
- const parseSource = (source) => {
5844
- const parser = new Parser(source);
6022
+ const parseSourceTree = (source, compact) => {
6023
+ const parser = new Parser(source, false, compact);
5845
6024
  try {
5846
6025
  runTask(parser.source());
5847
6026
  return {
@@ -5856,6 +6035,10 @@ const parseSource = (source) => {
5856
6035
  throw error;
5857
6036
  }
5858
6037
  };
6038
+ /** Public parsing retains every production and token. */
6039
+ const parseSource = (source) => parseSourceTree(source, false);
6040
+ /** Internal strict compilation may omit operator-free precedence wrappers. */
6041
+ const parseSourceForLoad = (source) => parseSourceTree(source, true);
5859
6042
  /** Recover past syntax errors. Invalid scalar source still throws HostError. */
5860
6043
  const parseSourceRecovering = (source) => {
5861
6044
  const parser = new Parser(source, true);
@@ -5935,6 +6118,11 @@ const isElementRead = (node) => {
5935
6118
  if (node.rule === "Chunk") return isWordToken(first, "element") || isWordToken(first, "elements");
5936
6119
  return node.rule === "The" && (second?.kind === "token" && isWordToken(third, "element") || second?.kind === "node" && second.rule === "Key" && tokens(second).map((t) => t.v).join(" ") === "number" && isWordToken(fourth, "elements"));
5937
6120
  };
6121
+ /** `the elements of x` or `every element of x` (#1627). */
6122
+ const isCollectionWalk = (node) => {
6123
+ const [, second] = node.children;
6124
+ return node.rule === "EveryHead" && isWordToken(second, "element") || node.rule === "The" && second?.kind === "node" && second.rule === "Key" && tokens(second).map((t) => t.v).join(" ") === "elements";
6125
+ };
5938
6126
  /** The expression a Container is, past its wrappers and parentheses. */
5939
6127
  const containerExpression = (container) => {
5940
6128
  let node = container;
@@ -6013,8 +6201,8 @@ const parsedSyntax = (root) => {
6013
6201
  * Resolve bindings and check writes, named calls, constants and control flow.
6014
6202
  * On recovered syntax, omit malformed constructs and check retained code.
6015
6203
  */
6016
- const checkSyntax = (syntax, options = {}) => {
6017
- syntax = parsedSyntax(syntax);
6204
+ const checkSyntax = (syntax, options = {}) => checkParsed(parsedSyntax(syntax), options);
6205
+ const checkParsed = (syntax, options) => {
6018
6206
  const scopes = [];
6019
6207
  const newScope = (kind, parent) => {
6020
6208
  const scope = {
@@ -6028,7 +6216,14 @@ const checkSyntax = (syntax, options = {}) => {
6028
6216
  return scope;
6029
6217
  };
6030
6218
  const unit = newScope("unit", null);
6031
- const context = /* @__PURE__ */ new Map();
6219
+ const at = new Array(syntax.end + 1).fill(void 0);
6220
+ const startOf = (element) => element.kind === "node" ? element.start : element.pos;
6221
+ const context = { get(element) {
6222
+ if (!element) return;
6223
+ let info = at[startOf(element)];
6224
+ while (info && info.element !== element) info = info.next;
6225
+ return info;
6226
+ } };
6032
6227
  const ordered = [];
6033
6228
  const work = [{
6034
6229
  element: syntax,
@@ -6040,7 +6235,8 @@ const checkSyntax = (syntax, options = {}) => {
6040
6235
  parent: null,
6041
6236
  first: void 0,
6042
6237
  last: void 0,
6043
- converted: null
6238
+ converted: null,
6239
+ next: void 0
6044
6240
  }];
6045
6241
  while (work.length) {
6046
6242
  const current = work.pop();
@@ -6080,7 +6276,8 @@ const checkSyntax = (syntax, options = {}) => {
6080
6276
  parent: element,
6081
6277
  first: void 0,
6082
6278
  last: void 0,
6083
- converted: null
6279
+ converted: null,
6280
+ next: void 0
6084
6281
  });
6085
6282
  }
6086
6283
  ordered.push(current);
@@ -6089,18 +6286,55 @@ const checkSyntax = (syntax, options = {}) => {
6089
6286
  current.binary = binary;
6090
6287
  current.pattern = pattern;
6091
6288
  current.parameter = parameter;
6092
- context.set(element, current);
6093
- }
6289
+ const start = startOf(element);
6290
+ current.next = at[start];
6291
+ at[start] = current;
6292
+ }
6293
+ const done = [];
6294
+ const slots = [];
6295
+ const slotTokens = [];
6296
+ const slotIndexes = [];
6094
6297
  for (let i = ordered.length - 1; i >= 0; i--) {
6095
6298
  const info = ordered[i];
6096
6299
  const { element } = info;
6097
6300
  if (element.kind === "token") {
6098
6301
  if (element.t !== "nl" && element.t !== "eof") info.first = info.last = element;
6099
- } else for (const child of element.children) {
6100
- const bounds = context.get(child);
6101
- info.first ??= bounds.first;
6102
- if (bounds.last) info.last = bounds.last;
6302
+ } else {
6303
+ const children = [];
6304
+ for (let n = element.children.length; n > 0; n--) {
6305
+ const child = done.pop();
6306
+ info.first ??= child.first;
6307
+ if (child.last) info.last = child.last;
6308
+ const converted = child.element;
6309
+ if (converted.kind === "token") {
6310
+ if (converted.t !== "error" && child.first) {
6311
+ slots.push(children);
6312
+ slotTokens.push(converted);
6313
+ slotIndexes.push(children.length);
6314
+ children.push(null);
6315
+ }
6316
+ } else if (child.converted) children.push(child.converted);
6317
+ }
6318
+ const { first: start, last: end } = info;
6319
+ if (start || element === syntax) info.converted = {
6320
+ kind: "node",
6321
+ rule: element.rule,
6322
+ scope: info.scope.id,
6323
+ children,
6324
+ span: start ? {
6325
+ start: start.pos,
6326
+ end: end.end,
6327
+ line: start.line,
6328
+ col: start.col
6329
+ } : {
6330
+ start: element.start,
6331
+ end: element.end,
6332
+ line: 1,
6333
+ col: 1
6334
+ }
6335
+ };
6103
6336
  }
6337
+ done.push(info);
6104
6338
  }
6105
6339
  const sites = /* @__PURE__ */ new Map();
6106
6340
  const eventScripts = /* @__PURE__ */ new Set();
@@ -6189,22 +6423,24 @@ const checkSyntax = (syntax, options = {}) => {
6189
6423
  };
6190
6424
  for (const { element } of ordered) {
6191
6425
  if (element.kind !== "node" || !siteRules.has(element.rule)) continue;
6192
- const ts = tokens(element);
6193
- const ns = nodes(element);
6426
+ let tokenList;
6427
+ let nodeList;
6428
+ const ts = () => tokenList ??= tokens(element);
6429
+ const ns = () => nodeList ??= nodes(element);
6194
6430
  const head = context.get(element)?.first;
6195
6431
  if (!head) continue;
6196
6432
  switch (element.rule) {
6197
6433
  case "Declaration":
6198
6434
  if (head.v === "constant" || head.v === "script") {
6199
- const name = context.get(ns.find((node) => node.rule === "Name"))?.first;
6435
+ const name = context.get(ns().find((node) => node.rule === "Name"))?.first;
6200
6436
  if (name) declaration(name, head.v === "constant" ? "constant" : "script variable");
6201
6437
  }
6202
6438
  break;
6203
6439
  case "Handler":
6204
6440
  case "Function": {
6205
- const name = context.get(ns.find((node) => node.rule === (element.rule === "Handler" ? "MessageName" : "Name")))?.first;
6441
+ const name = context.get(ns().find((node) => node.rule === (element.rule === "Handler" ? "MessageName" : "Name")))?.first;
6206
6442
  if (name) {
6207
- const parameters = ns.filter((node) => node.rule === "Parameter");
6443
+ const parameters = ns().filter((node) => node.rule === "Parameter");
6208
6444
  declaration(name, element.rule === "Handler" ? "handler" : "function", void 0, element.rule === "Function" ? {
6209
6445
  required: parameters.filter((parameter) => !nodes(parameter).some((node) => node.rule === "Expression")).length,
6210
6446
  total: parameters.length
@@ -6212,8 +6448,8 @@ const checkSyntax = (syntax, options = {}) => {
6212
6448
  if (element.rule === "Handler") sites.get(name).name.text = syntaxSelector(element, name.v);
6213
6449
  }
6214
6450
  if (element.rule === "Handler") {
6215
- const during = ts.findIndex((t) => t.v === "during");
6216
- if (during >= 0 && ts[during + 1]) mark(ts[during + 1], "binding", true);
6451
+ const during = ts().findIndex((t) => t.v === "during");
6452
+ if (during >= 0 && ts()[during + 1]) mark(ts()[during + 1], "binding", true);
6217
6453
  }
6218
6454
  break;
6219
6455
  }
@@ -6242,7 +6478,7 @@ const checkSyntax = (syntax, options = {}) => {
6242
6478
  case "Name": {
6243
6479
  if (sites.has(head)) break;
6244
6480
  const parent = context.get(element).parent;
6245
- const prefix = tokens(parent)[0];
6481
+ const prefix = parent.children.find((child) => child.kind === "token");
6246
6482
  if (parent.rule === "OfferClause" || parent.rule === "ChooseOffer") mark(head, "offer");
6247
6483
  else if (parent.rule === "MessageName") mark(head, "message").name.text = syntaxSelector(context.get(parent).parent, head.v);
6248
6484
  else if (parent.rule === "Parameter" || parent.rule === "OfferParameter" || parent.rule === "Collecting") mark(head, "binding", true);
@@ -6251,21 +6487,21 @@ const checkSyntax = (syntax, options = {}) => {
6251
6487
  break;
6252
6488
  }
6253
6489
  case "PatternPrimary":
6254
- if (isName(head) && !ns.length) mark(head, "binding", true);
6255
- for (let index = 1; index < ts.length; index++) if (ts[index - 1].v === "..." && isName(ts[index])) mark(ts[index], "binding", true);
6490
+ if (isName(head) && !ns().length) mark(head, "binding", true);
6491
+ for (let index = 1; index < ts().length; index++) if (ts()[index - 1].v === "..." && isName(ts()[index])) mark(ts()[index], "binding", true);
6256
6492
  break;
6257
6493
  case "Field":
6258
- if (ts[1]?.v === ":" && isName(head)) mark(head, "binding", true);
6494
+ if (ts()[1]?.v === ":" && isName(head)) mark(head, "binding", true);
6259
6495
  if (head.v === "...") {
6260
- const rest = ts.find(isName);
6496
+ const rest = ts().find(isName);
6261
6497
  if (rest) mark(rest, "binding", true);
6262
6498
  }
6263
6499
  break;
6264
6500
  case "Atom":
6265
- if (ts[1]?.v === ":") mark(head, "capture", context.get(element)?.pattern || context.get(element)?.parent?.rule === "Replace");
6501
+ if (ts()[1]?.v === ":") mark(head, "capture", context.get(element)?.pattern || context.get(element)?.parent?.rule === "Replace");
6266
6502
  break;
6267
6503
  case "Primary":
6268
- if (!sites.has(head) && isName(head) && ts[0] === head && !ns.length) mark(head, context.get(element)?.binary ? "binary size" : "value");
6504
+ if (!sites.has(head) && isName(head) && ts()[0] === head && !ns().length) mark(head, context.get(element)?.binary ? "binary size" : "value");
6269
6505
  if (head.t === "word" && head.v === "it") mark(head, "value");
6270
6506
  break;
6271
6507
  case "Call":
@@ -6277,12 +6513,12 @@ const checkSyntax = (syntax, options = {}) => {
6277
6513
  "bytes",
6278
6514
  "bit",
6279
6515
  "bits"
6280
- ].includes(ts[1]?.v ?? "")) {
6516
+ ].includes(ts()[1]?.v ?? "")) {
6281
6517
  if (isName(head)) mark(head, "binary size");
6282
6518
  }
6283
6519
  break;
6284
6520
  case "SimpleStatement":
6285
- if (ts[0] === head && isName(head) && head.v !== "next") mark(head, "command").name.text = syntaxSelector(element, head.v);
6521
+ if (ts()[0] === head && isName(head) && head.v !== "next") mark(head, "command").name.text = syntaxSelector(element, head.v);
6286
6522
  break;
6287
6523
  case "Send":
6288
6524
  case "Event": {
@@ -6299,7 +6535,7 @@ const checkSyntax = (syntax, options = {}) => {
6299
6535
  }
6300
6536
  case "AskTell":
6301
6537
  case "TellBlock": {
6302
- const target = ns.find((node) => node.rule === "Expression");
6538
+ const target = ns().find((node) => node.rule === "Expression");
6303
6539
  if (target) {
6304
6540
  let base = target;
6305
6541
  while (nodes(base).length === 1 && tokens(base).length === 0) base = nodes(base)[0];
@@ -6359,7 +6595,8 @@ const checkSyntax = (syntax, options = {}) => {
6359
6595
  const previous = binding.span;
6360
6596
  report("name clash", imported?.token ?? (previous && previous.start > site.token.pos ? firstTokenAt.get(previous.start) : site.token));
6361
6597
  };
6362
- const firstTokenAt = new Map(ordered.map((info) => info.element).filter((element) => element.kind === "token").map((token) => [token.pos, token]));
6598
+ let firstTokens;
6599
+ const firstTokenAt = { get: (pos) => (firstTokens ??= new Map(ordered.map((info) => info.element).filter((element) => element.kind === "token").map((token) => [token.pos, token]))).get(pos) };
6363
6600
  for (const { site, kind, importedFrom, contract } of declarationSites) {
6364
6601
  const old = unit.bindings.get(site.name.text);
6365
6602
  const handler = handlers.get(site.name.text);
@@ -6512,7 +6749,7 @@ const checkSyntax = (syntax, options = {}) => {
6512
6749
  }
6513
6750
  continue;
6514
6751
  }
6515
- if (isElementRead(element)) {
6752
+ if (isElementRead(element) || isCollectionWalk(element)) {
6516
6753
  report("not constant", context.get(element).first);
6517
6754
  return;
6518
6755
  }
@@ -6565,46 +6802,18 @@ const checkSyntax = (syntax, options = {}) => {
6565
6802
  if (expression) checkConstant(expression, head.pos);
6566
6803
  }
6567
6804
  }
6568
- for (let i = ordered.length - 1; i >= 0; i--) {
6569
- const info = ordered[i];
6570
- const { element } = info;
6571
- if (element.kind === "token") {
6572
- if (element.t === "nl" || element.t === "eof" || element.t === "error") continue;
6573
- info.converted = sites.get(element)?.name ?? {
6574
- kind: "token",
6575
- type: element.t,
6576
- text: element.v,
6577
- raw: element.raw,
6578
- span: span(element)
6579
- };
6580
- } else {
6581
- const { first: start, last: end } = info;
6582
- if (!start && element !== syntax) continue;
6583
- const children = [];
6584
- for (const child of element.children) {
6585
- const result = context.get(child).converted;
6586
- if (result) children.push(result);
6587
- }
6588
- info.converted = {
6589
- kind: "node",
6590
- rule: element.rule,
6591
- scope: info.scope.id,
6592
- children,
6593
- span: start ? {
6594
- start: start.pos,
6595
- end: end.end,
6596
- line: start.line,
6597
- col: start.col
6598
- } : {
6599
- start: element.start,
6600
- end: element.end,
6601
- line: 1,
6602
- col: 1
6603
- }
6604
- };
6605
- }
6805
+ for (let i = 0; i < slots.length; i++) {
6806
+ const children = slots[i];
6807
+ const token = slotTokens[i];
6808
+ children[slotIndexes[i]] = sites.get(token)?.name ?? {
6809
+ kind: "token",
6810
+ type: token.t,
6811
+ text: token.v,
6812
+ raw: token.raw,
6813
+ span: span(token)
6814
+ };
6606
6815
  }
6607
- const root = context.get(syntax).converted;
6816
+ const root = ordered[0].converted;
6608
6817
  const reportAt = (code, at) => diagnostics.push({
6609
6818
  code,
6610
6819
  span: at.span,
@@ -6641,17 +6850,17 @@ const checkSyntax = (syntax, options = {}) => {
6641
6850
  }
6642
6851
  };
6643
6852
  };
6644
- const checkSource = (source, options = {}) => {
6645
- const parsed = parseSource(source);
6646
- return parsed.error ? {
6647
- error: parsed.error,
6648
- tree: null,
6649
- ok: false,
6650
- diagnostics: []
6651
- } : {
6652
- error: null,
6653
- ...checkSyntax(parsed.tree, options)
6654
- };
6853
+ const checkParsedSource = (parsed, options) => parsed.error ? {
6854
+ error: parsed.error,
6855
+ tree: null,
6856
+ ok: false,
6857
+ diagnostics: []
6858
+ } : {
6859
+ error: null,
6860
+ ...checkParsed(parsed.tree, options)
6655
6861
  };
6862
+ const checkSource = (source, options = {}) => checkParsedSource(parseSource(source), options);
6863
+ /** Internal compilation path; public semantic trees retain all productions. */
6864
+ const checkSourceForLoad = (source, options = {}) => checkParsedSource(parseSourceForLoad(source), options);
6656
6865
  //#endregion
6657
- export { viewSource as _, ParseError as a, parseSourceRecovering as c, codeDoc as d, declarationDocs as f, checkDecisionCalls as g, leadingDoc as h, syntaxText as i, checkEffectCall as l, functionDoc as m, checkSyntax as n, parseEntry as o, declarationStart as p, syntaxSelector as r, parseSource as s, checkSource as t, operationUses as u };
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 };