@rohal12/spindle 0.62.1 → 0.62.3

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.
@@ -10,133 +10,6 @@ var __exportAll = (all, no_symbols) => {
10
10
  return target;
11
11
  };
12
12
  //#endregion
13
- //#region src/utils/macro-names.ts
14
- /**
15
- * Macro and widget names are case-insensitive: `{StatusBar}` invokes the
16
- * widget defined as `statusbar`. A NameMap keys its entries by the lowercased
17
- * name.
18
- */
19
- var NameMap = class extends Map {
20
- get(name) {
21
- return super.get(name.toLowerCase());
22
- }
23
- set(name, value) {
24
- return super.set(name.toLowerCase(), value);
25
- }
26
- has(name) {
27
- return super.has(name.toLowerCase());
28
- }
29
- delete(name) {
30
- return super.delete(name.toLowerCase());
31
- }
32
- };
33
- /** A set of macro or widget names (see NameMap). */
34
- var NameSet = class {
35
- constructor(names = []) {
36
- this.names = new NameMap();
37
- for (const name of names) this.add(name);
38
- }
39
- add(name) {
40
- this.names.set(name, true);
41
- }
42
- has(name) {
43
- return this.names.has(name);
44
- }
45
- delete(name) {
46
- this.names.delete(name);
47
- }
48
- clear() {
49
- this.names.clear();
50
- }
51
- };
52
- new NameMap();
53
- new NameMap();
54
- new NameSet();
55
- /**
56
- * How a macro argument is read (see components/macros/macro-args.ts). Every
57
- * declared parameter names one: there is no default.
58
- * Quoted strings accept `\"`, `\'` and `\\` escapes.
59
- * - `expression`: code, as written.
60
- * - `statements`: code run as statements (`{set}`), as written.
61
- * - `passage`: a passage name: a quoted string or an expression, as written.
62
- * - `variable`: a variable reference such as `$name` or `"$name"`, as written.
63
- * - `string`: one quoted string; anything else leaves the argument unset.
64
- * - `text`: one quoted string, or text with any loose quotes stripped.
65
- * - `names`: a comma-separated list of names (`@item, @i`).
66
- * - `delay`: a duration (`2s`, `500ms`, `300`) in milliseconds.
67
- * - `number`: a number.
68
- * - `flag`: a keyword, the parameter's name, at the start or end; a boolean.
69
- * - `separator`: a word (`of`) or `=` separating the parameters before it
70
- * from those after it; a boolean.
71
- * - `options`: keywords, the names of its `parameters`, each followed by a
72
- * quoted string or a number unless it is a flag.
73
- */
74
- var PARAMETER_TYPES = [
75
- "expression",
76
- "statements",
77
- "passage",
78
- "variable",
79
- "string",
80
- "text",
81
- "names",
82
- "delay",
83
- "number",
84
- "flag",
85
- "separator",
86
- "options"
87
- ];
88
- /**
89
- * What the value of a `string` or `text` argument holds, for the check at
90
- * story start and for tooling (see code-check.ts):
91
- * - `markup`: markup the macro renders (`{button}`'s label): its markup
92
- * is checked.
93
- * - `text`: plain text the macro uses as written (`{checkbox}`'s label).
94
- * - `passage`: a passage name (`{watch}`'s `goto`): the passage must exist.
95
- * - `expression`, `statements`: code (`{watch}`'s condition and `run`): it
96
- * is checked as code, and its variable references against the schema.
97
- *
98
- * Without it, the argument of a macro with `interpolate` holds `markup`,
99
- * any other `text`.
100
- */
101
- var STRING_HOLDS = [
102
- "markup",
103
- "text",
104
- "passage",
105
- "expression",
106
- "statements"
107
- ];
108
- /**
109
- * Throw if a parameter `macro` declares (or an option of one) has no type,
110
- * or one that isn't a ParameterType: arguments are read by their type, and
111
- * there is no default. Throw too if it declares what it `holds` wrongly.
112
- */
113
- function checkParameterTypes(macro, parameters) {
114
- const holdsFix = `Give a \`string\` or \`text\` parameter one of ${STRING_HOLDS.join(", ")} to hold (see docs/custom-macros.md#what-a-string-holds).`;
115
- for (const param of parameters) {
116
- const type = param.type;
117
- if (!PARAMETER_TYPES.includes(type)) throw parameterError(macro, param, type === void 0 ? "has no type" : `has the unknown type ${JSON.stringify(type)}`, `Give it one of the types ${PARAMETER_TYPES.join(", ")} (see docs/custom-macros.md#parameter-types), or declare no parameters and read props.rawArgs.`);
118
- const holds = param.holds;
119
- if (holds !== void 0 && type !== "string" && type !== "text") throw parameterError(macro, param, `is of the type ${type}, which holds what it is`, holdsFix);
120
- if (holds !== void 0 && !STRING_HOLDS.includes(holds)) throw parameterError(macro, param, `holds the unknown ${JSON.stringify(holds)}`, holdsFix);
121
- if (param.parameters) checkParameterTypes(macro, param.parameters);
122
- }
123
- }
124
- /** The error for the parameter `param` of `macro`: what is wrong, and the fix. */
125
- function parameterError(macro, param, problem, fix) {
126
- return /* @__PURE__ */ new Error(`spindle: The parameter "${param.name}" of the macro {${macro}} ${problem}. ${fix}`);
127
- }
128
- var metadataRegistry = new NameMap();
129
- /** Indexed at registration, so parsing each tag does not scan every macro. */
130
- var companionParents = new NameMap();
131
- /** The parents declaring a branching companion (listbox options are values). */
132
- function branchParents(name, macros) {
133
- if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent !== "listbox");
134
- return macros.filter((macro) => macro.name.toLowerCase() !== "listbox" && macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase())).map((macro) => macro.name.toLowerCase());
135
- }
136
- function getMacroRegistry() {
137
- return Array.from(metadataRegistry.values());
138
- }
139
- //#endregion
140
13
  //#region src/markup/tokens.ts
141
14
  /** Variable sigils: story ($), temporary (_), local (@), transient (%). */
142
15
  var SIGIL_SCOPES = {
@@ -764,23 +637,29 @@ function peg$parse(input, options) {
764
637
  return [body ? lexeme("text", loc, { value: body }) : null, end];
765
638
  }
766
639
  function peg$f16() {
640
+ return completionMode;
641
+ }
642
+ function peg$f17(body) {
643
+ return lexeme("text", location(), { value: body });
644
+ }
645
+ function peg$f18() {
767
646
  return offset();
768
647
  }
769
- function peg$f17(value) {
648
+ function peg$f19(value) {
770
649
  return lexeme("text", location(), { value });
771
650
  }
772
- function peg$f18(value) {
651
+ function peg$f20(value) {
773
652
  const node = lexeme("text", location(), { value });
774
653
  node.comment = true;
775
654
  return node;
776
655
  }
777
- function peg$f19(bs) {
656
+ function peg$f21(bs) {
778
657
  return bs.length % 2 === 1;
779
658
  }
780
- function peg$f20(bs, c) {
659
+ function peg$f22(bs, c) {
781
660
  return c;
782
661
  }
783
- function peg$f21(bs, brace) {
662
+ function peg$f23(bs, brace) {
784
663
  const loc = location();
785
664
  const next = input.charAt(loc.end.offset);
786
665
  if (textMode) {
@@ -797,48 +676,48 @@ function peg$parse(input, options) {
797
676
  escaped.escape = true;
798
677
  return bs.length > 1 ? [before, escaped] : escaped;
799
678
  }
800
- function peg$f22() {
679
+ function peg$f24() {
801
680
  return lexeme("text", location(), { value: LB });
802
681
  }
803
- function peg$f23() {
682
+ function peg$f25() {
804
683
  return !textMode;
805
684
  }
806
- function peg$f24() {
685
+ function peg$f26() {
807
686
  return lexeme("text", location(), { value: "<" });
808
687
  }
809
- function peg$f25() {
688
+ function peg$f27() {
810
689
  return lexeme("text", location(), { value: "[" });
811
690
  }
812
- function peg$f26() {
691
+ function peg$f28() {
813
692
  return !textMode;
814
693
  }
815
- function peg$f27(ss, s, at, inner) {
694
+ function peg$f29(ss, s, at, inner) {
816
695
  const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
817
696
  link.selectorSpan = selectorSpan(s, ss, at);
818
697
  return withSelectors(link, s);
819
698
  }
820
- function peg$f28() {
699
+ function peg$f30() {
821
700
  return !textMode;
822
701
  }
823
- function peg$f29() {
702
+ function peg$f31() {
824
703
  fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
825
704
  }
826
- function peg$f30(parts) {
705
+ function peg$f32(parts) {
827
706
  return selectorsOf(parts);
828
707
  }
829
- function peg$f31() {
708
+ function peg$f33() {
830
709
  return NO_SELECTORS;
831
710
  }
832
- function peg$f32(s, end) {
711
+ function peg$f34(s, end) {
833
712
  return {
834
713
  ...s,
835
714
  end
836
715
  };
837
716
  }
838
- function peg$f33(prefix, name) {
717
+ function peg$f35(prefix, name) {
839
718
  return [prefix, name];
840
719
  }
841
- function peg$f34(ss, s, sigil, nameStart, name) {
720
+ function peg$f36(ss, s, sigil, nameStart, name) {
842
721
  const variable = lexeme("variable", location(), {
843
722
  name,
844
723
  nameStart,
@@ -848,7 +727,7 @@ function peg$parse(input, options) {
848
727
  variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
849
728
  return withSelectors(variable, s);
850
729
  }
851
- function peg$f35(ss, s, after, expression) {
730
+ function peg$f37(ss, s, after, expression) {
852
731
  const node = lexeme("expression", location(), {
853
732
  expression,
854
733
  expressionStart: after,
@@ -857,28 +736,33 @@ function peg$parse(input, options) {
857
736
  node.selectorSpan = selectorSpan(s, ss, after);
858
737
  return withSelectors(node, s);
859
738
  }
860
- function peg$f36() {
739
+ function peg$f38() {
861
740
  fail("Unclosed {" + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
862
741
  }
863
- function peg$f37(start) {
864
- return skipTo(hooks.closeBrace(input, start, start));
742
+ function peg$f39(start) {
743
+ const end = hooks.closeBrace(input, start, start);
744
+ return skipTo(end < 0 && completionMode ? input.length : end);
865
745
  }
866
- function peg$f38(start) {
746
+ function peg$f40(start) {
867
747
  return skipEnd - offset();
868
748
  }
869
- function peg$f39(start, code) {
749
+ function peg$f41(start, code) {
870
750
  return code;
871
751
  }
872
- function peg$f40(ss, s, start, close, name, nameEnd) {
873
- return skipTo(hooks.closeBrace(input, nameEnd, start));
752
+ function peg$f42() {
753
+ return completionMode;
754
+ }
755
+ function peg$f43(ss, s, start, close, name, nameEnd) {
756
+ const end = hooks.closeBrace(input, nameEnd, start);
757
+ return skipTo(end < 0 && completionMode ? input.length : end);
874
758
  }
875
- function peg$f41(ss, s, start, close, name, nameEnd) {
759
+ function peg$f44(ss, s, start, close, name, nameEnd) {
876
760
  return skipEnd - offset();
877
761
  }
878
- function peg$f42(ss, s, start, close, name, nameEnd, args) {
762
+ function peg$f45(ss, s, start, close, name, nameEnd, args) {
879
763
  return args;
880
764
  }
881
- function peg$f43(ss, s, start, close, name, nameEnd, tail) {
765
+ function peg$f46(ss, s, start, close, name, nameEnd, tail) {
882
766
  const loc = location();
883
767
  const lower = name.toLowerCase();
884
768
  const tag = lexeme("macro", loc, {
@@ -891,7 +775,7 @@ function peg$parse(input, options) {
891
775
  tag.nameEnd = nameEnd;
892
776
  tag.selectorSpan = selectorSpan(s, ss, start);
893
777
  if (tail === null) fail("Unclosed {" + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
894
- tag.rawArgs = tail.trim();
778
+ tag.rawArgs = completionMode ? tail.trimStart() : tail.trim();
895
779
  tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
896
780
  tag.argsEnd = tag.argsStart + tag.rawArgs.length;
897
781
  if (close) {
@@ -904,19 +788,19 @@ function peg$parse(input, options) {
904
788
  }
905
789
  return tag;
906
790
  }
907
- function peg$f44(s) {
791
+ function peg$f47(s) {
908
792
  fail("A closing tag starts with a letter after {/", location(), "invalid-closer");
909
793
  }
910
- function peg$f45(value) {
794
+ function peg$f48(value) {
911
795
  return EMAIL_AUTOLINK.test(value);
912
796
  }
913
- function peg$f46(value) {
797
+ function peg$f49(value) {
914
798
  return lexeme("text", location(), { value });
915
799
  }
916
- function peg$f47(value) {
800
+ function peg$f50(value) {
917
801
  return lexeme("text", location(), { value });
918
802
  }
919
- function peg$f48(tagStart, tag, list, slash) {
803
+ function peg$f51(tagStart, tag, list, slash) {
920
804
  const lower = tag.toLowerCase();
921
805
  return lexeme("html", location(), {
922
806
  tag,
@@ -929,7 +813,7 @@ function peg$parse(input, options) {
929
813
  isSelfClose: !!slash || VOID_TAGS.has(lower)
930
814
  });
931
815
  }
932
- function peg$f49(tag, bad) {
816
+ function peg$f52(tag, bad) {
933
817
  const c = input.charAt(bad);
934
818
  if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
935
819
  const at = {
@@ -947,7 +831,7 @@ function peg$parse(input, options) {
947
831
  };
948
832
  fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
949
833
  }
950
- function peg$f50(tagStart, tag) {
834
+ function peg$f53(tagStart, tag) {
951
835
  return lexeme("html", location(), {
952
836
  tag,
953
837
  lower: tag.toLowerCase(),
@@ -959,14 +843,14 @@ function peg$parse(input, options) {
959
843
  isSelfClose: false
960
844
  });
961
845
  }
962
- function peg$f51(nameStart, name) {
846
+ function peg$f54(nameStart, name) {
963
847
  attrCode = hooks.isCodeAttribute(name);
964
848
  return true;
965
849
  }
966
- function peg$f52(nameStart, name, v) {
850
+ function peg$f55(nameStart, name, v) {
967
851
  return v;
968
852
  }
969
- function peg$f53(nameStart, name, value) {
853
+ function peg$f56(nameStart, name, value) {
970
854
  const attribute = {
971
855
  name,
972
856
  value: value ? value.value : "",
@@ -980,7 +864,7 @@ function peg$parse(input, options) {
980
864
  }
981
865
  return attribute;
982
866
  }
983
- function peg$f54(start, value, end) {
867
+ function peg$f57(start, value, end) {
984
868
  return {
985
869
  value,
986
870
  start,
@@ -988,7 +872,7 @@ function peg$parse(input, options) {
988
872
  quote: "\""
989
873
  };
990
874
  }
991
- function peg$f55(start, value, end) {
875
+ function peg$f58(start, value, end) {
992
876
  return {
993
877
  value,
994
878
  start,
@@ -996,35 +880,36 @@ function peg$parse(input, options) {
996
880
  quote: "'"
997
881
  };
998
882
  }
999
- function peg$f56(q) {
883
+ function peg$f59(q) {
1000
884
  fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
1001
885
  }
1002
- function peg$f57(start, value, end) {
886
+ function peg$f60(start, value, end) {
1003
887
  return {
1004
888
  value,
1005
889
  start,
1006
890
  end
1007
891
  };
1008
892
  }
1009
- function peg$f58() {
893
+ function peg$f61() {
1010
894
  return !attrCode;
1011
895
  }
1012
- function peg$f59(bs) {
896
+ function peg$f62(bs) {
1013
897
  return bs.length % 2 === 1;
1014
898
  }
1015
- function peg$f60() {
899
+ function peg$f63() {
1016
900
  return !attrCode;
1017
901
  }
1018
- function peg$f61(start, nameEnd) {
1019
- return skipTo(hooks.closeBrace(input, nameEnd, start));
902
+ function peg$f64(start, nameEnd) {
903
+ const end = hooks.closeBrace(input, nameEnd, start);
904
+ return skipTo(end < 0 && completionMode ? input.length : end);
1020
905
  }
1021
- function peg$f62(start, nameEnd) {
906
+ function peg$f65(start, nameEnd) {
1022
907
  return skipEnd - offset();
1023
908
  }
1024
- function peg$f63() {
909
+ function peg$f66() {
1025
910
  return !attrCode;
1026
911
  }
1027
- function peg$f64() {
912
+ function peg$f67() {
1028
913
  return attrCode;
1029
914
  }
1030
915
  let peg$currPos = options.peg$currPos | 0;
@@ -1363,6 +1248,40 @@ function peg$parse(input, options) {
1363
1248
  peg$currPos = s0;
1364
1249
  s0 = peg$FAILED;
1365
1250
  }
1251
+ if (s0 === peg$FAILED) {
1252
+ s0 = peg$currPos;
1253
+ peg$savedPos = peg$currPos;
1254
+ s1 = peg$f16();
1255
+ if (s1) s1 = void 0;
1256
+ else s1 = peg$FAILED;
1257
+ if (s1 !== peg$FAILED) {
1258
+ s2 = peg$currPos;
1259
+ s3 = [];
1260
+ if (input.length > peg$currPos) {
1261
+ s4 = input.charAt(peg$currPos);
1262
+ peg$currPos++;
1263
+ } else {
1264
+ s4 = peg$FAILED;
1265
+ if (peg$silentFails === 0) peg$fail(peg$e0);
1266
+ }
1267
+ while (s4 !== peg$FAILED) {
1268
+ s3.push(s4);
1269
+ if (input.length > peg$currPos) {
1270
+ s4 = input.charAt(peg$currPos);
1271
+ peg$currPos++;
1272
+ } else {
1273
+ s4 = peg$FAILED;
1274
+ if (peg$silentFails === 0) peg$fail(peg$e0);
1275
+ }
1276
+ }
1277
+ s2 = input.substring(s2, peg$currPos);
1278
+ peg$savedPos = s0;
1279
+ s0 = peg$f17(s2);
1280
+ } else {
1281
+ peg$currPos = s0;
1282
+ s0 = peg$FAILED;
1283
+ }
1284
+ }
1366
1285
  return s0;
1367
1286
  }
1368
1287
  function peg$parseHere() {
@@ -1370,7 +1289,7 @@ function peg$parse(input, options) {
1370
1289
  s0 = peg$currPos;
1371
1290
  s1 = "";
1372
1291
  peg$savedPos = s0;
1373
- s1 = peg$f16();
1292
+ s1 = peg$f18();
1374
1293
  s0 = s1;
1375
1294
  return s0;
1376
1295
  }
@@ -1399,7 +1318,7 @@ function peg$parse(input, options) {
1399
1318
  else s1 = s2;
1400
1319
  if (s1 !== peg$FAILED) {
1401
1320
  peg$savedPos = s0;
1402
- s1 = peg$f17(s1);
1321
+ s1 = peg$f19(s1);
1403
1322
  }
1404
1323
  s0 = s1;
1405
1324
  return s0;
@@ -1515,6 +1434,7 @@ function peg$parse(input, options) {
1515
1434
  s6 = peg$FAILED;
1516
1435
  if (peg$silentFails === 0) peg$fail(peg$e5);
1517
1436
  }
1437
+ if (s6 === peg$FAILED) s6 = peg$parseOpenEnd();
1518
1438
  if (s6 !== peg$FAILED) {
1519
1439
  s5 = [s5, s6];
1520
1440
  s4 = s5;
@@ -1539,7 +1459,7 @@ function peg$parse(input, options) {
1539
1459
  else s1 = s2;
1540
1460
  if (s1 !== peg$FAILED) {
1541
1461
  peg$savedPos = s0;
1542
- s1 = peg$f18(s1);
1462
+ s1 = peg$f20(s1);
1543
1463
  }
1544
1464
  s0 = s1;
1545
1465
  return s0;
@@ -1572,7 +1492,7 @@ function peg$parse(input, options) {
1572
1492
  if (s1 !== peg$FAILED) {
1573
1493
  s2 = peg$currPos;
1574
1494
  peg$savedPos = peg$currPos;
1575
- s3 = peg$f19(s1);
1495
+ s3 = peg$f21(s1);
1576
1496
  if (s3) s3 = void 0;
1577
1497
  else s3 = peg$FAILED;
1578
1498
  if (s3 !== peg$FAILED) {
@@ -1584,7 +1504,7 @@ function peg$parse(input, options) {
1584
1504
  }
1585
1505
  if (s4 !== peg$FAILED) {
1586
1506
  peg$savedPos = s2;
1587
- s2 = peg$f20(s1, s4);
1507
+ s2 = peg$f22(s1, s4);
1588
1508
  } else {
1589
1509
  peg$currPos = s2;
1590
1510
  s2 = peg$FAILED;
@@ -1595,7 +1515,7 @@ function peg$parse(input, options) {
1595
1515
  }
1596
1516
  if (s2 === peg$FAILED) s2 = null;
1597
1517
  peg$savedPos = s0;
1598
- s0 = peg$f21(s1, s2);
1518
+ s0 = peg$f23(s1, s2);
1599
1519
  } else {
1600
1520
  peg$currPos = s0;
1601
1521
  s0 = peg$FAILED;
@@ -1643,7 +1563,7 @@ function peg$parse(input, options) {
1643
1563
  }
1644
1564
  if (s2 !== peg$FAILED) {
1645
1565
  peg$savedPos = s0;
1646
- s0 = peg$f22();
1566
+ s0 = peg$f24();
1647
1567
  } else {
1648
1568
  peg$currPos = s0;
1649
1569
  s0 = peg$FAILED;
@@ -1658,7 +1578,7 @@ function peg$parse(input, options) {
1658
1578
  peg$silentFails++;
1659
1579
  s2 = peg$currPos;
1660
1580
  peg$savedPos = peg$currPos;
1661
- s3 = peg$f23();
1581
+ s3 = peg$f25();
1662
1582
  if (s3) s3 = void 0;
1663
1583
  else s3 = peg$FAILED;
1664
1584
  if (s3 !== peg$FAILED) {
@@ -1690,7 +1610,7 @@ function peg$parse(input, options) {
1690
1610
  }
1691
1611
  if (s2 !== peg$FAILED) {
1692
1612
  peg$savedPos = s0;
1693
- s0 = peg$f24();
1613
+ s0 = peg$f26();
1694
1614
  } else {
1695
1615
  peg$currPos = s0;
1696
1616
  s0 = peg$FAILED;
@@ -1710,7 +1630,7 @@ function peg$parse(input, options) {
1710
1630
  }
1711
1631
  if (s1 !== peg$FAILED) {
1712
1632
  peg$savedPos = s0;
1713
- s1 = peg$f25();
1633
+ s1 = peg$f27();
1714
1634
  }
1715
1635
  s0 = s1;
1716
1636
  }
@@ -1721,7 +1641,7 @@ function peg$parse(input, options) {
1721
1641
  let s0, s1, s2, s3, s4, s5, s6, s7;
1722
1642
  s0 = peg$currPos;
1723
1643
  peg$savedPos = peg$currPos;
1724
- s1 = peg$f26();
1644
+ s1 = peg$f28();
1725
1645
  if (s1) s1 = void 0;
1726
1646
  else s1 = peg$FAILED;
1727
1647
  if (s1 !== peg$FAILED) {
@@ -1747,9 +1667,10 @@ function peg$parse(input, options) {
1747
1667
  s7 = peg$FAILED;
1748
1668
  if (peg$silentFails === 0) peg$fail(peg$e13);
1749
1669
  }
1670
+ if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
1750
1671
  if (s7 !== peg$FAILED) {
1751
1672
  peg$savedPos = s0;
1752
- s0 = peg$f27(s3, s4, s5, s6);
1673
+ s0 = peg$f29(s3, s4, s5, s6);
1753
1674
  } else {
1754
1675
  peg$currPos = s0;
1755
1676
  s0 = peg$FAILED;
@@ -1769,7 +1690,7 @@ function peg$parse(input, options) {
1769
1690
  if (s0 === peg$FAILED) {
1770
1691
  s0 = peg$currPos;
1771
1692
  peg$savedPos = peg$currPos;
1772
- s1 = peg$f28();
1693
+ s1 = peg$f30();
1773
1694
  if (s1) s1 = void 0;
1774
1695
  else s1 = peg$FAILED;
1775
1696
  if (s1 !== peg$FAILED) {
@@ -1782,7 +1703,7 @@ function peg$parse(input, options) {
1782
1703
  }
1783
1704
  if (s2 !== peg$FAILED) {
1784
1705
  peg$savedPos = s0;
1785
- s0 = peg$f29();
1706
+ s0 = peg$f31();
1786
1707
  } else {
1787
1708
  peg$currPos = s0;
1788
1709
  s0 = peg$FAILED;
@@ -1910,7 +1831,7 @@ function peg$parse(input, options) {
1910
1831
  }
1911
1832
  if (s2 === peg$FAILED) s2 = null;
1912
1833
  peg$savedPos = s0;
1913
- s0 = peg$f30(s1);
1834
+ s0 = peg$f32(s1);
1914
1835
  } else {
1915
1836
  peg$currPos = s0;
1916
1837
  s0 = peg$FAILED;
@@ -1919,7 +1840,7 @@ function peg$parse(input, options) {
1919
1840
  s0 = peg$currPos;
1920
1841
  s1 = "";
1921
1842
  peg$savedPos = s0;
1922
- s1 = peg$f31();
1843
+ s1 = peg$f33();
1923
1844
  s0 = s1;
1924
1845
  }
1925
1846
  return s0;
@@ -1949,7 +1870,7 @@ function peg$parse(input, options) {
1949
1870
  }
1950
1871
  }
1951
1872
  peg$savedPos = s0;
1952
- s0 = peg$f32(s1, s2);
1873
+ s0 = peg$f34(s1, s2);
1953
1874
  } else {
1954
1875
  peg$currPos = s0;
1955
1876
  s0 = peg$FAILED;
@@ -1975,7 +1896,7 @@ function peg$parse(input, options) {
1975
1896
  }
1976
1897
  s2 = input.substring(s2, peg$currPos);
1977
1898
  peg$savedPos = s0;
1978
- s0 = peg$f33(s1, s2);
1899
+ s0 = peg$f35(s1, s2);
1979
1900
  } else {
1980
1901
  peg$currPos = s0;
1981
1902
  s0 = peg$FAILED;
@@ -2093,16 +2014,10 @@ function peg$parse(input, options) {
2093
2014
  }
2094
2015
  }
2095
2016
  s6 = input.substring(s6, peg$currPos);
2096
- if (input.charCodeAt(peg$currPos) === 125) {
2097
- s7 = peg$c11;
2098
- peg$currPos++;
2099
- } else {
2100
- s7 = peg$FAILED;
2101
- if (peg$silentFails === 0) peg$fail(peg$e19);
2102
- }
2017
+ s7 = peg$parseBraceEnd();
2103
2018
  if (s7 !== peg$FAILED) {
2104
2019
  peg$savedPos = s0;
2105
- s0 = peg$f34(s2, s3, s4, s5, s6);
2020
+ s0 = peg$f36(s2, s3, s4, s5, s6);
2106
2021
  } else {
2107
2022
  peg$currPos = s0;
2108
2023
  s0 = peg$FAILED;
@@ -2149,16 +2064,10 @@ function peg$parse(input, options) {
2149
2064
  if (s5 !== peg$FAILED) {
2150
2065
  s6 = peg$parseCodeToBrace();
2151
2066
  if (s6 !== peg$FAILED) {
2152
- if (input.charCodeAt(peg$currPos) === 125) {
2153
- s7 = peg$c11;
2154
- peg$currPos++;
2155
- } else {
2156
- s7 = peg$FAILED;
2157
- if (peg$silentFails === 0) peg$fail(peg$e19);
2158
- }
2067
+ s7 = peg$parseBraceEnd();
2159
2068
  if (s7 !== peg$FAILED) {
2160
2069
  peg$savedPos = s0;
2161
- s0 = peg$f35(s2, s3, s4, s6);
2070
+ s0 = peg$f37(s2, s3, s4, s6);
2162
2071
  } else {
2163
2072
  peg$currPos = s0;
2164
2073
  s0 = peg$FAILED;
@@ -2206,7 +2115,7 @@ function peg$parse(input, options) {
2206
2115
  } else s3 = peg$FAILED;
2207
2116
  if (s3 !== peg$FAILED) {
2208
2117
  peg$savedPos = s0;
2209
- s0 = peg$f36();
2118
+ s0 = peg$f38();
2210
2119
  } else {
2211
2120
  peg$currPos = s0;
2212
2121
  s0 = peg$FAILED;
@@ -2228,12 +2137,12 @@ function peg$parse(input, options) {
2228
2137
  s0 = peg$currPos;
2229
2138
  s1 = peg$parseHere();
2230
2139
  peg$savedPos = peg$currPos;
2231
- s2 = peg$f37(s1);
2140
+ s2 = peg$f39(s1);
2232
2141
  if (s2) s2 = void 0;
2233
2142
  else s2 = peg$FAILED;
2234
2143
  if (s2 !== peg$FAILED) {
2235
2144
  s3 = peg$currPos;
2236
- s4 = peg$f38(s1);
2145
+ s4 = peg$f40(s1);
2237
2146
  s5 = peg$currPos;
2238
2147
  s6 = [];
2239
2148
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -2264,7 +2173,7 @@ function peg$parse(input, options) {
2264
2173
  else s3 = s4;
2265
2174
  if (s3 !== peg$FAILED) {
2266
2175
  peg$savedPos = s0;
2267
- s0 = peg$f39(s1, s3);
2176
+ s0 = peg$f41(s1, s3);
2268
2177
  } else {
2269
2178
  peg$currPos = s0;
2270
2179
  s0 = peg$FAILED;
@@ -2275,6 +2184,54 @@ function peg$parse(input, options) {
2275
2184
  }
2276
2185
  return s0;
2277
2186
  }
2187
+ function peg$parseOpenEnd() {
2188
+ let s0, s1, s2, s3;
2189
+ s0 = peg$currPos;
2190
+ peg$savedPos = peg$currPos;
2191
+ s1 = peg$f42();
2192
+ if (s1) s1 = void 0;
2193
+ else s1 = peg$FAILED;
2194
+ if (s1 !== peg$FAILED) {
2195
+ s2 = peg$currPos;
2196
+ peg$silentFails++;
2197
+ if (input.length > peg$currPos) {
2198
+ s3 = input.charAt(peg$currPos);
2199
+ peg$currPos++;
2200
+ } else {
2201
+ s3 = peg$FAILED;
2202
+ if (peg$silentFails === 0) peg$fail(peg$e0);
2203
+ }
2204
+ peg$silentFails--;
2205
+ if (s3 === peg$FAILED) s2 = void 0;
2206
+ else {
2207
+ peg$currPos = s2;
2208
+ s2 = peg$FAILED;
2209
+ }
2210
+ if (s2 !== peg$FAILED) {
2211
+ s1 = [s1, s2];
2212
+ s0 = s1;
2213
+ } else {
2214
+ peg$currPos = s0;
2215
+ s0 = peg$FAILED;
2216
+ }
2217
+ } else {
2218
+ peg$currPos = s0;
2219
+ s0 = peg$FAILED;
2220
+ }
2221
+ return s0;
2222
+ }
2223
+ function peg$parseBraceEnd() {
2224
+ let s0;
2225
+ if (input.charCodeAt(peg$currPos) === 125) {
2226
+ s0 = peg$c11;
2227
+ peg$currPos++;
2228
+ } else {
2229
+ s0 = peg$FAILED;
2230
+ if (peg$silentFails === 0) peg$fail(peg$e19);
2231
+ }
2232
+ if (s0 === peg$FAILED) s0 = peg$parseOpenEnd();
2233
+ return s0;
2234
+ }
2278
2235
  function peg$parseMacroTag() {
2279
2236
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
2280
2237
  s0 = peg$currPos;
@@ -2303,12 +2260,12 @@ function peg$parse(input, options) {
2303
2260
  s7 = peg$parseHere();
2304
2261
  s8 = peg$currPos;
2305
2262
  peg$savedPos = peg$currPos;
2306
- s9 = peg$f40(s2, s3, s4, s5, s6, s7);
2263
+ s9 = peg$f43(s2, s3, s4, s5, s6, s7);
2307
2264
  if (s9) s9 = void 0;
2308
2265
  else s9 = peg$FAILED;
2309
2266
  if (s9 !== peg$FAILED) {
2310
2267
  s10 = peg$currPos;
2311
- s11 = peg$f41(s2, s3, s4, s5, s6, s7);
2268
+ s11 = peg$f44(s2, s3, s4, s5, s6, s7);
2312
2269
  s12 = peg$currPos;
2313
2270
  s13 = [];
2314
2271
  if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
@@ -2338,16 +2295,10 @@ function peg$parse(input, options) {
2338
2295
  if (s11 !== peg$FAILED) s10 = input.substring(s10, peg$currPos);
2339
2296
  else s10 = s11;
2340
2297
  if (s10 !== peg$FAILED) {
2341
- if (input.charCodeAt(peg$currPos) === 125) {
2342
- s11 = peg$c11;
2343
- peg$currPos++;
2344
- } else {
2345
- s11 = peg$FAILED;
2346
- if (peg$silentFails === 0) peg$fail(peg$e19);
2347
- }
2298
+ s11 = peg$parseBraceEnd();
2348
2299
  if (s11 !== peg$FAILED) {
2349
2300
  peg$savedPos = s8;
2350
- s8 = peg$f42(s2, s3, s4, s5, s6, s7, s10);
2301
+ s8 = peg$f45(s2, s3, s4, s5, s6, s7, s10);
2351
2302
  } else {
2352
2303
  peg$currPos = s8;
2353
2304
  s8 = peg$FAILED;
@@ -2362,7 +2313,7 @@ function peg$parse(input, options) {
2362
2313
  }
2363
2314
  if (s8 === peg$FAILED) s8 = null;
2364
2315
  peg$savedPos = s0;
2365
- s0 = peg$f43(s2, s3, s4, s5, s6, s7, s8);
2316
+ s0 = peg$f46(s2, s3, s4, s5, s6, s7, s8);
2366
2317
  } else {
2367
2318
  peg$currPos = s0;
2368
2319
  s0 = peg$FAILED;
@@ -2396,7 +2347,7 @@ function peg$parse(input, options) {
2396
2347
  }
2397
2348
  if (s3 !== peg$FAILED) {
2398
2349
  peg$savedPos = s0;
2399
- s0 = peg$f44(s2);
2350
+ s0 = peg$f47(s2);
2400
2351
  } else {
2401
2352
  peg$currPos = s0;
2402
2353
  s0 = peg$FAILED;
@@ -2546,12 +2497,12 @@ function peg$parse(input, options) {
2546
2497
  else s1 = s2;
2547
2498
  if (s1 !== peg$FAILED) {
2548
2499
  peg$savedPos = peg$currPos;
2549
- s2 = peg$f45(s1);
2500
+ s2 = peg$f48(s1);
2550
2501
  if (s2) s2 = void 0;
2551
2502
  else s2 = peg$FAILED;
2552
2503
  if (s2 !== peg$FAILED) {
2553
2504
  peg$savedPos = s0;
2554
- s0 = peg$f46(s1);
2505
+ s0 = peg$f49(s1);
2555
2506
  } else {
2556
2507
  peg$currPos = s0;
2557
2508
  s0 = peg$FAILED;
@@ -2728,7 +2679,7 @@ function peg$parse(input, options) {
2728
2679
  else s1 = s2;
2729
2680
  if (s1 !== peg$FAILED) {
2730
2681
  peg$savedPos = s0;
2731
- s1 = peg$f47(s1);
2682
+ s1 = peg$f50(s1);
2732
2683
  }
2733
2684
  s0 = s1;
2734
2685
  return s0;
@@ -2769,9 +2720,10 @@ function peg$parse(input, options) {
2769
2720
  s7 = peg$FAILED;
2770
2721
  if (peg$silentFails === 0) peg$fail(peg$e3);
2771
2722
  }
2723
+ if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
2772
2724
  if (s7 !== peg$FAILED) {
2773
2725
  peg$savedPos = s0;
2774
- s0 = peg$f48(s2, s3, s4, s6);
2726
+ s0 = peg$f51(s2, s3, s4, s6);
2775
2727
  } else {
2776
2728
  peg$currPos = s0;
2777
2729
  s0 = peg$FAILED;
@@ -2836,7 +2788,7 @@ function peg$parse(input, options) {
2836
2788
  s5 = peg$parse_();
2837
2789
  s6 = peg$parseHere();
2838
2790
  peg$savedPos = s0;
2839
- s0 = peg$f49(s2, s6);
2791
+ s0 = peg$f52(s2, s6);
2840
2792
  } else {
2841
2793
  peg$currPos = s0;
2842
2794
  s0 = peg$FAILED;
@@ -2876,7 +2828,7 @@ function peg$parse(input, options) {
2876
2828
  }
2877
2829
  if (s5 !== peg$FAILED) {
2878
2830
  peg$savedPos = s0;
2879
- s0 = peg$f50(s2, s3);
2831
+ s0 = peg$f53(s2, s3);
2880
2832
  } else {
2881
2833
  peg$currPos = s0;
2882
2834
  s0 = peg$FAILED;
@@ -3011,7 +2963,7 @@ function peg$parse(input, options) {
3011
2963
  else s3 = s4;
3012
2964
  if (s3 !== peg$FAILED) {
3013
2965
  peg$savedPos = peg$currPos;
3014
- s4 = peg$f51(s2, s3);
2966
+ s4 = peg$f54(s2, s3);
3015
2967
  if (s4) s4 = void 0;
3016
2968
  else s4 = peg$FAILED;
3017
2969
  if (s4 !== peg$FAILED) {
@@ -3029,7 +2981,7 @@ function peg$parse(input, options) {
3029
2981
  s9 = peg$parseAttrValue();
3030
2982
  if (s9 !== peg$FAILED) {
3031
2983
  peg$savedPos = s5;
3032
- s5 = peg$f52(s2, s3, s9);
2984
+ s5 = peg$f55(s2, s3, s9);
3033
2985
  } else {
3034
2986
  peg$currPos = s5;
3035
2987
  s5 = peg$FAILED;
@@ -3040,7 +2992,7 @@ function peg$parse(input, options) {
3040
2992
  }
3041
2993
  if (s5 === peg$FAILED) s5 = null;
3042
2994
  peg$savedPos = s0;
3043
- s0 = peg$f53(s2, s3, s5);
2995
+ s0 = peg$f56(s2, s3, s5);
3044
2996
  } else {
3045
2997
  peg$currPos = s0;
3046
2998
  s0 = peg$FAILED;
@@ -3095,9 +3047,10 @@ function peg$parse(input, options) {
3095
3047
  s5 = peg$FAILED;
3096
3048
  if (peg$silentFails === 0) peg$fail(peg$e35);
3097
3049
  }
3050
+ if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
3098
3051
  if (s5 !== peg$FAILED) {
3099
3052
  peg$savedPos = s0;
3100
- s0 = peg$f54(s2, s3, s4);
3053
+ s0 = peg$f57(s2, s3, s4);
3101
3054
  } else {
3102
3055
  peg$currPos = s0;
3103
3056
  s0 = peg$FAILED;
@@ -3149,9 +3102,10 @@ function peg$parse(input, options) {
3149
3102
  s5 = peg$FAILED;
3150
3103
  if (peg$silentFails === 0) peg$fail(peg$e37);
3151
3104
  }
3105
+ if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
3152
3106
  if (s5 !== peg$FAILED) {
3153
3107
  peg$savedPos = s0;
3154
- s0 = peg$f55(s2, s3, s4);
3108
+ s0 = peg$f58(s2, s3, s4);
3155
3109
  } else {
3156
3110
  peg$currPos = s0;
3157
3111
  s0 = peg$FAILED;
@@ -3170,7 +3124,7 @@ function peg$parse(input, options) {
3170
3124
  }
3171
3125
  if (s1 !== peg$FAILED) {
3172
3126
  peg$savedPos = s0;
3173
- s1 = peg$f56(s1);
3127
+ s1 = peg$f59(s1);
3174
3128
  }
3175
3129
  s0 = s1;
3176
3130
  if (s0 === peg$FAILED) {
@@ -3196,7 +3150,7 @@ function peg$parse(input, options) {
3196
3150
  s2 = input.substring(s2, peg$currPos);
3197
3151
  s3 = peg$parseHere();
3198
3152
  peg$savedPos = s0;
3199
- s0 = peg$f57(s1, s2, s3);
3153
+ s0 = peg$f60(s1, s2, s3);
3200
3154
  }
3201
3155
  }
3202
3156
  }
@@ -3206,7 +3160,7 @@ function peg$parse(input, options) {
3206
3160
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
3207
3161
  s0 = peg$currPos;
3208
3162
  peg$savedPos = peg$currPos;
3209
- s1 = peg$f58();
3163
+ s1 = peg$f61();
3210
3164
  if (s1) s1 = void 0;
3211
3165
  else s1 = peg$FAILED;
3212
3166
  if (s1 !== peg$FAILED) {
@@ -3235,7 +3189,7 @@ function peg$parse(input, options) {
3235
3189
  if (s2 !== peg$FAILED) {
3236
3190
  s3 = peg$currPos;
3237
3191
  peg$savedPos = peg$currPos;
3238
- s4 = peg$f59(s2);
3192
+ s4 = peg$f62(s2);
3239
3193
  if (s4) s4 = void 0;
3240
3194
  else s4 = peg$FAILED;
3241
3195
  if (s4 !== peg$FAILED) {
@@ -3274,7 +3228,7 @@ function peg$parse(input, options) {
3274
3228
  if (s0 === peg$FAILED) {
3275
3229
  s0 = peg$currPos;
3276
3230
  peg$savedPos = peg$currPos;
3277
- s1 = peg$f60();
3231
+ s1 = peg$f63();
3278
3232
  if (s1) s1 = void 0;
3279
3233
  else s1 = peg$FAILED;
3280
3234
  if (s1 !== peg$FAILED) {
@@ -3301,12 +3255,12 @@ function peg$parse(input, options) {
3301
3255
  if (s6 !== peg$FAILED) {
3302
3256
  s7 = peg$parseHere();
3303
3257
  peg$savedPos = peg$currPos;
3304
- s8 = peg$f61(s4, s7);
3258
+ s8 = peg$f64(s4, s7);
3305
3259
  if (s8) s8 = void 0;
3306
3260
  else s8 = peg$FAILED;
3307
3261
  if (s8 !== peg$FAILED) {
3308
3262
  s9 = peg$currPos;
3309
- s10 = peg$f62(s4, s7);
3263
+ s10 = peg$f65(s4, s7);
3310
3264
  s11 = peg$currPos;
3311
3265
  s12 = [];
3312
3266
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -3336,13 +3290,7 @@ function peg$parse(input, options) {
3336
3290
  if (s10 !== peg$FAILED) s9 = input.substring(s9, peg$currPos);
3337
3291
  else s9 = s10;
3338
3292
  if (s9 !== peg$FAILED) {
3339
- if (input.charCodeAt(peg$currPos) === 125) {
3340
- s10 = peg$c11;
3341
- peg$currPos++;
3342
- } else {
3343
- s10 = peg$FAILED;
3344
- if (peg$silentFails === 0) peg$fail(peg$e19);
3345
- }
3293
+ s10 = peg$parseBraceEnd();
3346
3294
  if (s10 !== peg$FAILED) {
3347
3295
  s1 = [
3348
3296
  s1,
@@ -3388,7 +3336,7 @@ function peg$parse(input, options) {
3388
3336
  if (s0 === peg$FAILED) {
3389
3337
  s0 = peg$currPos;
3390
3338
  peg$savedPos = peg$currPos;
3391
- s1 = peg$f63();
3339
+ s1 = peg$f66();
3392
3340
  if (s1) s1 = void 0;
3393
3341
  else s1 = peg$FAILED;
3394
3342
  if (s1 !== peg$FAILED) {
@@ -3435,13 +3383,7 @@ function peg$parse(input, options) {
3435
3383
  if (s4 !== peg$FAILED) {
3436
3384
  s5 = peg$parseCodeToBrace();
3437
3385
  if (s5 !== peg$FAILED) {
3438
- if (input.charCodeAt(peg$currPos) === 125) {
3439
- s6 = peg$c11;
3440
- peg$currPos++;
3441
- } else {
3442
- s6 = peg$FAILED;
3443
- if (peg$silentFails === 0) peg$fail(peg$e19);
3444
- }
3386
+ s6 = peg$parseBraceEnd();
3445
3387
  if (s6 !== peg$FAILED) {
3446
3388
  s1 = [
3447
3389
  s1,
@@ -3479,7 +3421,7 @@ function peg$parse(input, options) {
3479
3421
  if (s0 === peg$FAILED) {
3480
3422
  s0 = peg$currPos;
3481
3423
  peg$savedPos = peg$currPos;
3482
- s1 = peg$f64();
3424
+ s1 = peg$f67();
3483
3425
  if (s1) s1 = void 0;
3484
3426
  else s1 = peg$FAILED;
3485
3427
  if (s1 !== peg$FAILED) {
@@ -3507,13 +3449,7 @@ function peg$parse(input, options) {
3507
3449
  if (s3 !== peg$FAILED) {
3508
3450
  s4 = peg$parseCodeToBrace();
3509
3451
  if (s4 !== peg$FAILED) {
3510
- if (input.charCodeAt(peg$currPos) === 125) {
3511
- s5 = peg$c11;
3512
- peg$currPos++;
3513
- } else {
3514
- s5 = peg$FAILED;
3515
- if (peg$silentFails === 0) peg$fail(peg$e19);
3516
- }
3452
+ s5 = peg$parseBraceEnd();
3517
3453
  if (s5 !== peg$FAILED) {
3518
3454
  s1 = [
3519
3455
  s1,
@@ -3569,6 +3505,7 @@ function peg$parse(input, options) {
3569
3505
  return s0;
3570
3506
  }
3571
3507
  const textMode = options.text === true;
3508
+ const completionMode = options.completion === true;
3572
3509
  const hooks = options.hooks;
3573
3510
  /** End of the stretch a `.|n|` repetition consumes (see skipTo). */
3574
3511
  let skipEnd = -1;
@@ -3654,6 +3591,46 @@ function peg$parse(input, options) {
3654
3591
  else peg$throw();
3655
3592
  }
3656
3593
  //#endregion
3594
+ //#region src/utils/macro-names.ts
3595
+ /**
3596
+ * Macro and widget names are case-insensitive: `{StatusBar}` invokes the
3597
+ * widget defined as `statusbar`. A NameMap keys its entries by the lowercased
3598
+ * name.
3599
+ */
3600
+ var NameMap = class extends Map {
3601
+ get(name) {
3602
+ return super.get(name.toLowerCase());
3603
+ }
3604
+ set(name, value) {
3605
+ return super.set(name.toLowerCase(), value);
3606
+ }
3607
+ has(name) {
3608
+ return super.has(name.toLowerCase());
3609
+ }
3610
+ delete(name) {
3611
+ return super.delete(name.toLowerCase());
3612
+ }
3613
+ };
3614
+ /** A set of macro or widget names (see NameMap). */
3615
+ var NameSet = class {
3616
+ constructor(names = []) {
3617
+ this.names = new NameMap();
3618
+ for (const name of names) this.add(name);
3619
+ }
3620
+ add(name) {
3621
+ this.names.set(name, true);
3622
+ }
3623
+ has(name) {
3624
+ return this.names.has(name);
3625
+ }
3626
+ delete(name) {
3627
+ this.names.delete(name);
3628
+ }
3629
+ clear() {
3630
+ this.names.clear();
3631
+ }
3632
+ };
3633
+ //#endregion
3657
3634
  //#region src/markup/ast.ts
3658
3635
  /**
3659
3636
  * The passage AST (built by parse.ts), and the registry of block macros:
@@ -3682,13 +3659,15 @@ var BLOCK_MACROS = new NameSet([
3682
3659
  * definition is, whereas the macros in BLOCK_MACROS stay blocks.
3683
3660
  */
3684
3661
  var BLOCK_WIDGETS = new NameSet();
3662
+ /** All widgets, including inline ones, override built-in parsing semantics. */
3663
+ var WIDGETS = new NameSet();
3685
3664
  /** Classification owned by defineMacro, independent of explicit registrations. */
3686
3665
  var DEFINED_BLOCK_MACROS = new NameSet();
3687
3666
  /** Macros whose body is JavaScript source, kept verbatim. */
3688
3667
  var RAW_BODY_MACROS = /* @__PURE__ */ new Set(["do"]);
3689
3668
  /** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
3690
- function isRawMacro(name) {
3691
- return RAW_BODY_MACROS.has(name);
3669
+ function isRawMacro(name, widget = WIDGETS.has(name)) {
3670
+ return RAW_BODY_MACROS.has(name.toLowerCase()) && !widget;
3692
3671
  }
3693
3672
  /** Whether a macro takes a body closed by `{/name}`. */
3694
3673
  function isBlockMacro(name) {
@@ -3747,7 +3726,8 @@ function astNode({ token, body }) {
3747
3726
  };
3748
3727
  if (!body) return withSelectors$1(node, token);
3749
3728
  const children = buildAst(body.children);
3750
- if (!BRANCHING.has(name) && body.branches.length === 0) {
3729
+ const branching = BRANCHING.has(name) && !WIDGETS.has(name);
3730
+ if (!branching && body.branches.length === 0) {
3751
3731
  node.children = children;
3752
3732
  return withSelectors$1(node, token);
3753
3733
  }
@@ -3755,12 +3735,99 @@ function astNode({ token, body }) {
3755
3735
  rawArgs: tag.rawArgs,
3756
3736
  children: branchChildren
3757
3737
  }, tag);
3758
- if (!BRANCHING.has(name)) node.children = children;
3759
- node.branches = [...BRANCHING.has(name) ? [branch(token, children)] : [], ...body.branches.map(({ tag, children: c }) => branch(tag, buildAst(c)))];
3760
- return BRANCHING.has(name) ? node : withSelectors$1(node, token);
3738
+ if (!branching) node.children = children;
3739
+ node.branches = [...branching ? [branch(token, children)] : [], ...body.branches.map(({ tag, children: c }) => branch(tag, buildAst(c)))];
3740
+ return branching ? node : withSelectors$1(node, token);
3761
3741
  }
3762
3742
  }
3763
3743
  }
3744
+ new NameMap();
3745
+ new NameMap();
3746
+ new NameSet();
3747
+ /**
3748
+ * How a macro argument is read (see components/macros/macro-args.ts). Every
3749
+ * declared parameter names one: there is no default.
3750
+ * Quoted strings accept `\"`, `\'` and `\\` escapes.
3751
+ * - `expression`: code, as written.
3752
+ * - `statements`: code run as statements (`{set}`), as written.
3753
+ * - `passage`: a passage name: a quoted string or an expression, as written.
3754
+ * - `variable`: a variable reference such as `$name` or `"$name"`, as written.
3755
+ * - `string`: one quoted string; anything else leaves the argument unset.
3756
+ * - `text`: one quoted string, or text with any loose quotes stripped.
3757
+ * - `names`: a comma-separated list of names (`@item, @i`).
3758
+ * - `delay`: a duration (`2s`, `500ms`, `300`) in milliseconds.
3759
+ * - `number`: a number.
3760
+ * - `flag`: a keyword, the parameter's name, at the start or end; a boolean.
3761
+ * - `separator`: a word (`of`) or `=` separating the parameters before it
3762
+ * from those after it; a boolean.
3763
+ * - `options`: keywords, the names of its `parameters`, each followed by a
3764
+ * quoted string or a number unless it is a flag.
3765
+ */
3766
+ var PARAMETER_TYPES = [
3767
+ "expression",
3768
+ "statements",
3769
+ "passage",
3770
+ "variable",
3771
+ "string",
3772
+ "text",
3773
+ "names",
3774
+ "delay",
3775
+ "number",
3776
+ "flag",
3777
+ "separator",
3778
+ "options"
3779
+ ];
3780
+ /**
3781
+ * What the value of a `string` or `text` argument holds, for the check at
3782
+ * story start and for tooling (see code-check.ts):
3783
+ * - `markup`: markup the macro renders (`{button}`'s label): its markup
3784
+ * is checked.
3785
+ * - `text`: plain text the macro uses as written (`{checkbox}`'s label).
3786
+ * - `passage`: a passage name (`{watch}`'s `goto`): the passage must exist.
3787
+ * - `expression`, `statements`: code (`{watch}`'s condition and `run`): it
3788
+ * is checked as code, and its variable references against the schema.
3789
+ *
3790
+ * Without it, the argument of a macro with `interpolate` holds `markup`,
3791
+ * any other `text`.
3792
+ */
3793
+ var STRING_HOLDS = [
3794
+ "markup",
3795
+ "text",
3796
+ "passage",
3797
+ "expression",
3798
+ "statements"
3799
+ ];
3800
+ /**
3801
+ * Throw if a parameter `macro` declares (or an option of one) has no type,
3802
+ * or one that isn't a ParameterType: arguments are read by their type, and
3803
+ * there is no default. Throw too if it declares what it `holds` wrongly.
3804
+ */
3805
+ function checkParameterTypes(macro, parameters) {
3806
+ const holdsFix = `Give a \`string\` or \`text\` parameter one of ${STRING_HOLDS.join(", ")} to hold (see docs/custom-macros.md#what-a-string-holds).`;
3807
+ for (const param of parameters) {
3808
+ const type = param.type;
3809
+ if (!PARAMETER_TYPES.includes(type)) throw parameterError(macro, param, type === void 0 ? "has no type" : `has the unknown type ${JSON.stringify(type)}`, `Give it one of the types ${PARAMETER_TYPES.join(", ")} (see docs/custom-macros.md#parameter-types), or declare no parameters and read props.rawArgs.`);
3810
+ const holds = param.holds;
3811
+ if (holds !== void 0 && type !== "string" && type !== "text") throw parameterError(macro, param, `is of the type ${type}, which holds what it is`, holdsFix);
3812
+ if (holds !== void 0 && !STRING_HOLDS.includes(holds)) throw parameterError(macro, param, `holds the unknown ${JSON.stringify(holds)}`, holdsFix);
3813
+ if (param.parameters) checkParameterTypes(macro, param.parameters);
3814
+ }
3815
+ }
3816
+ /** The error for the parameter `param` of `macro`: what is wrong, and the fix. */
3817
+ function parameterError(macro, param, problem, fix) {
3818
+ return /* @__PURE__ */ new Error(`spindle: The parameter "${param.name}" of the macro {${macro}} ${problem}. ${fix}`);
3819
+ }
3820
+ var metadataRegistry = new NameMap();
3821
+ /** Indexed at registration, so parsing each tag does not scan every macro. */
3822
+ var companionParents = new NameMap();
3823
+ /** The parents declaring a branching companion (listbox options are values). */
3824
+ function branchParents(name, macros) {
3825
+ if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent !== "listbox");
3826
+ return macros.filter((macro) => macro.name.toLowerCase() !== "listbox" && macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase())).map((macro) => macro.name.toLowerCase());
3827
+ }
3828
+ function getMacroRegistry() {
3829
+ return Array.from(metadataRegistry.values());
3830
+ }
3764
3831
  //#endregion
3765
3832
  //#region src/markup/line-column.ts
3766
3833
  /** 1-based line and column of `offset` in `text`. */
@@ -3777,6 +3844,25 @@ function lineColumn(text, offset) {
3777
3844
  column: offset - lineStart + 1
3778
3845
  };
3779
3846
  }
3847
+ /** Index one source once; offsets and columns count UTF-16 code units. */
3848
+ function sourcePositions(text) {
3849
+ const starts = [0];
3850
+ for (let i = 0; i < text.length; i++) if (text[i] === "\n") starts.push(i + 1);
3851
+ return (offset) => {
3852
+ let low = 0;
3853
+ let high = starts.length;
3854
+ while (low < high) {
3855
+ const mid = low + high >>> 1;
3856
+ if (starts[mid] <= offset) low = mid + 1;
3857
+ else high = mid;
3858
+ }
3859
+ const line = Math.max(1, low);
3860
+ return {
3861
+ line,
3862
+ column: offset - starts[line - 1] + 1
3863
+ };
3864
+ };
3865
+ }
3780
3866
  //#endregion
3781
3867
  //#region src/markup/pair.ts
3782
3868
  /**
@@ -3828,9 +3914,11 @@ function pairMarkup(tokens, options = {}) {
3828
3914
  };
3829
3915
  const errors = [];
3830
3916
  const noticedAtEnd = (tokens[tokens.length - 1]?.end ?? 0) + 1;
3917
+ let position;
3831
3918
  const where = (offset) => {
3832
3919
  if (options.source === void 0) return `offset ${offset}`;
3833
- const { line, column } = lineColumn(options.source, offset);
3920
+ position ?? (position = sourcePositions(options.source));
3921
+ const { line, column } = position(offset);
3834
3922
  return `line ${line}, column ${column}`;
3835
3923
  };
3836
3924
  const report = (code, token, message, noticedAt, data) => {
@@ -10144,7 +10232,7 @@ function isCodeAttribute(name) {
10144
10232
  * sigil is not followed by a word character (`{$(…)}`) is code, kept
10145
10233
  * verbatim: not resolved, and not decoded like text.
10146
10234
  */
10147
- function splitSigilTemplate(template) {
10235
+ function splitSigilTemplate(template, incomplete = false) {
10148
10236
  const parts = [];
10149
10237
  let text = "";
10150
10238
  let i = 0;
@@ -10156,7 +10244,8 @@ function splitSigilTemplate(template) {
10156
10244
  }
10157
10245
  text += template.slice(i, brace);
10158
10246
  i = brace + 1;
10159
- const end = isSigil(template[i]) ? defaultCodeEnd.closeBrace(template, i, i) : -1;
10247
+ let end = isSigil(template[i]) ? defaultCodeEnd.closeBrace(template, i, i) : -1;
10248
+ if (end === -1 && incomplete && isSigil(template[i])) end = template.length;
10160
10249
  if (end === -1) {
10161
10250
  text += "{";
10162
10251
  continue;
@@ -10164,7 +10253,7 @@ function splitSigilTemplate(template) {
10164
10253
  if (text) parts.push({ text });
10165
10254
  text = "";
10166
10255
  const block = template.slice(i, end);
10167
- parts.push(/^.\w/.test(block) ? { expr: block } : { verbatim: `{${block}}` });
10256
+ parts.push(/^.\w/.test(block) || incomplete && block.length === 1 && end === template.length ? { expr: block } : { verbatim: `{${block}}` });
10168
10257
  i = end + 1;
10169
10258
  }
10170
10259
  if (text) parts.push({ text });
@@ -10197,7 +10286,7 @@ var MarkupError = class extends Error {
10197
10286
  this.name = "MarkupError";
10198
10287
  }
10199
10288
  };
10200
- function run$1(source, startRule, options) {
10289
+ function run$1(source, startRule, options, completion = false) {
10201
10290
  const hooks = options.hooks ? {
10202
10291
  ...defaultHooks,
10203
10292
  ...options.hooks
@@ -10206,7 +10295,8 @@ function run$1(source, startRule, options) {
10206
10295
  return peg$parse(source, {
10207
10296
  startRule,
10208
10297
  text: options.text === true,
10209
- hooks
10298
+ hooks,
10299
+ completion
10210
10300
  });
10211
10301
  } catch (err) {
10212
10302
  const { location, code } = err;
@@ -10243,7 +10333,8 @@ function analyzeMarkup(source, options = {}) {
10243
10333
  };
10244
10334
  const inDamage = (start) => errors.some((e, i) => start >= damage[i] && start <= e.offset);
10245
10335
  const noticed = errors.map((e, i) => [damage[i] + .5, e]);
10246
- for (const error of paired.errors) if (!inDamage(error.start)) noticed.push([error.noticedAt, pairingError(source, error)]);
10336
+ const position = paired.errors.length ? sourcePositions(source) : void 0;
10337
+ for (const error of paired.errors) if (!inDamage(error.start)) noticed.push([error.noticedAt, pairingError(position, error)]);
10247
10338
  noticed.sort((a, b) => a[0] - b[0]);
10248
10339
  return {
10249
10340
  tokens,
@@ -10262,8 +10353,8 @@ function parseMarkup(source, options = {}) {
10262
10353
  return buildAst(nodes);
10263
10354
  }
10264
10355
  /** A pairing problem as the MarkupError it is for `source`. */
10265
- function pairingError(source, error) {
10266
- const { line, column } = lineColumn(source, error.start);
10356
+ function pairingError(position, error) {
10357
+ const { line, column } = position(error.start);
10267
10358
  return new MarkupError(error.message, error.start, line, column, error.code, error.end, error.data);
10268
10359
  }
10269
10360
  /**
@@ -10306,10 +10397,11 @@ function tokenizeMarkupTolerant(source, options = {}) {
10306
10397
  * each error starts (`damage[i]` for `errors[i]`): the tag that is
10307
10398
  * malformed, which an error inside it (an attribute value) is after.
10308
10399
  */
10309
- function scanMarkupTolerant(source, options = {}) {
10400
+ function scanMarkupTolerant(source, options = {}, completion = false) {
10310
10401
  const tokens = [];
10311
10402
  const errors = [];
10312
10403
  const damage = [];
10404
+ let position;
10313
10405
  const lastBrace = source.lastIndexOf("}");
10314
10406
  const { closeBrace } = {
10315
10407
  ...defaultHooks,
@@ -10322,10 +10414,10 @@ function scanMarkupTolerant(source, options = {}) {
10322
10414
  closeBrace: (input, codeStart, lenientStart) => base + Math.min(codeStart, lenientStart) > lastBrace ? -1 : closeBrace(input, codeStart, lenientStart)
10323
10415
  };
10324
10416
  try {
10325
- return tokenizeMarkup(text, {
10417
+ return run$1(text, "Tokens", {
10326
10418
  ...options,
10327
10419
  hooks
10328
- }).map((token) => shiftOffsets(token, base));
10420
+ }, completion).map((token) => shiftOffsets(token, base));
10329
10421
  } catch (error) {
10330
10422
  if (!(error instanceof MarkupError)) throw error;
10331
10423
  return error;
@@ -10340,7 +10432,8 @@ function scanMarkupTolerant(source, options = {}) {
10340
10432
  break;
10341
10433
  }
10342
10434
  const at = base + result.offset;
10343
- const { line, column } = lineColumn(source, at);
10435
+ position ?? (position = sourcePositions(source));
10436
+ const { line, column } = position(at);
10344
10437
  errors.push(new MarkupError(result.reason, at, line, column, result.code, base + result.end));
10345
10438
  let cut = result.offset;
10346
10439
  let prefix = attempt(rest.slice(0, cut), base);
@@ -10367,6 +10460,10 @@ function scanMarkupTolerant(source, options = {}) {
10367
10460
  damage
10368
10461
  };
10369
10462
  }
10463
+ /** Runtime grammar with unfinished EOF tokens, for cursor contexts only. */
10464
+ function completionTokens(source, options = {}) {
10465
+ return scanMarkupTolerant(source, options, true).tokens;
10466
+ }
10370
10467
  /** The offset fields of a token (and of an attribute): `start`, `nameEnd`… */
10371
10468
  var OFFSET_FIELD = /^(start|end|[A-Za-z]*(Start|End))$/;
10372
10469
  /** `token` (or an attribute of it) with each of its offsets turned by `map`. */
@@ -11219,14 +11316,16 @@ function* codeAndText(src, tokens, parametersOf) {
11219
11316
  * `src`. In source order, a nested piece after the text it is in.
11220
11317
  */
11221
11318
  function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
11222
- yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0);
11319
+ let position;
11320
+ const locate = (offset) => (position ?? (position = sourcePositions(src)))(offset);
11321
+ yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0, locate);
11223
11322
  }
11224
11323
  /**
11225
11324
  * The pieces of `tokens`, the tokens of `src`, which is the text described by
11226
11325
  * `where` (none for `root`, the markup of the whole passage), and whose
11227
11326
  * offsets `toRoot` turns into offsets in `root`.
11228
11327
  */
11229
- function* expand(root, src, tokens, parametersOf, options, toRoot, where) {
11328
+ function* expand(root, src, tokens, parametersOf, options, toRoot, where, locate) {
11230
11329
  for (const flat of codeAndText(src, tokens, parametersOf)) {
11231
11330
  const piece = where ? nestedPiece(flat, toRoot, where) : flat;
11232
11331
  if (flat.kind !== "text" || !flat.text.includes("{")) {
@@ -11236,17 +11335,20 @@ function* expand(root, src, tokens, parametersOf, options, toRoot, where) {
11236
11335
  const toText = (i) => toRoot(pieceOffset(flat, i));
11237
11336
  const inner = analyzeMarkup(flat.text, {
11238
11337
  text: true,
11239
- hooks: options.isBlock && { isBlock: options.isBlock }
11338
+ hooks: {
11339
+ ...options.isBlock && { isBlock: options.isBlock },
11340
+ isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0)
11341
+ }
11240
11342
  });
11241
11343
  yield {
11242
11344
  ...piece,
11243
11345
  tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
11244
11346
  errors: inner.errors.map((e) => {
11245
- const { line, column } = lineColumn(root, toText(e.offset));
11347
+ const { line, column } = locate(toText(e.offset));
11246
11348
  return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
11247
11349
  })
11248
11350
  };
11249
- yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where);
11351
+ yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where, locate);
11250
11352
  }
11251
11353
  }
11252
11354
  /** `piece`, of a text in another, with its offsets turned by `toRoot`. */
@@ -11540,6 +11642,118 @@ function referencesOf(pieces) {
11540
11642
  return refs;
11541
11643
  }
11542
11644
  //#endregion
11645
+ //#region src/completion-context.ts
11646
+ /** Cursor context from the runtime grammar and argument metadata, without executing code. */
11647
+ var LITERAL = { kind: "literal" };
11648
+ /**
11649
+ * Whether a cursor is in executable markup, including unfinished EOF tags.
11650
+ * Only the source before cursor is inspected. Code includes its literals;
11651
+ * kind is literal when the cursor itself is inside one, a comment, or prose.
11652
+ */
11653
+ function completionContext(source, cursor, macros = []) {
11654
+ if (!Number.isInteger(cursor) || cursor < 0 || cursor > source.length) throw new RangeError("cursor must be a UTF-16 offset within source");
11655
+ const parametersOf = parameterLookup(macros);
11656
+ const codeContext = (code, goal, map) => {
11657
+ const probe = code.length + 1;
11658
+ let executable = false;
11659
+ lexJs(code + " __spindle_cursor__", {
11660
+ code(_ch, at) {
11661
+ if (at >= probe) executable = true;
11662
+ },
11663
+ variable(_sigil, _name, at) {
11664
+ if (at >= probe) executable = true;
11665
+ }
11666
+ }, goal);
11667
+ if (!executable) return LITERAL;
11668
+ const offset = map(0);
11669
+ const offsets = Array.from({ length: code.length + 1 }, (_, i) => map(i));
11670
+ return {
11671
+ kind: "code",
11672
+ code,
11673
+ goal,
11674
+ offset,
11675
+ cursor: code.length,
11676
+ ...offsets.some((at, i) => at !== offset + i) ? { sourceOffsets: offsets } : {}
11677
+ };
11678
+ };
11679
+ const read = (src, map, text = false, depth = 0, sigilsOnly = false) => {
11680
+ if (depth >= 64) return LITERAL;
11681
+ if (sigilsOnly) {
11682
+ let at = 0;
11683
+ for (const part of splitSigilTemplate(src, true)) if ("expr" in part) {
11684
+ if (at + 1 + part.expr.length === src.length) return codeContext(part.expr, "expression", (i) => map(at + 1 + i));
11685
+ at += part.expr.length + 2;
11686
+ } else at += ("text" in part ? part.text : part.verbatim).length;
11687
+ return LITERAL;
11688
+ }
11689
+ const tokens = completionTokens(src, {
11690
+ text,
11691
+ hooks: { isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0) }
11692
+ });
11693
+ const token = tokens[tokens.length - 1];
11694
+ if (!token || token.end !== src.length) return LITERAL;
11695
+ const codeAt = (code, at, goal = "expression") => codeContext(code, goal, (i) => map(at + i));
11696
+ const nested = (value, at, offsets, onlySigils = false) => read(value, (i) => map(offsets?.[i] ?? at + i), true, depth + 1, onlySigils);
11697
+ if (token.type === "variable" && token.nameEnd === src.length) return codeAt(src.slice(token.nameStart - 1), token.nameStart - 1);
11698
+ if (token.type === "expression" && token.expressionEnd === src.length) return codeAt(token.expression, token.expressionStart);
11699
+ if (token.type === "html") {
11700
+ for (const { name, value, at } of attributeValues(src, token)) if (at + value.length === src.length) return nested(value, at, void 0, isCodeAttribute(name));
11701
+ } else if (token.type === "link" && token.displayEnd === src.length) return nested(token.display, token.displayStart);
11702
+ else if (token.type === "text" && !token.comment) {
11703
+ const opener = tokens[tokens.length - 2];
11704
+ if (opener?.type === "macro" && !opener.isClose && isRawMacro(opener.name, parametersOf.widget?.(opener.name) !== void 0)) return codeAt(token.value, token.start, "statements");
11705
+ } else if (token.type === "macro" && !token.isClose && token.argsEnd === src.length) {
11706
+ const name = token.name.toLowerCase();
11707
+ const args = token.rawArgs;
11708
+ const widget = parametersOf.widget?.(name);
11709
+ if (!widget && [
11710
+ "if",
11711
+ "elseif",
11712
+ "case"
11713
+ ].includes(name)) return codeAt(args, token.argsStart);
11714
+ const stringContext = (raw, at, holds, escapes = "quotes") => {
11715
+ const quoted = readQuoted(raw, 0, true);
11716
+ if (!quoted) {
11717
+ if (holds === "expression" || holds === "statements") return codeAt(raw, at, holds);
11718
+ return holds === "markup" ? nested(raw, at) : LITERAL;
11719
+ }
11720
+ if (scanStringLiteral(raw, 0).closed) return LITERAL;
11721
+ const value = escapes === "javascript" ? stringLiteralValue(raw + raw[0]) : quoted.value;
11722
+ if (value == null) return LITERAL;
11723
+ const offsets = escapeOffsets(raw.slice(1), at + 1, value, escapes);
11724
+ if (holds === "expression" || holds === "statements") return codeContext(value, holds, (i) => map(offsets?.[i] ?? at + 1 + i));
11725
+ return holds === "markup" ? nested(value, at + 1, offsets) : LITERAL;
11726
+ };
11727
+ if (widget) {
11728
+ const spans = splitArgSpans(args);
11729
+ const span = spans[spans.length - 1];
11730
+ if (!span) return LITERAL;
11731
+ const raw = args.slice(span[0]);
11732
+ const holds = widget[spans.length - 1]?.holds;
11733
+ return /^["']/.test(raw) && holds ? stringContext(raw, token.argsStart + span[0], holds, "javascript") : codeAt(raw, token.argsStart + span[0]);
11734
+ }
11735
+ const params = parametersOf(name);
11736
+ if (!params) return LITERAL;
11737
+ const spans = macroArgumentSpans(args, params).filter((span) => span.parameter.type !== "options" && span.end === args.trimEnd().length);
11738
+ const span = spans[spans.length - 1];
11739
+ if (!span) return LITERAL;
11740
+ const param = span.parameter;
11741
+ let at = span.start;
11742
+ if (span.parameterPath.length > 1) {
11743
+ at += param.name.length;
11744
+ while (/\s/.test(args.charAt(at))) at++;
11745
+ }
11746
+ const raw = args.slice(at);
11747
+ const offset = token.argsStart + at;
11748
+ if (param.type === "expression" || param.type === "passage") return codeAt(raw, offset);
11749
+ if (param.type === "statements") return codeAt(raw, offset, "statements");
11750
+ if (param.type === "string" || param.type === "text") return stringContext(raw, offset, param.holds);
11751
+ }
11752
+ return LITERAL;
11753
+ };
11754
+ return read(source.slice(0, cursor), (i) => i);
11755
+ }
11756
+ //#endregion
11543
11757
  //#region src/widgets/ast-scanner.ts
11544
11758
  /** The declared parameters of the macros registered so far. */
11545
11759
  var registeredParameters = (name) => parameterLookup(getMacroRegistry())(name);
@@ -11547,25 +11761,29 @@ var registeredParameters = (name) => parameterLookup(getMacroRegistry())(name);
11547
11761
  * Whether the text of an attribute value or macro label renders a
11548
11762
  * `{@children}`: it is markup, parsed as the renderer parses it.
11549
11763
  */
11550
- function textContainsChildren(text, parametersOf) {
11764
+ function textContainsChildren(text, parametersOf, hooks) {
11551
11765
  if (!text.includes("{")) return false;
11552
11766
  let nodes;
11553
11767
  try {
11554
- nodes = parseMarkup(text, { text: true });
11768
+ nodes = parseMarkup(text, {
11769
+ text: true,
11770
+ hooks
11771
+ });
11555
11772
  } catch {
11556
11773
  return false;
11557
11774
  }
11558
- return astContainsChildren(nodes, parametersOf);
11775
+ return astContainsChildren(nodes, parametersOf, hooks);
11559
11776
  }
11560
11777
  /**
11561
11778
  * Whether a tag renders a `{@children}` in an attribute value or a macro
11562
11779
  * argument that holds markup (`<span title="{@children}">`,
11563
11780
  * `{button "{@children}"}`). Literal arguments and code are not markup.
11564
11781
  * `src` is the text a flat token's offsets index into (its attribute values
11565
- * are read from it); a token made from an AST has none.
11782
+ * are read from it); a token made from an AST has none. Discovery hooks
11783
+ * also apply inside these texts, before widgets have been registered.
11566
11784
  */
11567
- function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "") {
11568
- for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf)) return true;
11785
+ function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks) {
11786
+ for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks)) return true;
11569
11787
  return false;
11570
11788
  }
11571
11789
  /**
@@ -11575,36 +11793,33 @@ function tokenTextContainsChildren(token, parametersOf = registeredParameters, s
11575
11793
  * entered: its slot belongs to the innermost widget (as widgetDefinitions
11576
11794
  * reads it), and a definition renders nothing of its own.
11577
11795
  */
11578
- function astContainsChildren(nodes, parametersOf = registeredParameters) {
11796
+ function astContainsChildren(nodes, parametersOf = registeredParameters, hooks) {
11579
11797
  for (const node of nodes) {
11580
11798
  if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
11581
- if (node.type === "html") {
11582
- if (tokenTextContainsChildren({
11583
- isClose: false,
11584
- isSelfClose: false,
11585
- tagNameStart: 0,
11586
- tagNameEnd: 0,
11587
- attributeSpans: [],
11588
- ...node,
11589
- start: 0,
11590
- end: 0
11591
- }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11592
- }
11593
- if (node.type === "macro") {
11594
- if (node.name.toLowerCase() === "widget") continue;
11595
- if (tokenTextContainsChildren({
11596
- isClose: false,
11597
- nameStart: 0,
11598
- nameEnd: 0,
11599
- argsStart: 0,
11600
- argsEnd: 0,
11601
- ...node,
11602
- start: 0,
11603
- end: 0
11604
- }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11605
- if (node.branches) {
11606
- for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf)) return true;
11607
- }
11799
+ if (node.type !== "html" && node.type !== "macro") continue;
11800
+ if (node.type === "macro" && node.name.toLowerCase() === "widget") continue;
11801
+ const span = {
11802
+ isClose: false,
11803
+ start: 0,
11804
+ end: 0
11805
+ };
11806
+ if (tokenTextContainsChildren(node.type === "html" ? {
11807
+ ...node,
11808
+ ...span,
11809
+ isSelfClose: false,
11810
+ tagNameStart: 0,
11811
+ tagNameEnd: 0,
11812
+ attributeSpans: []
11813
+ } : {
11814
+ ...node,
11815
+ ...span,
11816
+ nameStart: 0,
11817
+ nameEnd: 0,
11818
+ argsStart: 0,
11819
+ argsEnd: 0
11820
+ }, parametersOf, "", hooks) || astContainsChildren(node.children, parametersOf, hooks)) return true;
11821
+ if (node.type === "macro" && node.branches) {
11822
+ for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf, hooks)) return true;
11608
11823
  }
11609
11824
  }
11610
11825
  return false;
@@ -11680,42 +11895,48 @@ function nameSpan(rawArgs) {
11680
11895
  * nested definitions, it belongs to the innermost.
11681
11896
  */
11682
11897
  function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
11683
- const found = [];
11684
- for (const passage of passages) {
11685
- if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
11686
- const open = [];
11687
- const done = [];
11688
- for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
11689
- if (!token.isClose) open.push({
11690
- token,
11691
- isBlock: false
11692
- });
11693
- else {
11694
- const def = open.pop();
11695
- if (def) done.push({
11696
- ...def,
11697
- closeStart: token.start
11898
+ const list = [...passages];
11899
+ const scan = (replacesDo) => {
11900
+ const found = [];
11901
+ const hooks = { isRaw: (name) => isRawMacro(name, replacesDo || parametersOf.widget?.(name) !== void 0) };
11902
+ for (const passage of list) {
11903
+ if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
11904
+ const open = [];
11905
+ const done = [];
11906
+ for (const token of tokenizeMarkupTolerant(passage.content, { hooks }).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
11907
+ if (!token.isClose) open.push({
11908
+ token,
11909
+ isBlock: false
11698
11910
  });
11699
- }
11700
- } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content))) open[open.length - 1].isBlock = true;
11701
- done.push(...open);
11702
- const defs = [];
11703
- for (const { token, isBlock, closeStart } of done) try {
11704
- const [from, to] = nameSpan(token.rawArgs);
11705
- defs.push({
11706
- ...parseWidgetDef(token.rawArgs),
11707
- block: isBlock,
11708
- passage: passage.name,
11709
- start: token.start,
11710
- end: token.end,
11711
- nameStart: token.argsStart + from,
11712
- nameEnd: token.argsStart + to,
11713
- ...closeStart === void 0 ? {} : { closeStart }
11714
- });
11715
- } catch {}
11716
- found.push(...defs.sort((a, b) => a.start - b.start));
11717
- }
11718
- return found;
11911
+ else {
11912
+ const def = open.pop();
11913
+ if (def) done.push({
11914
+ ...def,
11915
+ closeStart: token.start
11916
+ });
11917
+ }
11918
+ } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks))) open[open.length - 1].isBlock = true;
11919
+ done.push(...open);
11920
+ const defs = [];
11921
+ for (const { token, isBlock, closeStart } of done) try {
11922
+ const [from, to] = nameSpan(token.rawArgs);
11923
+ defs.push({
11924
+ ...parseWidgetDef(token.rawArgs),
11925
+ block: isBlock,
11926
+ passage: passage.name,
11927
+ start: token.start,
11928
+ end: token.end,
11929
+ nameStart: token.argsStart + from,
11930
+ nameEnd: token.argsStart + to,
11931
+ ...closeStart === void 0 ? {} : { closeStart }
11932
+ });
11933
+ } catch {}
11934
+ found.push(...defs.sort((a, b) => a.start - b.start));
11935
+ }
11936
+ return found;
11937
+ };
11938
+ const initial = scan(false);
11939
+ return effectiveWidgetDefinitions(initial).some((def) => def.name.toLowerCase() === "do") ? scan(true) : initial;
11719
11940
  }
11720
11941
  /**
11721
11942
  * The definitions the runtime ends up with, one per widget name: the closed
@@ -11774,14 +11995,23 @@ function distance(a, b) {
11774
11995
  }
11775
11996
  /** The known name closest to `name`, if one is close. */
11776
11997
  function closestName(name, names) {
11998
+ if (name.length > 256) return void 0;
11777
11999
  const lower = name.toLowerCase();
11778
12000
  let best;
11779
12001
  let bestDistance = Math.max(2, Math.floor(lower.length / 3)) + 1;
12002
+ let budget = 1e5;
12003
+ let candidates = 1e3;
11780
12004
  for (const candidate of names) {
12005
+ if (--candidates < 0) break;
12006
+ if (candidate.length > 256) continue;
12007
+ if (Math.abs(candidate.length - lower.length) >= bestDistance) continue;
12008
+ budget -= lower.length * candidate.length;
12009
+ if (budget < 0) break;
11781
12010
  const d = distance(lower, candidate.toLowerCase());
11782
12011
  if (d < bestDistance) {
11783
12012
  best = candidate;
11784
12013
  bestDistance = d;
12014
+ if (d === 0) break;
11785
12015
  }
11786
12016
  }
11787
12017
  return best;
@@ -11806,12 +12036,19 @@ function widgetName(rawArgs) {
11806
12036
  */
11807
12037
  function validateMarkup(passages, options) {
11808
12038
  const diagnostics = [];
12039
+ const positions = /* @__PURE__ */ new Map();
11809
12040
  const hooks = {
11810
12041
  ...options.isBlockMacro && { isBlock: options.isBlockMacro },
11811
- ...options.branchParents && { branchParents: options.branchParents }
12042
+ ...options.branchParents && { branchParents: options.branchParents },
12043
+ isRaw: (name) => isRawMacro(name, options.parametersOf ? options.parametersOf.widget?.(name) !== void 0 : void 0)
11812
12044
  };
11813
12045
  const report = (passage, start, end, code, message, data) => {
11814
- const { line, column } = lineColumn(passage.content, start);
12046
+ let position = positions.get(passage);
12047
+ if (!position) {
12048
+ position = sourcePositions(passage.content);
12049
+ positions.set(passage, position);
12050
+ }
12051
+ const { line, column } = position(start);
11815
12052
  const d = {
11816
12053
  passage: passage.name,
11817
12054
  line,
@@ -11857,7 +12094,7 @@ function validateMarkup(passages, options) {
11857
12094
  continue;
11858
12095
  }
11859
12096
  try {
11860
- const tokens = tokenizeMarkup(passage.content);
12097
+ const tokens = tokenizeMarkup(passage.content, { hooks });
11861
12098
  addWidgets(tokens);
11862
12099
  if (!reported) continue;
11863
12100
  parseMarkup(passage.content, { hooks });
@@ -12292,22 +12529,40 @@ var Reader = class {
12292
12529
  }
12293
12530
  /** Skip an array literal (or any bracketed group) at the cursor. */
12294
12531
  skipBalanced() {
12295
- const { src } = this;
12296
12532
  const close = {
12297
12533
  "[": "]",
12298
12534
  "{": "}",
12299
12535
  "(": ")"
12300
- }[src.charAt(this.i)];
12301
- if (!close) return false;
12536
+ }[this.src.charAt(this.i)];
12537
+ return close ? this.skipNested(close) : false;
12538
+ }
12539
+ /** Skip groups and template interpolations with an explicit stack. */
12540
+ skipNested(close) {
12541
+ const { src } = this;
12542
+ const stack = [close];
12302
12543
  this.i++;
12303
- while (this.i < src.length) {
12304
- if (src.charAt(this.i) === close) {
12544
+ while (this.i < src.length && stack.length) {
12545
+ const c = src.charAt(this.i);
12546
+ const top = stack[stack.length - 1];
12547
+ if (c === top) {
12548
+ stack.pop();
12305
12549
  this.i++;
12306
- return true;
12307
- }
12308
- if (!this.skipOne()) return false;
12550
+ } else if (top === "`") {
12551
+ if (c === "\\") this.i += 2;
12552
+ else if (c === "$" && src.charAt(this.i + 1) === "{") {
12553
+ stack.push("}");
12554
+ this.i += 2;
12555
+ } else this.i++;
12556
+ } else if (c === "`" || c === "[" || c === "{" || c === "(") {
12557
+ stack.push(c === "`" ? "`" : {
12558
+ "[": "]",
12559
+ "{": "}",
12560
+ "(": ")"
12561
+ }[c]);
12562
+ this.i++;
12563
+ } else if (!this.skipOne()) return false;
12309
12564
  }
12310
- return false;
12565
+ return stack.length === 0;
12311
12566
  }
12312
12567
  /** Skip one character, or one string, template, comment or group. */
12313
12568
  skipOne() {
@@ -12334,20 +12589,7 @@ var Reader = class {
12334
12589
  }
12335
12590
  /** Skip a template literal, with the expressions in it. */
12336
12591
  skipTemplate() {
12337
- const { src } = this;
12338
- this.i++;
12339
- while (this.i < src.length) {
12340
- const c = src.charAt(this.i);
12341
- if (c === "\\") this.i += 2;
12342
- else if (c === "`") {
12343
- this.i++;
12344
- return true;
12345
- } else if (c === "$" && src.charAt(this.i + 1) === "{") {
12346
- this.i++;
12347
- if (!this.skipBalanced()) return false;
12348
- } else this.i++;
12349
- }
12350
- return false;
12592
+ return this.skipNested("`");
12351
12593
  }
12352
12594
  };
12353
12595
  //#endregion
@@ -12356,10 +12598,14 @@ var Reader = class {
12356
12598
  * The tokens of markup, or none if it is malformed (validateMarkup reports
12357
12599
  * that, with its position); in tolerant mode, those of the well-formed parts.
12358
12600
  */
12359
- function tokensOf(text, textMode, { tolerant } = {}) {
12360
- if (tolerant) return tokenizeMarkupTolerant(text, { text: textMode }).tokens;
12601
+ function tokensOf(text, textMode, { tolerant, parametersOf } = {}) {
12602
+ const options = {
12603
+ text: textMode,
12604
+ hooks: parametersOf && { isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0) }
12605
+ };
12606
+ if (tolerant) return tokenizeMarkupTolerant(text, options).tokens;
12361
12607
  try {
12362
- return tokenizeMarkup(text, { text: textMode });
12608
+ return tokenizeMarkup(text, options);
12363
12609
  } catch (err) {
12364
12610
  if (err instanceof MarkupError) return [];
12365
12611
  throw err;
@@ -12895,6 +13141,8 @@ var Bindings = class {
12895
13141
  this.byOpen = /* @__PURE__ */ new Map();
12896
13142
  this.byClose = /* @__PURE__ */ new Map();
12897
13143
  this.functions = /* @__PURE__ */ new Map();
13144
+ this.functionStarts = /* @__PURE__ */ new Map();
13145
+ this.facts = /* @__PURE__ */ new Map();
12898
13146
  this.top = {
12899
13147
  start: -1,
12900
13148
  end: Infinity
@@ -12910,6 +13158,18 @@ var Bindings = class {
12910
13158
  * (given another, or one of its `properties` set) where the use can follow.
12911
13159
  */
12912
13160
  objectOf(name, at, properties) {
13161
+ let names = this.facts.get(properties);
13162
+ if (!names) this.facts.set(properties, names = /* @__PURE__ */ new Map());
13163
+ let bindings = names.get(name);
13164
+ if (!bindings) {
13165
+ bindings = this.readBindings(name, properties);
13166
+ names.set(name, bindings);
13167
+ }
13168
+ const found = this.innermostVisible(bindings, at);
13169
+ return found.length === 1 ? found[0].object : void 0;
13170
+ }
13171
+ /** Declaration and write facts are immutable for this source and property set. */
13172
+ readBindings(name, properties) {
12913
13173
  const { code } = this;
12914
13174
  const escaped = name.replace(/\$/g, "\\$");
12915
13175
  const bindings = [];
@@ -12919,8 +13179,7 @@ var Bindings = class {
12919
13179
  }
12920
13180
  const declarations = bindings.filter((b) => !b.write);
12921
13181
  for (const b of bindings) if (b.write) b.scope = this.innermostVisible(declarations, b.at)[0]?.scope ?? this.top;
12922
- const found = this.innermostVisible(bindings, at);
12923
- return found.length === 1 ? found[0].object : void 0;
13182
+ return bindings;
12924
13183
  }
12925
13184
  /**
12926
13185
  * Of the `bindings` the use at `at` can see, those in the innermost scope:
@@ -12997,7 +13256,13 @@ var Bindings = class {
12997
13256
  }
12998
13257
  /** The start of the function that has `index` in its body, or -1. */
12999
13258
  functionStart(index) {
13000
- for (let g = this.innermost(index, "{"); g; g = g.parent) if (g.kind === "{" && this.isFunctionBody(g)) return g.open;
13259
+ const known = this.functionStarts.get(index);
13260
+ if (known !== void 0) return known;
13261
+ for (let g = this.innermost(index, "{"); g; g = g.parent) if (g.kind === "{" && this.isFunctionBody(g)) {
13262
+ this.functionStarts.set(index, g.open);
13263
+ return g.open;
13264
+ }
13265
+ this.functionStarts.set(index, -1);
13001
13266
  return -1;
13002
13267
  }
13003
13268
  scopeOf(group) {
@@ -13322,6 +13587,7 @@ var ConfigReader = class extends Reader {
13322
13587
  constructor(..._args) {
13323
13588
  super(..._args);
13324
13589
  this.failed = false;
13590
+ this.depth = 0;
13325
13591
  }
13326
13592
  /** The static value of a member or element, whatever follows is skipped. */
13327
13593
  member() {
@@ -13389,22 +13655,31 @@ var ConfigReader = class extends Reader {
13389
13655
  * after what it read. False if the text ends first, or cannot be read.
13390
13656
  */
13391
13657
  elements(close, read) {
13392
- this.i++;
13393
- for (;;) {
13394
- this.space();
13395
- const c = this.src.charAt(this.i);
13396
- if (c === close) {
13397
- this.i++;
13398
- return true;
13399
- }
13400
- if (c === ",") {
13401
- this.i++;
13402
- continue;
13658
+ if (this.depth >= 64) {
13659
+ if (!this.skipBalanced()) this.fail();
13660
+ return false;
13661
+ }
13662
+ this.depth++;
13663
+ try {
13664
+ this.i++;
13665
+ for (;;) {
13666
+ this.space();
13667
+ const c = this.src.charAt(this.i);
13668
+ if (c === close) {
13669
+ this.i++;
13670
+ return true;
13671
+ }
13672
+ if (c === ",") {
13673
+ this.i++;
13674
+ continue;
13675
+ }
13676
+ if (this.failed || this.i >= this.src.length) return false;
13677
+ const before = this.i;
13678
+ read();
13679
+ if (this.i === before) this.fail();
13403
13680
  }
13404
- if (this.failed || this.i >= this.src.length) return false;
13405
- const before = this.i;
13406
- read();
13407
- if (this.i === before) this.fail();
13681
+ } finally {
13682
+ this.depth--;
13408
13683
  }
13409
13684
  }
13410
13685
  array() {
@@ -13564,6 +13839,7 @@ function macroOf(config) {
13564
13839
  function discoverMacros(source) {
13565
13840
  const { code, regexes } = codeOnly(source);
13566
13841
  const found = [];
13842
+ const configs = /* @__PURE__ */ new Map();
13567
13843
  let bindings;
13568
13844
  for (const call of code.matchAll(CALL_RE)) {
13569
13845
  let at = call.index + call[0].length;
@@ -13575,12 +13851,15 @@ function discoverMacros(source) {
13575
13851
  if (object === void 0) continue;
13576
13852
  at = object;
13577
13853
  }
13578
- const reader = new ConfigReader(source, {
13579
- goal: "statements",
13580
- regexes
13581
- });
13582
- reader.i = at;
13583
- const config = reader.datum();
13854
+ if (!configs.has(at)) {
13855
+ const reader = new ConfigReader(source, {
13856
+ goal: "statements",
13857
+ regexes
13858
+ });
13859
+ reader.i = at;
13860
+ configs.set(at, reader.datum());
13861
+ }
13862
+ const config = configs.get(at);
13584
13863
  const macro = config && macroOf(config);
13585
13864
  if (macro) found.push(macro);
13586
13865
  }
@@ -24447,18 +24726,8 @@ function markdownOptions(options) {
24447
24726
  //#region src/format/source-lines.ts
24448
24727
  /** Index a source once; locate zero-based lines without rescanning its prefixes. */
24449
24728
  function sourceLines(source) {
24450
- const starts = [0];
24451
- for (let i = 0; i < source.length; i++) if (source[i] === "\n") starts.push(i + 1);
24452
- return (offset) => {
24453
- let low = 0;
24454
- let high = starts.length;
24455
- while (low < high) {
24456
- const middle = low + high >>> 1;
24457
- if (starts[middle] <= offset) low = middle + 1;
24458
- else high = middle;
24459
- }
24460
- return Math.max(0, low - 1);
24461
- };
24729
+ const position = sourcePositions(source);
24730
+ return (offset) => position(offset).line - 1;
24462
24731
  }
24463
24732
  //#endregion
24464
24733
  //#region src/format/markdown-lines.ts
@@ -25361,7 +25630,9 @@ function blockLookup(macros) {
25361
25630
  * The macros are those the markup may use, built-in and user-defined.
25362
25631
  */
25363
25632
  function passagePieces(source, macros = []) {
25364
- return passagePiecesOfTokens(source, macros, tokenizeMarkupTolerant(source).tokens);
25633
+ const all = [...macros];
25634
+ const parametersOf = parameterLookup(all);
25635
+ return passagePiecesOfTokens(source, all, tokenizeMarkupTolerant(source, { hooks: { isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0) } }).tokens);
25365
25636
  }
25366
25637
  /**
25367
25638
  * `passagePieces` for a caller that has the tokens of
@@ -25440,4 +25711,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
25440
25711
  return checkVariableReferences(list.filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros, false, list));
25441
25712
  }
25442
25713
  //#endregion
25443
- export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, lexJs, lexTemplate, macroArgumentSpans, pairMarkup, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
25714
+ export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, lexJs, lexTemplate, macroArgumentSpans, pairMarkup, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };