@rohal12/spindle 0.59.22 → 0.59.24

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.
@@ -50,18 +50,13 @@ var VOID_TAGS = new Set([
50
50
  "track",
51
51
  "wbr"
52
52
  ]);
53
- var BRANCH_PARENT = {
53
+ var BRANCH_PARENT$1 = {
54
54
  elseif: "if",
55
55
  else: "if",
56
56
  case: "switch",
57
57
  default: "switch",
58
58
  next: "timed"
59
59
  };
60
- var BRANCHING = new Set([
61
- "if",
62
- "switch",
63
- "timed"
64
- ]);
65
60
  var LINK_SEPARATORS = [
66
61
  ["|", false],
67
62
  ["->", false],
@@ -98,6 +93,8 @@ function parseLink(inner, at, indexOf) {
98
93
  const [display, target] = targetFirst ? [after, before] : [before, after];
99
94
  return {
100
95
  display: display.value,
96
+ displayStart: display.start,
97
+ displayEnd: display.end,
101
98
  target: target.value,
102
99
  targetStart: target.start,
103
100
  targetEnd: target.end
@@ -106,14 +103,13 @@ function parseLink(inner, at, indexOf) {
106
103
  const whole = part(0, inner.length);
107
104
  return {
108
105
  display: whole.value,
106
+ displayStart: whole.start,
107
+ displayEnd: whole.end,
109
108
  target: whole.value,
110
109
  targetStart: whole.start,
111
110
  targetEnd: whole.end
112
111
  };
113
112
  }
114
- function quoteArg(value) {
115
- return "\"" + value.replace(/[\\"]/g, "\\$&") + "\"";
116
- }
117
113
  function selectorsOf(parts) {
118
114
  const classes = [];
119
115
  let id = "";
@@ -132,15 +128,6 @@ function label(tag) {
132
128
  if (tag.lex === "html") return (tag.isClose ? "</" : "<") + tag.tag + ">";
133
129
  return LB + (tag.isClose ? "/" : "") + tag.name + RB;
134
130
  }
135
- function closerOf(tag) {
136
- return tag.lex === "html" ? "</" + tag.tag + ">" : LB + "/" + tag.name + RB;
137
- }
138
- function at(loc) {
139
- return "line " + loc.start.line + ", column " + loc.start.column;
140
- }
141
- function sameName(open, close) {
142
- return open.lex === close.lex && open.lower === close.lower;
143
- }
144
131
  /** A lexeme: what one token of the flat stream holds, with its span. */
145
132
  function lexeme(lex, loc, fields) {
146
133
  fields.lex = lex;
@@ -149,35 +136,6 @@ function lexeme(lex, loc, fields) {
149
136
  fields.loc = loc;
150
137
  return fields;
151
138
  }
152
- /** The AST node of a lexeme that stands alone (not a macro or element). */
153
- function nodeOf(x) {
154
- switch (x.lex) {
155
- case "text": return x.comment ? {
156
- type: "text",
157
- value: x.value,
158
- comment: true
159
- } : {
160
- type: "text",
161
- value: x.value
162
- };
163
- case "link": return withSelectors({
164
- type: "macro",
165
- name: "link",
166
- rawArgs: quoteArg(x.display) + " " + quoteArg(x.target),
167
- children: []
168
- }, x);
169
- case "variable": return withSelectors({
170
- type: "variable",
171
- name: x.name,
172
- scope: x.scope
173
- }, x);
174
- case "expression": return withSelectors({
175
- type: "expression",
176
- expression: x.expression
177
- }, x);
178
- default: return x;
179
- }
180
- }
181
139
  /** The token of a lexeme (tokens.ts Token). */
182
140
  function tokenOf(x) {
183
141
  const span = {
@@ -185,7 +143,12 @@ function tokenOf(x) {
185
143
  end: x.end
186
144
  };
187
145
  switch (x.lex) {
188
- case "text": return {
146
+ case "text": return x.comment ? {
147
+ type: "text",
148
+ value: x.value,
149
+ comment: true,
150
+ ...span
151
+ } : {
189
152
  type: "text",
190
153
  value: x.value,
191
154
  ...span
@@ -193,33 +156,50 @@ function tokenOf(x) {
193
156
  case "link": return withSelectors({
194
157
  type: "link",
195
158
  display: x.display,
159
+ displayStart: x.displayStart,
160
+ displayEnd: x.displayEnd,
196
161
  target: x.target,
197
162
  targetStart: x.targetStart,
198
163
  targetEnd: x.targetEnd,
164
+ ...x.selectorSpan,
199
165
  ...span
200
166
  }, x);
201
167
  case "variable": return withSelectors({
202
168
  type: "variable",
203
169
  name: x.name,
170
+ nameStart: x.nameStart,
171
+ nameEnd: x.nameEnd,
204
172
  scope: x.scope,
173
+ ...x.selectorSpan,
205
174
  ...span
206
175
  }, x);
207
176
  case "expression": return withSelectors({
208
177
  type: "expression",
209
178
  expression: x.expression,
179
+ expressionStart: x.expressionStart,
180
+ expressionEnd: x.expressionEnd,
181
+ ...x.selectorSpan,
210
182
  ...span
211
183
  }, x);
212
184
  case "macro": return withSelectors({
213
185
  type: "macro",
214
186
  name: x.name,
187
+ nameStart: x.nameStart,
188
+ nameEnd: x.nameEnd,
215
189
  rawArgs: x.rawArgs,
190
+ argsStart: x.argsStart,
191
+ argsEnd: x.argsEnd,
216
192
  isClose: x.isClose,
193
+ ...x.selectorSpan,
217
194
  ...span
218
195
  }, x);
219
196
  case "html": return {
220
197
  type: "html",
221
198
  tag: x.tag,
199
+ tagNameStart: x.tagNameStart,
200
+ tagNameEnd: x.tagNameEnd,
222
201
  attributes: x.attributes,
202
+ attributeSpans: x.attributeSpans,
223
203
  isClose: x.isClose,
224
204
  isSelfClose: x.isSelfClose,
225
205
  ...span
@@ -230,7 +210,7 @@ function tokenOf(x) {
230
210
  * Flatten items (lexemes, nodes, arrays of them, nulls) and join adjacent
231
211
  * text, except escaped braces and comments, which stay a text item of their own.
232
212
  */
233
- function joinText(items, convert) {
213
+ function joinText(items) {
234
214
  const out = [];
235
215
  let last = null;
236
216
  const add = (item) => {
@@ -245,7 +225,7 @@ function joinText(items, convert) {
245
225
  last = item;
246
226
  };
247
227
  add(items);
248
- return convert ? out.map(convert) : out;
228
+ return out.map(tokenOf);
249
229
  }
250
230
  var peg$SyntaxError = class extends SyntaxError {
251
231
  constructor(message, expected, found, location) {
@@ -338,11 +318,10 @@ function peg$parse(input, options) {
338
318
  const peg$FAILED = {};
339
319
  const peg$source = options.grammarSource;
340
320
  const peg$startRuleFunctions = {
341
- Markup: peg$parseMarkup,
342
321
  Tokens: peg$parseTokens,
343
322
  SelectorsPrefix: peg$parseSelectorsPrefix
344
323
  };
345
- let peg$startRuleFunction = peg$parseMarkup;
324
+ let peg$startRuleFunction = peg$parseTokens;
346
325
  const peg$c0 = "<!--";
347
326
  const peg$c1 = ">";
348
327
  const peg$c2 = "->";
@@ -572,175 +551,74 @@ function peg$parse(input, options) {
572
551
  " ",
573
552
  ""
574
553
  ], false, false, false);
575
- function peg$f0(nodes) {
576
- return nodes;
554
+ function peg$f0(items) {
555
+ return joinText(items);
577
556
  }
578
- function peg$f1(tag) {
579
- fail(label(tag) + " must be directly inside {" + BRANCH_PARENT[tag.lower] + RB, tag.loc);
557
+ function peg$f1() {
558
+ return !textMode;
580
559
  }
581
560
  function peg$f2(tag) {
582
- fail(label(tag) + " closes nothing: no " + (tag.lex === "html" ? "<" + tag.tag + ">" : LB + tag.name + RB) + " is open here", tag.loc);
561
+ return tag;
583
562
  }
584
- function peg$f3(items) {
585
- return joinText(items, nodeOf);
563
+ function peg$f3() {
564
+ return !textMode;
586
565
  }
587
566
  function peg$f4(tag) {
588
- return tag.kind === "open";
567
+ return VOID_TAGS.has(tag.lower) ? null : tag;
589
568
  }
590
569
  function peg$f5(tag) {
591
570
  rawName = tag.lower;
592
- return hooks.isRaw(rawName);
571
+ return tag.kind === "open" && hooks.isRaw(rawName);
593
572
  }
594
573
  function peg$f6(tag, b) {
595
574
  return b;
596
575
  }
597
- function peg$f7(tag) {
598
- return hooks.isBlock(tag.lower);
599
- }
600
- function peg$f8(tag, b) {
601
- return b;
602
- }
603
- function peg$f9(tag) {
604
- return null;
605
- }
606
- function peg$f10(tag, body) {
607
- return macroNode(tag, body);
608
- }
609
- function peg$f11() {
610
- return !textMode;
611
- }
612
- function peg$f12(open) {
613
- return !open.isSelfClose;
614
- }
615
- function peg$f13(open, b) {
616
- return b;
617
- }
618
- function peg$f14(open, body) {
619
- const node = {
620
- type: "html",
621
- tag: open.tag,
622
- attributes: open.attributes,
623
- children: []
624
- };
625
- if (body) {
626
- checkBody(open, body);
627
- node.children = body.children;
628
- }
629
- return node;
630
- }
631
- function peg$f15(children, branches, end) {
632
- return {
633
- children,
634
- branches,
635
- end
636
- };
637
- }
638
- function peg$f16(tag, children) {
639
- return {
640
- tag,
641
- children
642
- };
643
- }
644
- function peg$f17() {
645
- return null;
646
- }
647
- function peg$f18(tag) {
648
- return tag.kind === "branch";
649
- }
650
- function peg$f19(tag) {
651
- return tag;
576
+ function peg$f7(tag, body) {
577
+ return body ? [tag, body] : tag;
652
578
  }
653
- function peg$f20(tag) {
579
+ function peg$f8(tag) {
654
580
  return tag.kind === "close";
655
581
  }
656
- function peg$f21(tag) {
582
+ function peg$f9(tag) {
657
583
  return tag;
658
584
  }
659
- function peg$f22() {
585
+ function peg$f10() {
660
586
  return !textMode;
661
587
  }
662
- function peg$f23(tag) {
588
+ function peg$f11(tag) {
663
589
  return tag;
664
590
  }
665
- function peg$f24(start) {
591
+ function peg$f12(start) {
666
592
  return skipTo(hooks.rawBodyEnd(input, start, rawName));
667
593
  }
668
- function peg$f25(start) {
594
+ function peg$f13(start) {
669
595
  return skipEnd - offset();
670
596
  }
671
- function peg$f26(start, body, end) {
672
- return {
673
- children: body ? [{
674
- type: "text",
675
- value: body
676
- }] : [],
677
- branches: [],
678
- end
679
- };
680
- }
681
- function peg$f27() {
682
- return {
683
- children: [],
684
- branches: [],
685
- end: null
686
- };
687
- }
688
- function peg$f28(items) {
689
- return joinText(items, tokenOf);
690
- }
691
- function peg$f29() {
692
- return !textMode;
693
- }
694
- function peg$f30(tag) {
695
- return tag;
696
- }
697
- function peg$f31() {
698
- return !textMode;
699
- }
700
- function peg$f32(tag) {
701
- return VOID_TAGS.has(tag.lower) ? null : tag;
702
- }
703
- function peg$f33(tag) {
704
- rawName = tag.lower;
705
- return tag.kind === "open" && hooks.isRaw(rawName);
706
- }
707
- function peg$f34(tag, b) {
708
- return b;
709
- }
710
- function peg$f35(tag, body) {
711
- return body ? [tag, body] : tag;
712
- }
713
- function peg$f36(start) {
714
- return skipTo(hooks.rawBodyEnd(input, start, rawName));
715
- }
716
- function peg$f37(start) {
717
- return skipEnd - offset();
718
- }
719
- function peg$f38(start, body, end) {
597
+ function peg$f14(start, body, end) {
720
598
  const loc = {
721
599
  start: { offset: start },
722
600
  end: { offset: start + body.length }
723
601
  };
724
602
  return [body ? lexeme("text", loc, { value: body }) : null, end];
725
603
  }
726
- function peg$f39() {
604
+ function peg$f15() {
727
605
  return offset();
728
606
  }
729
- function peg$f40(value) {
607
+ function peg$f16(value) {
730
608
  return lexeme("text", location(), { value });
731
609
  }
732
- function peg$f41(value) {
610
+ function peg$f17(value) {
733
611
  const node = lexeme("text", location(), { value });
734
612
  node.comment = true;
735
613
  return node;
736
614
  }
737
- function peg$f42(bs) {
615
+ function peg$f18(bs) {
738
616
  return bs.length % 2 === 1;
739
617
  }
740
- function peg$f43(bs, c) {
618
+ function peg$f19(bs, c) {
741
619
  return c;
742
620
  }
743
- function peg$f44(bs, brace) {
621
+ function peg$f20(bs, brace) {
744
622
  const loc = location();
745
623
  const next = input.charAt(loc.end.offset);
746
624
  if (textMode) {
@@ -757,76 +635,88 @@ function peg$parse(input, options) {
757
635
  escaped.escape = true;
758
636
  return bs.length > 1 ? [before, escaped] : escaped;
759
637
  }
760
- function peg$f45() {
638
+ function peg$f21() {
761
639
  return lexeme("text", location(), { value: LB });
762
640
  }
763
- function peg$f46() {
641
+ function peg$f22() {
764
642
  return !textMode;
765
643
  }
766
- function peg$f47() {
644
+ function peg$f23() {
767
645
  return lexeme("text", location(), { value: "<" });
768
646
  }
769
- function peg$f48() {
647
+ function peg$f24() {
770
648
  return lexeme("text", location(), { value: "[" });
771
649
  }
772
- function peg$f49() {
650
+ function peg$f25() {
773
651
  return !textMode;
774
652
  }
775
- function peg$f50(s, at, inner) {
776
- return withSelectors(lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator))), s);
653
+ function peg$f26(ss, s, at, inner) {
654
+ const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
655
+ link.selectorSpan = selectorSpan(s, ss, at);
656
+ return withSelectors(link, s);
777
657
  }
778
- function peg$f51() {
658
+ function peg$f27() {
779
659
  return !textMode;
780
660
  }
781
- function peg$f52() {
782
- fail("Unclosed link: [[ without ]]", location());
661
+ function peg$f28() {
662
+ fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
783
663
  }
784
- function peg$f53(parts) {
664
+ function peg$f29(parts) {
785
665
  return selectorsOf(parts);
786
666
  }
787
- function peg$f54() {
667
+ function peg$f30() {
788
668
  return NO_SELECTORS;
789
669
  }
790
- function peg$f55(s, end) {
670
+ function peg$f31(s, end) {
791
671
  return {
792
672
  ...s,
793
673
  end
794
674
  };
795
675
  }
796
- function peg$f56(prefix, name) {
676
+ function peg$f32(prefix, name) {
797
677
  return [prefix, name];
798
678
  }
799
- function peg$f57(s, sigil, name) {
800
- return withSelectors(lexeme("variable", location(), {
679
+ function peg$f33(ss, s, sigil, nameStart, name) {
680
+ const variable = lexeme("variable", location(), {
801
681
  name,
682
+ nameStart,
683
+ nameEnd: nameStart + name.length,
802
684
  scope: SIGIL_SCOPES$1[sigil]
803
- }), s);
804
- }
805
- function peg$f58(s, expression) {
806
- return withSelectors(lexeme("expression", location(), { expression }), s);
685
+ });
686
+ variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
687
+ return withSelectors(variable, s);
688
+ }
689
+ function peg$f34(ss, s, after, expression) {
690
+ const node = lexeme("expression", location(), {
691
+ expression,
692
+ expressionStart: after,
693
+ expressionEnd: after + expression.length
694
+ });
695
+ node.selectorSpan = selectorSpan(s, ss, after);
696
+ return withSelectors(node, s);
807
697
  }
808
- function peg$f59() {
809
- fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location());
698
+ function peg$f35() {
699
+ fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
810
700
  }
811
- function peg$f60(start) {
701
+ function peg$f36(start) {
812
702
  return skipTo(hooks.closeBrace(input, start, start));
813
703
  }
814
- function peg$f61(start) {
704
+ function peg$f37(start) {
815
705
  return skipEnd - offset();
816
706
  }
817
- function peg$f62(start, code) {
707
+ function peg$f38(start, code) {
818
708
  return code;
819
709
  }
820
- function peg$f63(s, start, close, name, nameEnd) {
710
+ function peg$f39(ss, s, start, close, name, nameEnd) {
821
711
  return skipTo(hooks.closeBrace(input, nameEnd, start));
822
712
  }
823
- function peg$f64(s, start, close, name, nameEnd) {
713
+ function peg$f40(ss, s, start, close, name, nameEnd) {
824
714
  return skipEnd - offset();
825
715
  }
826
- function peg$f65(s, start, close, name, nameEnd, args) {
716
+ function peg$f41(ss, s, start, close, name, nameEnd, args) {
827
717
  return args;
828
718
  }
829
- function peg$f66(s, start, close, name, nameEnd, tail) {
719
+ function peg$f42(ss, s, start, close, name, nameEnd, tail) {
830
720
  const loc = location();
831
721
  const lower = name.toLowerCase();
832
722
  const tag = lexeme("macro", loc, {
@@ -835,49 +725,48 @@ function peg$parse(input, options) {
835
725
  rawArgs: "",
836
726
  isClose: !!close
837
727
  });
838
- if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc);
728
+ tag.nameStart = nameEnd - name.length;
729
+ tag.nameEnd = nameEnd;
730
+ tag.selectorSpan = selectorSpan(s, ss, start);
731
+ if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
839
732
  tag.rawArgs = tail.trim();
733
+ tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
734
+ tag.argsEnd = tag.argsStart + tag.rawArgs.length;
840
735
  if (close) {
841
- if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc);
842
- if (tag.rawArgs) fail("A closing tag takes no arguments: " + LB + "/" + name + " " + tag.rawArgs + RB, loc);
736
+ if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc, "closer-with-selectors");
737
+ if (tag.rawArgs) fail("A closing tag takes no arguments: " + LB + "/" + name + " " + tag.rawArgs + RB, loc, "closer-with-arguments");
843
738
  tag.kind = "close";
844
739
  } else {
845
740
  withSelectors(tag, s);
846
- tag.kind = Object.prototype.hasOwnProperty.call(BRANCH_PARENT, lower) ? "branch" : "open";
741
+ tag.kind = Object.prototype.hasOwnProperty.call(BRANCH_PARENT$1, lower) ? "branch" : "open";
847
742
  }
848
743
  return tag;
849
744
  }
850
- function peg$f67(s) {
851
- fail("A closing tag starts with a letter after " + LB + "/", location());
745
+ function peg$f43(s) {
746
+ fail("A closing tag starts with a letter after " + LB + "/", location(), "invalid-closer");
852
747
  }
853
- function peg$f68(value) {
748
+ function peg$f44(value) {
854
749
  return EMAIL_AUTOLINK.test(value);
855
750
  }
856
- function peg$f69(value) {
751
+ function peg$f45(value) {
857
752
  return lexeme("text", location(), { value });
858
753
  }
859
- function peg$f70() {
860
- return !textMode;
861
- }
862
- function peg$f71(tag) {
863
- return VOID_TAGS.has(tag.lower);
864
- }
865
- function peg$f72(tag) {
866
- return null;
867
- }
868
- function peg$f73(tag, list, slash) {
754
+ function peg$f46(tagStart, tag, list, slash) {
869
755
  const lower = tag.toLowerCase();
870
756
  return lexeme("html", location(), {
871
757
  tag,
872
758
  lower,
759
+ tagNameStart: tagStart,
760
+ tagNameEnd: tagStart + tag.length,
873
761
  attributes: attrs(list),
762
+ attributeSpans: list,
874
763
  isClose: false,
875
764
  isSelfClose: !!slash || VOID_TAGS.has(lower)
876
765
  });
877
766
  }
878
- function peg$f74(tag, bad) {
767
+ function peg$f47(tag, bad) {
879
768
  const c = input.charAt(bad);
880
- if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location());
769
+ if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
881
770
  const at = {
882
771
  source: location().source,
883
772
  start: {
@@ -891,55 +780,86 @@ function peg$parse(input, options) {
891
780
  column: 0
892
781
  }
893
782
  };
894
- fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at);
783
+ fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
895
784
  }
896
- function peg$f75(tag) {
785
+ function peg$f48(tagStart, tag) {
897
786
  return lexeme("html", location(), {
898
787
  tag,
899
788
  lower: tag.toLowerCase(),
789
+ tagNameStart: tagStart,
790
+ tagNameEnd: tagStart + tag.length,
900
791
  attributes: {},
792
+ attributeSpans: [],
901
793
  isClose: true,
902
794
  isSelfClose: false
903
795
  });
904
796
  }
905
- function peg$f76(name) {
797
+ function peg$f49(nameStart, name) {
906
798
  attrCode = hooks.isCodeAttribute(name);
907
799
  return true;
908
800
  }
909
- function peg$f77(name, v) {
801
+ function peg$f50(nameStart, name, v) {
910
802
  return v;
911
803
  }
912
- function peg$f78(name, value) {
913
- return [name, value ?? ""];
804
+ function peg$f51(nameStart, name, value) {
805
+ const attribute = {
806
+ name,
807
+ value: value ? value.value : "",
808
+ nameStart,
809
+ nameEnd: nameStart + name.length
810
+ };
811
+ if (value) {
812
+ attribute.valueStart = value.start;
813
+ attribute.valueEnd = value.end;
814
+ if (value.quote) attribute.quote = value.quote;
815
+ }
816
+ return attribute;
914
817
  }
915
- function peg$f79(v) {
916
- return v;
818
+ function peg$f52(start, value, end) {
819
+ return {
820
+ value,
821
+ start,
822
+ end,
823
+ quote: "\""
824
+ };
917
825
  }
918
- function peg$f80(v) {
919
- return v;
826
+ function peg$f53(start, value, end) {
827
+ return {
828
+ value,
829
+ start,
830
+ end,
831
+ quote: "'"
832
+ };
920
833
  }
921
- function peg$f81(q) {
922
- fail("Unclosed attribute value: the " + q + " here has no closing " + q, location());
834
+ function peg$f54(q) {
835
+ fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
923
836
  }
924
- function peg$f82() {
837
+ function peg$f55(start, value, end) {
838
+ return {
839
+ value,
840
+ start,
841
+ end
842
+ };
843
+ }
844
+ function peg$f56() {
925
845
  return !attrCode;
926
846
  }
927
- function peg$f83(bs) {
847
+ function peg$f57(bs) {
928
848
  return bs.length % 2 === 1;
929
849
  }
930
- function peg$f84() {
850
+ function peg$f58() {
931
851
  return !attrCode;
932
852
  }
933
- function peg$f85(start, nameEnd) {
853
+ function peg$f59(start, nameEnd) {
934
854
  return skipTo(hooks.closeBrace(input, nameEnd, start));
935
855
  }
936
- function peg$f86(start, nameEnd) {
856
+ function peg$f60(start, nameEnd) {
937
857
  return skipEnd - offset();
938
858
  }
939
- function peg$f87() {
859
+ function peg$f61() {
940
860
  return !attrCode;
941
861
  }
942
- function peg$f88() {
862
+ function peg$f62() {
943
863
  return attrCode;
944
864
  }
945
865
  let peg$currPos = options.peg$currPos | 0;
@@ -1000,469 +920,60 @@ function peg$parse(input, options) {
1000
920
  else {
1001
921
  if (pos >= peg$posDetailsCache.length) p = peg$posDetailsCache.length - 1;
1002
922
  else {
1003
- p = pos;
1004
- while (!peg$posDetailsCache[--p]);
1005
- }
1006
- details = peg$posDetailsCache[p];
1007
- details = {
1008
- line: details.line,
1009
- column: details.column
1010
- };
1011
- while (p < pos) {
1012
- if (input.charCodeAt(p) === 10) {
1013
- details.line++;
1014
- details.column = 1;
1015
- } else details.column++;
1016
- p++;
1017
- }
1018
- peg$posDetailsCache[pos] = details;
1019
- return details;
1020
- }
1021
- }
1022
- function peg$computeLocation(startPos, endPos, offset) {
1023
- const startPosDetails = peg$computePosDetails(startPos);
1024
- const endPosDetails = peg$computePosDetails(endPos);
1025
- const res = {
1026
- source: peg$source,
1027
- start: {
1028
- offset: startPos,
1029
- line: startPosDetails.line,
1030
- column: startPosDetails.column
1031
- },
1032
- end: {
1033
- offset: endPos,
1034
- line: endPosDetails.line,
1035
- column: endPosDetails.column
1036
- }
1037
- };
1038
- if (offset && peg$source && typeof peg$source.offset === "function") {
1039
- res.start = peg$source.offset(res.start);
1040
- res.end = peg$source.offset(res.end);
1041
- }
1042
- return res;
1043
- }
1044
- function peg$fail(expected) {
1045
- if (peg$currPos < peg$maxFailPos) return;
1046
- if (peg$currPos > peg$maxFailPos) {
1047
- peg$maxFailPos = peg$currPos;
1048
- peg$maxFailExpected = [];
1049
- }
1050
- peg$maxFailExpected.push(expected);
1051
- }
1052
- function peg$buildSimpleError(message, location) {
1053
- return new peg$SyntaxError(message, null, null, location);
1054
- }
1055
- function peg$buildStructuredError(expected, found, location) {
1056
- return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1057
- }
1058
- function peg$parseMarkup() {
1059
- let s0, s1, s2;
1060
- s0 = peg$currPos;
1061
- s1 = peg$parseContent();
1062
- s2 = peg$parseTail();
1063
- if (s2 !== peg$FAILED) {
1064
- peg$savedPos = s0;
1065
- s0 = peg$f0(s1);
1066
- } else {
1067
- peg$currPos = s0;
1068
- s0 = peg$FAILED;
1069
- }
1070
- return s0;
1071
- }
1072
- function peg$parseTail() {
1073
- let s0, s1;
1074
- s0 = peg$currPos;
1075
- peg$silentFails++;
1076
- if (input.length > peg$currPos) {
1077
- s1 = input.charAt(peg$currPos);
1078
- peg$currPos++;
1079
- } else {
1080
- s1 = peg$FAILED;
1081
- if (peg$silentFails === 0) peg$fail(peg$e0);
1082
- }
1083
- peg$silentFails--;
1084
- if (s1 === peg$FAILED) s0 = void 0;
1085
- else {
1086
- peg$currPos = s0;
1087
- s0 = peg$FAILED;
1088
- }
1089
- if (s0 === peg$FAILED) {
1090
- s0 = peg$currPos;
1091
- s1 = peg$parseBranchTag();
1092
- if (s1 !== peg$FAILED) {
1093
- peg$savedPos = s0;
1094
- s1 = peg$f1(s1);
1095
- }
1096
- s0 = s1;
1097
- if (s0 === peg$FAILED) {
1098
- s0 = peg$currPos;
1099
- s1 = peg$parseCloseTag();
1100
- if (s1 !== peg$FAILED) {
1101
- peg$savedPos = s0;
1102
- s1 = peg$f2(s1);
1103
- }
1104
- s0 = s1;
1105
- }
1106
- }
1107
- return s0;
1108
- }
1109
- function peg$parseContent() {
1110
- let s0, s1, s2;
1111
- s0 = peg$currPos;
1112
- s1 = [];
1113
- s2 = peg$parseItem();
1114
- while (s2 !== peg$FAILED) {
1115
- s1.push(s2);
1116
- s2 = peg$parseItem();
1117
- }
1118
- peg$savedPos = s0;
1119
- s1 = peg$f3(s1);
1120
- s0 = s1;
1121
- return s0;
1122
- }
1123
- function peg$parseItem() {
1124
- let s0;
1125
- s0 = peg$parseTextRun();
1126
- if (s0 === peg$FAILED) {
1127
- s0 = peg$parseEscape();
1128
- if (s0 === peg$FAILED) {
1129
- s0 = peg$parseComment();
1130
- if (s0 === peg$FAILED) {
1131
- s0 = peg$parseLinkLexeme();
1132
- if (s0 === peg$FAILED) {
1133
- s0 = peg$parseEmailAutolink();
1134
- if (s0 === peg$FAILED) {
1135
- s0 = peg$parseHtmlElement();
1136
- if (s0 === peg$FAILED) {
1137
- s0 = peg$parseVoidCloser();
1138
- if (s0 === peg$FAILED) {
1139
- s0 = peg$parseValue();
1140
- if (s0 === peg$FAILED) {
1141
- s0 = peg$parseMacroElement();
1142
- if (s0 === peg$FAILED) s0 = peg$parseLiteral();
1143
- }
1144
- }
1145
- }
1146
- }
1147
- }
1148
- }
1149
- }
1150
- }
1151
- return s0;
1152
- }
1153
- function peg$parseMacroElement() {
1154
- let s0, s1, s2, s3, s4, s5;
1155
- s0 = peg$currPos;
1156
- s1 = peg$parseMacroTag();
1157
- if (s1 !== peg$FAILED) {
1158
- peg$savedPos = peg$currPos;
1159
- s2 = peg$f4(s1);
1160
- if (s2) s2 = void 0;
1161
- else s2 = peg$FAILED;
1162
- if (s2 !== peg$FAILED) {
1163
- s3 = peg$currPos;
1164
- peg$savedPos = peg$currPos;
1165
- s4 = peg$f5(s1);
1166
- if (s4) s4 = void 0;
1167
- else s4 = peg$FAILED;
1168
- if (s4 !== peg$FAILED) {
1169
- s5 = peg$parseRawBody();
1170
- if (s5 !== peg$FAILED) {
1171
- peg$savedPos = s3;
1172
- s3 = peg$f6(s1, s5);
1173
- } else {
1174
- peg$currPos = s3;
1175
- s3 = peg$FAILED;
1176
- }
1177
- } else {
1178
- peg$currPos = s3;
1179
- s3 = peg$FAILED;
1180
- }
1181
- if (s3 === peg$FAILED) {
1182
- s3 = peg$currPos;
1183
- peg$savedPos = peg$currPos;
1184
- s4 = peg$f7(s1);
1185
- if (s4) s4 = void 0;
1186
- else s4 = peg$FAILED;
1187
- if (s4 !== peg$FAILED) {
1188
- s5 = peg$parseBlockBody();
1189
- if (s5 !== peg$FAILED) {
1190
- peg$savedPos = s3;
1191
- s3 = peg$f8(s1, s5);
1192
- } else {
1193
- peg$currPos = s3;
1194
- s3 = peg$FAILED;
1195
- }
1196
- } else {
1197
- peg$currPos = s3;
1198
- s3 = peg$FAILED;
1199
- }
1200
- if (s3 === peg$FAILED) {
1201
- s3 = peg$currPos;
1202
- s4 = "";
1203
- peg$savedPos = s3;
1204
- s4 = peg$f9(s1);
1205
- s3 = s4;
1206
- }
1207
- }
1208
- if (s3 !== peg$FAILED) {
1209
- peg$savedPos = s0;
1210
- s0 = peg$f10(s1, s3);
1211
- } else {
1212
- peg$currPos = s0;
1213
- s0 = peg$FAILED;
1214
- }
1215
- } else {
1216
- peg$currPos = s0;
1217
- s0 = peg$FAILED;
1218
- }
1219
- } else {
1220
- peg$currPos = s0;
1221
- s0 = peg$FAILED;
1222
- }
1223
- return s0;
1224
- }
1225
- function peg$parseHtmlElement() {
1226
- let s0, s1, s2, s3, s4, s5;
1227
- s0 = peg$currPos;
1228
- peg$savedPos = peg$currPos;
1229
- s1 = peg$f11();
1230
- if (s1) s1 = void 0;
1231
- else s1 = peg$FAILED;
1232
- if (s1 !== peg$FAILED) {
1233
- s2 = peg$parseHtmlOpen();
1234
- if (s2 !== peg$FAILED) {
1235
- s3 = peg$currPos;
1236
- peg$savedPos = peg$currPos;
1237
- s4 = peg$f12(s2);
1238
- if (s4) s4 = void 0;
1239
- else s4 = peg$FAILED;
1240
- if (s4 !== peg$FAILED) {
1241
- s5 = peg$parseBlockBody();
1242
- if (s5 !== peg$FAILED) {
1243
- peg$savedPos = s3;
1244
- s3 = peg$f13(s2, s5);
1245
- } else {
1246
- peg$currPos = s3;
1247
- s3 = peg$FAILED;
1248
- }
1249
- } else {
1250
- peg$currPos = s3;
1251
- s3 = peg$FAILED;
1252
- }
1253
- if (s3 === peg$FAILED) s3 = null;
1254
- peg$savedPos = s0;
1255
- s0 = peg$f14(s2, s3);
1256
- } else {
1257
- peg$currPos = s0;
1258
- s0 = peg$FAILED;
1259
- }
1260
- } else {
1261
- peg$currPos = s0;
1262
- s0 = peg$FAILED;
1263
- }
1264
- return s0;
1265
- }
1266
- function peg$parseBlockBody() {
1267
- let s0, s1, s2, s3;
1268
- s0 = peg$currPos;
1269
- s1 = peg$parseContent();
1270
- if (s1 !== peg$FAILED) {
1271
- s2 = [];
1272
- s3 = peg$parseBranchPart();
1273
- while (s3 !== peg$FAILED) {
1274
- s2.push(s3);
1275
- s3 = peg$parseBranchPart();
1276
- }
1277
- s3 = peg$parseBlockEnd();
1278
- if (s3 !== peg$FAILED) {
1279
- peg$savedPos = s0;
1280
- s0 = peg$f15(s1, s2, s3);
1281
- } else {
1282
- peg$currPos = s0;
1283
- s0 = peg$FAILED;
1284
- }
1285
- } else {
1286
- peg$currPos = s0;
1287
- s0 = peg$FAILED;
1288
- }
1289
- return s0;
1290
- }
1291
- function peg$parseBranchPart() {
1292
- let s0, s1, s2;
1293
- s0 = peg$currPos;
1294
- s1 = peg$parseBranchTag();
1295
- if (s1 !== peg$FAILED) {
1296
- s2 = peg$parseContent();
1297
- if (s2 !== peg$FAILED) {
1298
- peg$savedPos = s0;
1299
- s0 = peg$f16(s1, s2);
1300
- } else {
1301
- peg$currPos = s0;
1302
- s0 = peg$FAILED;
1303
- }
1304
- } else {
1305
- peg$currPos = s0;
1306
- s0 = peg$FAILED;
1307
- }
1308
- return s0;
1309
- }
1310
- function peg$parseBlockEnd() {
1311
- let s0, s1, s2;
1312
- s0 = peg$parseCloseTag();
1313
- if (s0 === peg$FAILED) {
1314
- s0 = peg$currPos;
1315
- s1 = peg$currPos;
1316
- peg$silentFails++;
1317
- if (input.length > peg$currPos) {
1318
- s2 = input.charAt(peg$currPos);
1319
- peg$currPos++;
1320
- } else {
1321
- s2 = peg$FAILED;
1322
- if (peg$silentFails === 0) peg$fail(peg$e0);
1323
- }
1324
- peg$silentFails--;
1325
- if (s2 === peg$FAILED) s1 = void 0;
1326
- else {
1327
- peg$currPos = s1;
1328
- s1 = peg$FAILED;
923
+ p = pos;
924
+ while (!peg$posDetailsCache[--p]);
1329
925
  }
1330
- if (s1 !== peg$FAILED) {
1331
- peg$savedPos = s0;
1332
- s1 = peg$f17();
926
+ details = peg$posDetailsCache[p];
927
+ details = {
928
+ line: details.line,
929
+ column: details.column
930
+ };
931
+ while (p < pos) {
932
+ if (input.charCodeAt(p) === 10) {
933
+ details.line++;
934
+ details.column = 1;
935
+ } else details.column++;
936
+ p++;
1333
937
  }
1334
- s0 = s1;
938
+ peg$posDetailsCache[pos] = details;
939
+ return details;
1335
940
  }
1336
- return s0;
1337
941
  }
1338
- function peg$parseBranchTag() {
1339
- let s0, s1, s2;
1340
- s0 = peg$currPos;
1341
- s1 = peg$parseMacroTag();
1342
- if (s1 !== peg$FAILED) {
1343
- peg$savedPos = peg$currPos;
1344
- s2 = peg$f18(s1);
1345
- if (s2) s2 = void 0;
1346
- else s2 = peg$FAILED;
1347
- if (s2 !== peg$FAILED) {
1348
- peg$savedPos = s0;
1349
- s0 = peg$f19(s1);
1350
- } else {
1351
- peg$currPos = s0;
1352
- s0 = peg$FAILED;
942
+ function peg$computeLocation(startPos, endPos, offset) {
943
+ const startPosDetails = peg$computePosDetails(startPos);
944
+ const endPosDetails = peg$computePosDetails(endPos);
945
+ const res = {
946
+ source: peg$source,
947
+ start: {
948
+ offset: startPos,
949
+ line: startPosDetails.line,
950
+ column: startPosDetails.column
951
+ },
952
+ end: {
953
+ offset: endPos,
954
+ line: endPosDetails.line,
955
+ column: endPosDetails.column
1353
956
  }
1354
- } else {
1355
- peg$currPos = s0;
1356
- s0 = peg$FAILED;
957
+ };
958
+ if (offset && peg$source && typeof peg$source.offset === "function") {
959
+ res.start = peg$source.offset(res.start);
960
+ res.end = peg$source.offset(res.end);
1357
961
  }
1358
- return s0;
962
+ return res;
1359
963
  }
1360
- function peg$parseCloseTag() {
1361
- let s0, s1, s2;
1362
- s0 = peg$currPos;
1363
- s1 = peg$parseMacroTag();
1364
- if (s1 !== peg$FAILED) {
1365
- peg$savedPos = peg$currPos;
1366
- s2 = peg$f20(s1);
1367
- if (s2) s2 = void 0;
1368
- else s2 = peg$FAILED;
1369
- if (s2 !== peg$FAILED) {
1370
- peg$savedPos = s0;
1371
- s0 = peg$f21(s1);
1372
- } else {
1373
- peg$currPos = s0;
1374
- s0 = peg$FAILED;
1375
- }
1376
- } else {
1377
- peg$currPos = s0;
1378
- s0 = peg$FAILED;
1379
- }
1380
- if (s0 === peg$FAILED) {
1381
- s0 = peg$currPos;
1382
- peg$savedPos = peg$currPos;
1383
- s1 = peg$f22();
1384
- if (s1) s1 = void 0;
1385
- else s1 = peg$FAILED;
1386
- if (s1 !== peg$FAILED) {
1387
- s2 = peg$parseHtmlClose();
1388
- if (s2 !== peg$FAILED) {
1389
- peg$savedPos = s0;
1390
- s0 = peg$f23(s2);
1391
- } else {
1392
- peg$currPos = s0;
1393
- s0 = peg$FAILED;
1394
- }
1395
- } else {
1396
- peg$currPos = s0;
1397
- s0 = peg$FAILED;
1398
- }
964
+ function peg$fail(expected) {
965
+ if (peg$currPos < peg$maxFailPos) return;
966
+ if (peg$currPos > peg$maxFailPos) {
967
+ peg$maxFailPos = peg$currPos;
968
+ peg$maxFailExpected = [];
1399
969
  }
1400
- return s0;
970
+ peg$maxFailExpected.push(expected);
1401
971
  }
1402
- function peg$parseRawBody() {
1403
- let s0, s1, s2, s3, s4, s5, s6, s7;
1404
- s0 = peg$currPos;
1405
- s1 = peg$parseHere();
1406
- peg$savedPos = peg$currPos;
1407
- s2 = peg$f24(s1);
1408
- if (s2) s2 = void 0;
1409
- else s2 = peg$FAILED;
1410
- if (s2 !== peg$FAILED) {
1411
- s3 = peg$currPos;
1412
- s4 = peg$f25(s1);
1413
- s5 = peg$currPos;
1414
- s6 = [];
1415
- if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
1416
- else if (input.length > peg$currPos) {
1417
- s7 = input.charAt(peg$currPos);
1418
- peg$currPos++;
1419
- } else {
1420
- s7 = peg$FAILED;
1421
- if (peg$silentFails === 0) peg$fail(peg$e0);
1422
- }
1423
- while (s7 !== peg$FAILED) {
1424
- s6.push(s7);
1425
- if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
1426
- else if (input.length > peg$currPos) {
1427
- s7 = input.charAt(peg$currPos);
1428
- peg$currPos++;
1429
- } else {
1430
- s7 = peg$FAILED;
1431
- if (peg$silentFails === 0) peg$fail(peg$e0);
1432
- }
1433
- }
1434
- if (s6.length < (s4 | 0)) {
1435
- peg$currPos = s5;
1436
- s5 = peg$FAILED;
1437
- } else s5 = s6;
1438
- s4 = s5;
1439
- if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
1440
- else s3 = s4;
1441
- if (s3 !== peg$FAILED) {
1442
- s4 = peg$parseCloseTag();
1443
- if (s4 !== peg$FAILED) {
1444
- peg$savedPos = s0;
1445
- s0 = peg$f26(s1, s3, s4);
1446
- } else {
1447
- peg$currPos = s0;
1448
- s0 = peg$FAILED;
1449
- }
1450
- } else {
1451
- peg$currPos = s0;
1452
- s0 = peg$FAILED;
1453
- }
1454
- } else {
1455
- peg$currPos = s0;
1456
- s0 = peg$FAILED;
1457
- }
1458
- if (s0 === peg$FAILED) {
1459
- s0 = peg$currPos;
1460
- s1 = "";
1461
- peg$savedPos = s0;
1462
- s1 = peg$f27();
1463
- s0 = s1;
1464
- }
1465
- return s0;
972
+ function peg$buildSimpleError(message, location) {
973
+ return new peg$SyntaxError(message, null, null, location);
974
+ }
975
+ function peg$buildStructuredError(expected, found, location) {
976
+ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1466
977
  }
1467
978
  function peg$parseTokens() {
1468
979
  let s0, s1, s2;
@@ -1474,7 +985,7 @@ function peg$parse(input, options) {
1474
985
  s2 = peg$parseTokenItem();
1475
986
  }
1476
987
  peg$savedPos = s0;
1477
- s1 = peg$f28(s1);
988
+ s1 = peg$f0(s1);
1478
989
  s0 = s1;
1479
990
  return s0;
1480
991
  }
@@ -1492,14 +1003,14 @@ function peg$parse(input, options) {
1492
1003
  if (s0 === peg$FAILED) {
1493
1004
  s0 = peg$currPos;
1494
1005
  peg$savedPos = peg$currPos;
1495
- s1 = peg$f29();
1006
+ s1 = peg$f1();
1496
1007
  if (s1) s1 = void 0;
1497
1008
  else s1 = peg$FAILED;
1498
1009
  if (s1 !== peg$FAILED) {
1499
1010
  s2 = peg$parseHtmlOpen();
1500
1011
  if (s2 !== peg$FAILED) {
1501
1012
  peg$savedPos = s0;
1502
- s0 = peg$f30(s2);
1013
+ s0 = peg$f2(s2);
1503
1014
  } else {
1504
1015
  peg$currPos = s0;
1505
1016
  s0 = peg$FAILED;
@@ -1511,14 +1022,14 @@ function peg$parse(input, options) {
1511
1022
  if (s0 === peg$FAILED) {
1512
1023
  s0 = peg$currPos;
1513
1024
  peg$savedPos = peg$currPos;
1514
- s1 = peg$f31();
1025
+ s1 = peg$f3();
1515
1026
  if (s1) s1 = void 0;
1516
1027
  else s1 = peg$FAILED;
1517
1028
  if (s1 !== peg$FAILED) {
1518
1029
  s2 = peg$parseHtmlClose();
1519
1030
  if (s2 !== peg$FAILED) {
1520
1031
  peg$savedPos = s0;
1521
- s0 = peg$f32(s2);
1032
+ s0 = peg$f4(s2);
1522
1033
  } else {
1523
1034
  peg$currPos = s0;
1524
1035
  s0 = peg$FAILED;
@@ -1535,14 +1046,14 @@ function peg$parse(input, options) {
1535
1046
  if (s1 !== peg$FAILED) {
1536
1047
  s2 = peg$currPos;
1537
1048
  peg$savedPos = peg$currPos;
1538
- s3 = peg$f33(s1);
1049
+ s3 = peg$f5(s1);
1539
1050
  if (s3) s3 = void 0;
1540
1051
  else s3 = peg$FAILED;
1541
1052
  if (s3 !== peg$FAILED) {
1542
1053
  s4 = peg$parseRawTokens();
1543
1054
  if (s4 !== peg$FAILED) {
1544
1055
  peg$savedPos = s2;
1545
- s2 = peg$f34(s1, s4);
1056
+ s2 = peg$f6(s1, s4);
1546
1057
  } else {
1547
1058
  peg$currPos = s2;
1548
1059
  s2 = peg$FAILED;
@@ -1553,7 +1064,7 @@ function peg$parse(input, options) {
1553
1064
  }
1554
1065
  if (s2 === peg$FAILED) s2 = null;
1555
1066
  peg$savedPos = s0;
1556
- s0 = peg$f35(s1, s2);
1067
+ s0 = peg$f7(s1, s2);
1557
1068
  } else {
1558
1069
  peg$currPos = s0;
1559
1070
  s0 = peg$FAILED;
@@ -1569,17 +1080,59 @@ function peg$parse(input, options) {
1569
1080
  }
1570
1081
  return s0;
1571
1082
  }
1083
+ function peg$parseCloseTag() {
1084
+ let s0, s1, s2;
1085
+ s0 = peg$currPos;
1086
+ s1 = peg$parseMacroTag();
1087
+ if (s1 !== peg$FAILED) {
1088
+ peg$savedPos = peg$currPos;
1089
+ s2 = peg$f8(s1);
1090
+ if (s2) s2 = void 0;
1091
+ else s2 = peg$FAILED;
1092
+ if (s2 !== peg$FAILED) {
1093
+ peg$savedPos = s0;
1094
+ s0 = peg$f9(s1);
1095
+ } else {
1096
+ peg$currPos = s0;
1097
+ s0 = peg$FAILED;
1098
+ }
1099
+ } else {
1100
+ peg$currPos = s0;
1101
+ s0 = peg$FAILED;
1102
+ }
1103
+ if (s0 === peg$FAILED) {
1104
+ s0 = peg$currPos;
1105
+ peg$savedPos = peg$currPos;
1106
+ s1 = peg$f10();
1107
+ if (s1) s1 = void 0;
1108
+ else s1 = peg$FAILED;
1109
+ if (s1 !== peg$FAILED) {
1110
+ s2 = peg$parseHtmlClose();
1111
+ if (s2 !== peg$FAILED) {
1112
+ peg$savedPos = s0;
1113
+ s0 = peg$f11(s2);
1114
+ } else {
1115
+ peg$currPos = s0;
1116
+ s0 = peg$FAILED;
1117
+ }
1118
+ } else {
1119
+ peg$currPos = s0;
1120
+ s0 = peg$FAILED;
1121
+ }
1122
+ }
1123
+ return s0;
1124
+ }
1572
1125
  function peg$parseRawTokens() {
1573
1126
  let s0, s1, s2, s3, s4, s5, s6, s7;
1574
1127
  s0 = peg$currPos;
1575
1128
  s1 = peg$parseHere();
1576
1129
  peg$savedPos = peg$currPos;
1577
- s2 = peg$f36(s1);
1130
+ s2 = peg$f12(s1);
1578
1131
  if (s2) s2 = void 0;
1579
1132
  else s2 = peg$FAILED;
1580
1133
  if (s2 !== peg$FAILED) {
1581
1134
  s3 = peg$currPos;
1582
- s4 = peg$f37(s1);
1135
+ s4 = peg$f13(s1);
1583
1136
  s5 = peg$currPos;
1584
1137
  s6 = [];
1585
1138
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -1612,7 +1165,7 @@ function peg$parse(input, options) {
1612
1165
  s4 = peg$parseCloseTag();
1613
1166
  if (s4 !== peg$FAILED) {
1614
1167
  peg$savedPos = s0;
1615
- s0 = peg$f38(s1, s3, s4);
1168
+ s0 = peg$f14(s1, s3, s4);
1616
1169
  } else {
1617
1170
  peg$currPos = s0;
1618
1171
  s0 = peg$FAILED;
@@ -1632,7 +1185,7 @@ function peg$parse(input, options) {
1632
1185
  s0 = peg$currPos;
1633
1186
  s1 = "";
1634
1187
  peg$savedPos = s0;
1635
- s1 = peg$f39();
1188
+ s1 = peg$f15();
1636
1189
  s0 = s1;
1637
1190
  return s0;
1638
1191
  }
@@ -1661,7 +1214,7 @@ function peg$parse(input, options) {
1661
1214
  else s1 = s2;
1662
1215
  if (s1 !== peg$FAILED) {
1663
1216
  peg$savedPos = s0;
1664
- s1 = peg$f40(s1);
1217
+ s1 = peg$f16(s1);
1665
1218
  }
1666
1219
  s0 = s1;
1667
1220
  return s0;
@@ -1801,7 +1354,7 @@ function peg$parse(input, options) {
1801
1354
  else s1 = s2;
1802
1355
  if (s1 !== peg$FAILED) {
1803
1356
  peg$savedPos = s0;
1804
- s1 = peg$f41(s1);
1357
+ s1 = peg$f17(s1);
1805
1358
  }
1806
1359
  s0 = s1;
1807
1360
  return s0;
@@ -1834,7 +1387,7 @@ function peg$parse(input, options) {
1834
1387
  if (s1 !== peg$FAILED) {
1835
1388
  s2 = peg$currPos;
1836
1389
  peg$savedPos = peg$currPos;
1837
- s3 = peg$f42(s1);
1390
+ s3 = peg$f18(s1);
1838
1391
  if (s3) s3 = void 0;
1839
1392
  else s3 = peg$FAILED;
1840
1393
  if (s3 !== peg$FAILED) {
@@ -1846,7 +1399,7 @@ function peg$parse(input, options) {
1846
1399
  }
1847
1400
  if (s4 !== peg$FAILED) {
1848
1401
  peg$savedPos = s2;
1849
- s2 = peg$f43(s1, s4);
1402
+ s2 = peg$f19(s1, s4);
1850
1403
  } else {
1851
1404
  peg$currPos = s2;
1852
1405
  s2 = peg$FAILED;
@@ -1857,7 +1410,7 @@ function peg$parse(input, options) {
1857
1410
  }
1858
1411
  if (s2 === peg$FAILED) s2 = null;
1859
1412
  peg$savedPos = s0;
1860
- s0 = peg$f44(s1, s2);
1413
+ s0 = peg$f20(s1, s2);
1861
1414
  } else {
1862
1415
  peg$currPos = s0;
1863
1416
  s0 = peg$FAILED;
@@ -1905,7 +1458,7 @@ function peg$parse(input, options) {
1905
1458
  }
1906
1459
  if (s2 !== peg$FAILED) {
1907
1460
  peg$savedPos = s0;
1908
- s0 = peg$f45();
1461
+ s0 = peg$f21();
1909
1462
  } else {
1910
1463
  peg$currPos = s0;
1911
1464
  s0 = peg$FAILED;
@@ -1920,7 +1473,7 @@ function peg$parse(input, options) {
1920
1473
  peg$silentFails++;
1921
1474
  s2 = peg$currPos;
1922
1475
  peg$savedPos = peg$currPos;
1923
- s3 = peg$f46();
1476
+ s3 = peg$f22();
1924
1477
  if (s3) s3 = void 0;
1925
1478
  else s3 = peg$FAILED;
1926
1479
  if (s3 !== peg$FAILED) {
@@ -1952,7 +1505,7 @@ function peg$parse(input, options) {
1952
1505
  }
1953
1506
  if (s2 !== peg$FAILED) {
1954
1507
  peg$savedPos = s0;
1955
- s0 = peg$f47();
1508
+ s0 = peg$f23();
1956
1509
  } else {
1957
1510
  peg$currPos = s0;
1958
1511
  s0 = peg$FAILED;
@@ -1972,7 +1525,7 @@ function peg$parse(input, options) {
1972
1525
  }
1973
1526
  if (s1 !== peg$FAILED) {
1974
1527
  peg$savedPos = s0;
1975
- s1 = peg$f48();
1528
+ s1 = peg$f24();
1976
1529
  }
1977
1530
  s0 = s1;
1978
1531
  }
@@ -1980,10 +1533,10 @@ function peg$parse(input, options) {
1980
1533
  return s0;
1981
1534
  }
1982
1535
  function peg$parseLinkLexeme() {
1983
- let s0, s1, s2, s3, s4, s5, s6;
1536
+ let s0, s1, s2, s3, s4, s5, s6, s7;
1984
1537
  s0 = peg$currPos;
1985
1538
  peg$savedPos = peg$currPos;
1986
- s1 = peg$f49();
1539
+ s1 = peg$f25();
1987
1540
  if (s1) s1 = void 0;
1988
1541
  else s1 = peg$FAILED;
1989
1542
  if (s1 !== peg$FAILED) {
@@ -1995,22 +1548,23 @@ function peg$parse(input, options) {
1995
1548
  if (peg$silentFails === 0) peg$fail(peg$e12);
1996
1549
  }
1997
1550
  if (s2 !== peg$FAILED) {
1998
- s3 = peg$parseSelectors();
1999
- if (s3 !== peg$FAILED) {
2000
- s4 = peg$parseHere();
2001
- s5 = peg$currPos;
2002
- s6 = peg$parseLinkText();
2003
- s5 = input.substring(s5, peg$currPos);
1551
+ s3 = peg$parseHere();
1552
+ s4 = peg$parseSelectors();
1553
+ if (s4 !== peg$FAILED) {
1554
+ s5 = peg$parseHere();
1555
+ s6 = peg$currPos;
1556
+ s7 = peg$parseLinkText();
1557
+ s6 = input.substring(s6, peg$currPos);
2004
1558
  if (input.substr(peg$currPos, 2) === peg$c9) {
2005
- s6 = peg$c9;
1559
+ s7 = peg$c9;
2006
1560
  peg$currPos += 2;
2007
1561
  } else {
2008
- s6 = peg$FAILED;
1562
+ s7 = peg$FAILED;
2009
1563
  if (peg$silentFails === 0) peg$fail(peg$e13);
2010
1564
  }
2011
- if (s6 !== peg$FAILED) {
1565
+ if (s7 !== peg$FAILED) {
2012
1566
  peg$savedPos = s0;
2013
- s0 = peg$f50(s3, s4, s5);
1567
+ s0 = peg$f26(s3, s4, s5, s6);
2014
1568
  } else {
2015
1569
  peg$currPos = s0;
2016
1570
  s0 = peg$FAILED;
@@ -2030,7 +1584,7 @@ function peg$parse(input, options) {
2030
1584
  if (s0 === peg$FAILED) {
2031
1585
  s0 = peg$currPos;
2032
1586
  peg$savedPos = peg$currPos;
2033
- s1 = peg$f51();
1587
+ s1 = peg$f27();
2034
1588
  if (s1) s1 = void 0;
2035
1589
  else s1 = peg$FAILED;
2036
1590
  if (s1 !== peg$FAILED) {
@@ -2043,7 +1597,7 @@ function peg$parse(input, options) {
2043
1597
  }
2044
1598
  if (s2 !== peg$FAILED) {
2045
1599
  peg$savedPos = s0;
2046
- s0 = peg$f52();
1600
+ s0 = peg$f28();
2047
1601
  } else {
2048
1602
  peg$currPos = s0;
2049
1603
  s0 = peg$FAILED;
@@ -2167,7 +1721,7 @@ function peg$parse(input, options) {
2167
1721
  }
2168
1722
  if (s2 === peg$FAILED) s2 = null;
2169
1723
  peg$savedPos = s0;
2170
- s0 = peg$f53(s1);
1724
+ s0 = peg$f29(s1);
2171
1725
  } else {
2172
1726
  peg$currPos = s0;
2173
1727
  s0 = peg$FAILED;
@@ -2176,7 +1730,7 @@ function peg$parse(input, options) {
2176
1730
  s0 = peg$currPos;
2177
1731
  s1 = "";
2178
1732
  peg$savedPos = s0;
2179
- s1 = peg$f54();
1733
+ s1 = peg$f30();
2180
1734
  s0 = s1;
2181
1735
  }
2182
1736
  return s0;
@@ -2206,7 +1760,7 @@ function peg$parse(input, options) {
2206
1760
  }
2207
1761
  }
2208
1762
  peg$savedPos = s0;
2209
- s0 = peg$f55(s1, s2);
1763
+ s0 = peg$f31(s1, s2);
2210
1764
  } else {
2211
1765
  peg$currPos = s0;
2212
1766
  s0 = peg$FAILED;
@@ -2232,7 +1786,7 @@ function peg$parse(input, options) {
2232
1786
  }
2233
1787
  s2 = input.substring(s2, peg$currPos);
2234
1788
  peg$savedPos = s0;
2235
- s0 = peg$f56(s1, s2);
1789
+ s0 = peg$f32(s1, s2);
2236
1790
  } else {
2237
1791
  peg$currPos = s0;
2238
1792
  s0 = peg$FAILED;
@@ -2311,7 +1865,7 @@ function peg$parse(input, options) {
2311
1865
  return s0;
2312
1866
  }
2313
1867
  function peg$parseValue() {
2314
- let s0, s1, s2, s3, s4, s5, s6;
1868
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
2315
1869
  s0 = peg$currPos;
2316
1870
  if (input.charCodeAt(peg$currPos) === 123) {
2317
1871
  s1 = peg$c5;
@@ -2321,43 +1875,45 @@ function peg$parse(input, options) {
2321
1875
  if (peg$silentFails === 0) peg$fail(peg$e8);
2322
1876
  }
2323
1877
  if (s1 !== peg$FAILED) {
2324
- s2 = peg$parseSelectors();
2325
- if (s2 !== peg$FAILED) {
2326
- s3 = input.charAt(peg$currPos);
2327
- if (peg$r5.test(s3)) peg$currPos++;
1878
+ s2 = peg$parseHere();
1879
+ s3 = peg$parseSelectors();
1880
+ if (s3 !== peg$FAILED) {
1881
+ s4 = input.charAt(peg$currPos);
1882
+ if (peg$r5.test(s4)) peg$currPos++;
2328
1883
  else {
2329
- s3 = peg$FAILED;
1884
+ s4 = peg$FAILED;
2330
1885
  if (peg$silentFails === 0) peg$fail(peg$e17);
2331
1886
  }
2332
- if (s3 !== peg$FAILED) {
2333
- s4 = peg$currPos;
2334
- s5 = [];
2335
- s6 = input.charAt(peg$currPos);
2336
- if (peg$r6.test(s6)) peg$currPos++;
1887
+ if (s4 !== peg$FAILED) {
1888
+ s5 = peg$parseHere();
1889
+ s6 = peg$currPos;
1890
+ s7 = [];
1891
+ s8 = input.charAt(peg$currPos);
1892
+ if (peg$r6.test(s8)) peg$currPos++;
2337
1893
  else {
2338
- s6 = peg$FAILED;
1894
+ s8 = peg$FAILED;
2339
1895
  if (peg$silentFails === 0) peg$fail(peg$e18);
2340
1896
  }
2341
- while (s6 !== peg$FAILED) {
2342
- s5.push(s6);
2343
- s6 = input.charAt(peg$currPos);
2344
- if (peg$r6.test(s6)) peg$currPos++;
1897
+ while (s8 !== peg$FAILED) {
1898
+ s7.push(s8);
1899
+ s8 = input.charAt(peg$currPos);
1900
+ if (peg$r6.test(s8)) peg$currPos++;
2345
1901
  else {
2346
- s6 = peg$FAILED;
1902
+ s8 = peg$FAILED;
2347
1903
  if (peg$silentFails === 0) peg$fail(peg$e18);
2348
1904
  }
2349
1905
  }
2350
- s4 = input.substring(s4, peg$currPos);
1906
+ s6 = input.substring(s6, peg$currPos);
2351
1907
  if (input.charCodeAt(peg$currPos) === 125) {
2352
- s5 = peg$c11;
1908
+ s7 = peg$c11;
2353
1909
  peg$currPos++;
2354
1910
  } else {
2355
- s5 = peg$FAILED;
1911
+ s7 = peg$FAILED;
2356
1912
  if (peg$silentFails === 0) peg$fail(peg$e19);
2357
1913
  }
2358
- if (s5 !== peg$FAILED) {
1914
+ if (s7 !== peg$FAILED) {
2359
1915
  peg$savedPos = s0;
2360
- s0 = peg$f57(s2, s3, s4);
1916
+ s0 = peg$f33(s2, s3, s4, s5, s6);
2361
1917
  } else {
2362
1918
  peg$currPos = s0;
2363
1919
  s0 = peg$FAILED;
@@ -2384,34 +1940,36 @@ function peg$parse(input, options) {
2384
1940
  if (peg$silentFails === 0) peg$fail(peg$e8);
2385
1941
  }
2386
1942
  if (s1 !== peg$FAILED) {
2387
- s2 = peg$parseSelectors();
2388
- if (s2 !== peg$FAILED) {
2389
- s3 = peg$currPos;
1943
+ s2 = peg$parseHere();
1944
+ s3 = peg$parseSelectors();
1945
+ if (s3 !== peg$FAILED) {
1946
+ s4 = peg$parseHere();
1947
+ s5 = peg$currPos;
2390
1948
  peg$silentFails++;
2391
- s4 = input.charAt(peg$currPos);
2392
- if (peg$r7.test(s4)) peg$currPos++;
1949
+ s6 = input.charAt(peg$currPos);
1950
+ if (peg$r7.test(s6)) peg$currPos++;
2393
1951
  else {
2394
- s4 = peg$FAILED;
1952
+ s6 = peg$FAILED;
2395
1953
  if (peg$silentFails === 0) peg$fail(peg$e20);
2396
1954
  }
2397
1955
  peg$silentFails--;
2398
- if (s4 !== peg$FAILED) {
2399
- peg$currPos = s3;
2400
- s3 = void 0;
2401
- } else s3 = peg$FAILED;
2402
- if (s3 !== peg$FAILED) {
2403
- s4 = peg$parseCodeToBrace();
2404
- if (s4 !== peg$FAILED) {
1956
+ if (s6 !== peg$FAILED) {
1957
+ peg$currPos = s5;
1958
+ s5 = void 0;
1959
+ } else s5 = peg$FAILED;
1960
+ if (s5 !== peg$FAILED) {
1961
+ s6 = peg$parseCodeToBrace();
1962
+ if (s6 !== peg$FAILED) {
2405
1963
  if (input.charCodeAt(peg$currPos) === 125) {
2406
- s5 = peg$c11;
1964
+ s7 = peg$c11;
2407
1965
  peg$currPos++;
2408
1966
  } else {
2409
- s5 = peg$FAILED;
1967
+ s7 = peg$FAILED;
2410
1968
  if (peg$silentFails === 0) peg$fail(peg$e19);
2411
1969
  }
2412
- if (s5 !== peg$FAILED) {
1970
+ if (s7 !== peg$FAILED) {
2413
1971
  peg$savedPos = s0;
2414
- s0 = peg$f58(s2, s4);
1972
+ s0 = peg$f34(s2, s3, s4, s6);
2415
1973
  } else {
2416
1974
  peg$currPos = s0;
2417
1975
  s0 = peg$FAILED;
@@ -2459,7 +2017,7 @@ function peg$parse(input, options) {
2459
2017
  } else s3 = peg$FAILED;
2460
2018
  if (s3 !== peg$FAILED) {
2461
2019
  peg$savedPos = s0;
2462
- s0 = peg$f59();
2020
+ s0 = peg$f35();
2463
2021
  } else {
2464
2022
  peg$currPos = s0;
2465
2023
  s0 = peg$FAILED;
@@ -2481,12 +2039,12 @@ function peg$parse(input, options) {
2481
2039
  s0 = peg$currPos;
2482
2040
  s1 = peg$parseHere();
2483
2041
  peg$savedPos = peg$currPos;
2484
- s2 = peg$f60(s1);
2042
+ s2 = peg$f36(s1);
2485
2043
  if (s2) s2 = void 0;
2486
2044
  else s2 = peg$FAILED;
2487
2045
  if (s2 !== peg$FAILED) {
2488
2046
  s3 = peg$currPos;
2489
- s4 = peg$f61(s1);
2047
+ s4 = peg$f37(s1);
2490
2048
  s5 = peg$currPos;
2491
2049
  s6 = [];
2492
2050
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -2517,7 +2075,7 @@ function peg$parse(input, options) {
2517
2075
  else s3 = s4;
2518
2076
  if (s3 !== peg$FAILED) {
2519
2077
  peg$savedPos = s0;
2520
- s0 = peg$f62(s1, s3);
2078
+ s0 = peg$f38(s1, s3);
2521
2079
  } else {
2522
2080
  peg$currPos = s0;
2523
2081
  s0 = peg$FAILED;
@@ -2529,7 +2087,7 @@ function peg$parse(input, options) {
2529
2087
  return s0;
2530
2088
  }
2531
2089
  function peg$parseMacroTag() {
2532
- let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
2090
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
2533
2091
  s0 = peg$currPos;
2534
2092
  if (input.charCodeAt(peg$currPos) === 123) {
2535
2093
  s1 = peg$c5;
@@ -2539,82 +2097,83 @@ function peg$parse(input, options) {
2539
2097
  if (peg$silentFails === 0) peg$fail(peg$e8);
2540
2098
  }
2541
2099
  if (s1 !== peg$FAILED) {
2542
- s2 = peg$parseSelectors();
2543
- if (s2 !== peg$FAILED) {
2544
- s3 = peg$parseHere();
2100
+ s2 = peg$parseHere();
2101
+ s3 = peg$parseSelectors();
2102
+ if (s3 !== peg$FAILED) {
2103
+ s4 = peg$parseHere();
2545
2104
  if (input.charCodeAt(peg$currPos) === 47) {
2546
- s4 = peg$c12;
2105
+ s5 = peg$c12;
2547
2106
  peg$currPos++;
2548
2107
  } else {
2549
- s4 = peg$FAILED;
2108
+ s5 = peg$FAILED;
2550
2109
  if (peg$silentFails === 0) peg$fail(peg$e21);
2551
2110
  }
2552
- if (s4 === peg$FAILED) s4 = null;
2553
- s5 = peg$parseMacroName();
2554
- if (s5 !== peg$FAILED) {
2555
- s6 = peg$parseHere();
2556
- s7 = peg$currPos;
2111
+ if (s5 === peg$FAILED) s5 = null;
2112
+ s6 = peg$parseMacroName();
2113
+ if (s6 !== peg$FAILED) {
2114
+ s7 = peg$parseHere();
2115
+ s8 = peg$currPos;
2557
2116
  peg$savedPos = peg$currPos;
2558
- s8 = peg$f63(s2, s3, s4, s5, s6);
2559
- if (s8) s8 = void 0;
2560
- else s8 = peg$FAILED;
2561
- if (s8 !== peg$FAILED) {
2562
- s9 = peg$currPos;
2563
- s10 = peg$f64(s2, s3, s4, s5, s6);
2564
- s11 = peg$currPos;
2565
- s12 = [];
2566
- if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
2117
+ s9 = peg$f39(s2, s3, s4, s5, s6, s7);
2118
+ if (s9) s9 = void 0;
2119
+ else s9 = peg$FAILED;
2120
+ if (s9 !== peg$FAILED) {
2121
+ s10 = peg$currPos;
2122
+ s11 = peg$f40(s2, s3, s4, s5, s6, s7);
2123
+ s12 = peg$currPos;
2124
+ s13 = [];
2125
+ if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
2567
2126
  else if (input.length > peg$currPos) {
2568
- s13 = input.charAt(peg$currPos);
2127
+ s14 = input.charAt(peg$currPos);
2569
2128
  peg$currPos++;
2570
2129
  } else {
2571
- s13 = peg$FAILED;
2130
+ s14 = peg$FAILED;
2572
2131
  if (peg$silentFails === 0) peg$fail(peg$e0);
2573
2132
  }
2574
- while (s13 !== peg$FAILED) {
2575
- s12.push(s13);
2576
- if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
2133
+ while (s14 !== peg$FAILED) {
2134
+ s13.push(s14);
2135
+ if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
2577
2136
  else if (input.length > peg$currPos) {
2578
- s13 = input.charAt(peg$currPos);
2137
+ s14 = input.charAt(peg$currPos);
2579
2138
  peg$currPos++;
2580
2139
  } else {
2581
- s13 = peg$FAILED;
2140
+ s14 = peg$FAILED;
2582
2141
  if (peg$silentFails === 0) peg$fail(peg$e0);
2583
2142
  }
2584
2143
  }
2585
- if (s12.length < (s10 | 0)) {
2586
- peg$currPos = s11;
2587
- s11 = peg$FAILED;
2588
- } else s11 = s12;
2589
- s10 = s11;
2590
- if (s10 !== peg$FAILED) s9 = input.substring(s9, peg$currPos);
2591
- else s9 = s10;
2592
- if (s9 !== peg$FAILED) {
2144
+ if (s13.length < (s11 | 0)) {
2145
+ peg$currPos = s12;
2146
+ s12 = peg$FAILED;
2147
+ } else s12 = s13;
2148
+ s11 = s12;
2149
+ if (s11 !== peg$FAILED) s10 = input.substring(s10, peg$currPos);
2150
+ else s10 = s11;
2151
+ if (s10 !== peg$FAILED) {
2593
2152
  if (input.charCodeAt(peg$currPos) === 125) {
2594
- s10 = peg$c11;
2153
+ s11 = peg$c11;
2595
2154
  peg$currPos++;
2596
2155
  } else {
2597
- s10 = peg$FAILED;
2156
+ s11 = peg$FAILED;
2598
2157
  if (peg$silentFails === 0) peg$fail(peg$e19);
2599
2158
  }
2600
- if (s10 !== peg$FAILED) {
2601
- peg$savedPos = s7;
2602
- s7 = peg$f65(s2, s3, s4, s5, s6, s9);
2159
+ if (s11 !== peg$FAILED) {
2160
+ peg$savedPos = s8;
2161
+ s8 = peg$f41(s2, s3, s4, s5, s6, s7, s10);
2603
2162
  } else {
2604
- peg$currPos = s7;
2605
- s7 = peg$FAILED;
2163
+ peg$currPos = s8;
2164
+ s8 = peg$FAILED;
2606
2165
  }
2607
2166
  } else {
2608
- peg$currPos = s7;
2609
- s7 = peg$FAILED;
2167
+ peg$currPos = s8;
2168
+ s8 = peg$FAILED;
2610
2169
  }
2611
2170
  } else {
2612
- peg$currPos = s7;
2613
- s7 = peg$FAILED;
2171
+ peg$currPos = s8;
2172
+ s8 = peg$FAILED;
2614
2173
  }
2615
- if (s7 === peg$FAILED) s7 = null;
2174
+ if (s8 === peg$FAILED) s8 = null;
2616
2175
  peg$savedPos = s0;
2617
- s0 = peg$f66(s2, s3, s4, s5, s6, s7);
2176
+ s0 = peg$f42(s2, s3, s4, s5, s6, s7, s8);
2618
2177
  } else {
2619
2178
  peg$currPos = s0;
2620
2179
  s0 = peg$FAILED;
@@ -2648,7 +2207,7 @@ function peg$parse(input, options) {
2648
2207
  }
2649
2208
  if (s3 !== peg$FAILED) {
2650
2209
  peg$savedPos = s0;
2651
- s0 = peg$f67(s2);
2210
+ s0 = peg$f43(s2);
2652
2211
  } else {
2653
2212
  peg$currPos = s0;
2654
2213
  s0 = peg$FAILED;
@@ -2798,43 +2357,12 @@ function peg$parse(input, options) {
2798
2357
  else s1 = s2;
2799
2358
  if (s1 !== peg$FAILED) {
2800
2359
  peg$savedPos = peg$currPos;
2801
- s2 = peg$f68(s1);
2360
+ s2 = peg$f44(s1);
2802
2361
  if (s2) s2 = void 0;
2803
2362
  else s2 = peg$FAILED;
2804
2363
  if (s2 !== peg$FAILED) {
2805
2364
  peg$savedPos = s0;
2806
- s0 = peg$f69(s1);
2807
- } else {
2808
- peg$currPos = s0;
2809
- s0 = peg$FAILED;
2810
- }
2811
- } else {
2812
- peg$currPos = s0;
2813
- s0 = peg$FAILED;
2814
- }
2815
- return s0;
2816
- }
2817
- function peg$parseVoidCloser() {
2818
- let s0, s1, s2, s3;
2819
- s0 = peg$currPos;
2820
- peg$savedPos = peg$currPos;
2821
- s1 = peg$f70();
2822
- if (s1) s1 = void 0;
2823
- else s1 = peg$FAILED;
2824
- if (s1 !== peg$FAILED) {
2825
- s2 = peg$parseHtmlClose();
2826
- if (s2 !== peg$FAILED) {
2827
- peg$savedPos = peg$currPos;
2828
- s3 = peg$f71(s2);
2829
- if (s3) s3 = void 0;
2830
- else s3 = peg$FAILED;
2831
- if (s3 !== peg$FAILED) {
2832
- peg$savedPos = s0;
2833
- s0 = peg$f72(s2);
2834
- } else {
2835
- peg$currPos = s0;
2836
- s0 = peg$FAILED;
2837
- }
2365
+ s0 = peg$f45(s1);
2838
2366
  } else {
2839
2367
  peg$currPos = s0;
2840
2368
  s0 = peg$FAILED;
@@ -2846,7 +2374,7 @@ function peg$parse(input, options) {
2846
2374
  return s0;
2847
2375
  }
2848
2376
  function peg$parseHtmlOpen() {
2849
- let s0, s1, s2, s3, s4, s5, s6;
2377
+ let s0, s1, s2, s3, s4, s5, s6, s7;
2850
2378
  s0 = peg$currPos;
2851
2379
  if (input.charCodeAt(peg$currPos) === 60) {
2852
2380
  s1 = peg$c6;
@@ -2856,33 +2384,34 @@ function peg$parse(input, options) {
2856
2384
  if (peg$silentFails === 0) peg$fail(peg$e10);
2857
2385
  }
2858
2386
  if (s1 !== peg$FAILED) {
2859
- s2 = peg$parseTagName();
2860
- if (s2 !== peg$FAILED) {
2861
- s3 = [];
2862
- s4 = peg$parseAttribute();
2863
- while (s4 !== peg$FAILED) {
2864
- s3.push(s4);
2865
- s4 = peg$parseAttribute();
2387
+ s2 = peg$parseHere();
2388
+ s3 = peg$parseTagName();
2389
+ if (s3 !== peg$FAILED) {
2390
+ s4 = [];
2391
+ s5 = peg$parseAttribute();
2392
+ while (s5 !== peg$FAILED) {
2393
+ s4.push(s5);
2394
+ s5 = peg$parseAttribute();
2866
2395
  }
2867
- s4 = peg$parse_();
2396
+ s5 = peg$parse_();
2868
2397
  if (input.charCodeAt(peg$currPos) === 47) {
2869
- s5 = peg$c12;
2398
+ s6 = peg$c12;
2870
2399
  peg$currPos++;
2871
2400
  } else {
2872
- s5 = peg$FAILED;
2401
+ s6 = peg$FAILED;
2873
2402
  if (peg$silentFails === 0) peg$fail(peg$e21);
2874
2403
  }
2875
- if (s5 === peg$FAILED) s5 = null;
2404
+ if (s6 === peg$FAILED) s6 = null;
2876
2405
  if (input.charCodeAt(peg$currPos) === 62) {
2877
- s6 = peg$c1;
2406
+ s7 = peg$c1;
2878
2407
  peg$currPos++;
2879
2408
  } else {
2880
- s6 = peg$FAILED;
2409
+ s7 = peg$FAILED;
2881
2410
  if (peg$silentFails === 0) peg$fail(peg$e3);
2882
2411
  }
2883
- if (s6 !== peg$FAILED) {
2412
+ if (s7 !== peg$FAILED) {
2884
2413
  peg$savedPos = s0;
2885
- s0 = peg$f73(s2, s3, s5);
2414
+ s0 = peg$f46(s2, s3, s4, s6);
2886
2415
  } else {
2887
2416
  peg$currPos = s0;
2888
2417
  s0 = peg$FAILED;
@@ -2947,7 +2476,7 @@ function peg$parse(input, options) {
2947
2476
  s5 = peg$parse_();
2948
2477
  s6 = peg$parseHere();
2949
2478
  peg$savedPos = s0;
2950
- s0 = peg$f74(s2, s6);
2479
+ s0 = peg$f47(s2, s6);
2951
2480
  } else {
2952
2481
  peg$currPos = s0;
2953
2482
  s0 = peg$FAILED;
@@ -2964,7 +2493,7 @@ function peg$parse(input, options) {
2964
2493
  return s0;
2965
2494
  }
2966
2495
  function peg$parseHtmlClose() {
2967
- let s0, s1, s2, s4;
2496
+ let s0, s1, s2, s3, s5;
2968
2497
  s0 = peg$currPos;
2969
2498
  if (input.substr(peg$currPos, 2) === peg$c14) {
2970
2499
  s1 = peg$c14;
@@ -2974,19 +2503,20 @@ function peg$parse(input, options) {
2974
2503
  if (peg$silentFails === 0) peg$fail(peg$e28);
2975
2504
  }
2976
2505
  if (s1 !== peg$FAILED) {
2977
- s2 = peg$parseTagName();
2978
- if (s2 !== peg$FAILED) {
2506
+ s2 = peg$parseHere();
2507
+ s3 = peg$parseTagName();
2508
+ if (s3 !== peg$FAILED) {
2979
2509
  peg$parse_();
2980
2510
  if (input.charCodeAt(peg$currPos) === 62) {
2981
- s4 = peg$c1;
2511
+ s5 = peg$c1;
2982
2512
  peg$currPos++;
2983
2513
  } else {
2984
- s4 = peg$FAILED;
2514
+ s5 = peg$FAILED;
2985
2515
  if (peg$silentFails === 0) peg$fail(peg$e3);
2986
2516
  }
2987
- if (s4 !== peg$FAILED) {
2517
+ if (s5 !== peg$FAILED) {
2988
2518
  peg$savedPos = s0;
2989
- s0 = peg$f75(s2);
2519
+ s0 = peg$f48(s2, s3);
2990
2520
  } else {
2991
2521
  peg$currPos = s0;
2992
2522
  s0 = peg$FAILED;
@@ -3039,117 +2569,118 @@ function peg$parse(input, options) {
3039
2569
  return s0;
3040
2570
  }
3041
2571
  function peg$parseAttribute() {
3042
- let s0, s2, s3, s4, s5, s6, s8;
2572
+ let s0, s2, s3, s4, s5, s6, s7, s9;
3043
2573
  s0 = peg$currPos;
3044
2574
  peg$parse_();
3045
- s2 = peg$currPos;
3046
- s3 = [];
3047
- s4 = peg$currPos;
2575
+ s2 = peg$parseHere();
2576
+ s3 = peg$currPos;
2577
+ s4 = [];
3048
2578
  s5 = peg$currPos;
2579
+ s6 = peg$currPos;
3049
2580
  peg$silentFails++;
3050
- s6 = input.charAt(peg$currPos);
3051
- if (peg$r14.test(s6)) peg$currPos++;
2581
+ s7 = input.charAt(peg$currPos);
2582
+ if (peg$r14.test(s7)) peg$currPos++;
3052
2583
  else {
3053
- s6 = peg$FAILED;
2584
+ s7 = peg$FAILED;
3054
2585
  if (peg$silentFails === 0) peg$fail(peg$e30);
3055
2586
  }
3056
2587
  peg$silentFails--;
3057
- if (s6 === peg$FAILED) s5 = void 0;
2588
+ if (s7 === peg$FAILED) s6 = void 0;
3058
2589
  else {
3059
- peg$currPos = s5;
3060
- s5 = peg$FAILED;
2590
+ peg$currPos = s6;
2591
+ s6 = peg$FAILED;
3061
2592
  }
3062
- if (s5 !== peg$FAILED) {
2593
+ if (s6 !== peg$FAILED) {
3063
2594
  if (input.length > peg$currPos) {
3064
- s6 = input.charAt(peg$currPos);
2595
+ s7 = input.charAt(peg$currPos);
3065
2596
  peg$currPos++;
3066
2597
  } else {
3067
- s6 = peg$FAILED;
2598
+ s7 = peg$FAILED;
3068
2599
  if (peg$silentFails === 0) peg$fail(peg$e0);
3069
2600
  }
3070
- if (s6 !== peg$FAILED) {
3071
- s5 = [s5, s6];
3072
- s4 = s5;
2601
+ if (s7 !== peg$FAILED) {
2602
+ s6 = [s6, s7];
2603
+ s5 = s6;
3073
2604
  } else {
3074
- peg$currPos = s4;
3075
- s4 = peg$FAILED;
2605
+ peg$currPos = s5;
2606
+ s5 = peg$FAILED;
3076
2607
  }
3077
2608
  } else {
3078
- peg$currPos = s4;
3079
- s4 = peg$FAILED;
2609
+ peg$currPos = s5;
2610
+ s5 = peg$FAILED;
3080
2611
  }
3081
- if (s4 !== peg$FAILED) while (s4 !== peg$FAILED) {
3082
- s3.push(s4);
3083
- s4 = peg$currPos;
2612
+ if (s5 !== peg$FAILED) while (s5 !== peg$FAILED) {
2613
+ s4.push(s5);
3084
2614
  s5 = peg$currPos;
2615
+ s6 = peg$currPos;
3085
2616
  peg$silentFails++;
3086
- s6 = input.charAt(peg$currPos);
3087
- if (peg$r14.test(s6)) peg$currPos++;
2617
+ s7 = input.charAt(peg$currPos);
2618
+ if (peg$r14.test(s7)) peg$currPos++;
3088
2619
  else {
3089
- s6 = peg$FAILED;
2620
+ s7 = peg$FAILED;
3090
2621
  if (peg$silentFails === 0) peg$fail(peg$e30);
3091
2622
  }
3092
2623
  peg$silentFails--;
3093
- if (s6 === peg$FAILED) s5 = void 0;
2624
+ if (s7 === peg$FAILED) s6 = void 0;
3094
2625
  else {
3095
- peg$currPos = s5;
3096
- s5 = peg$FAILED;
2626
+ peg$currPos = s6;
2627
+ s6 = peg$FAILED;
3097
2628
  }
3098
- if (s5 !== peg$FAILED) {
2629
+ if (s6 !== peg$FAILED) {
3099
2630
  if (input.length > peg$currPos) {
3100
- s6 = input.charAt(peg$currPos);
2631
+ s7 = input.charAt(peg$currPos);
3101
2632
  peg$currPos++;
3102
2633
  } else {
3103
- s6 = peg$FAILED;
2634
+ s7 = peg$FAILED;
3104
2635
  if (peg$silentFails === 0) peg$fail(peg$e0);
3105
2636
  }
3106
- if (s6 !== peg$FAILED) {
3107
- s5 = [s5, s6];
3108
- s4 = s5;
2637
+ if (s7 !== peg$FAILED) {
2638
+ s6 = [s6, s7];
2639
+ s5 = s6;
3109
2640
  } else {
3110
- peg$currPos = s4;
3111
- s4 = peg$FAILED;
2641
+ peg$currPos = s5;
2642
+ s5 = peg$FAILED;
3112
2643
  }
3113
2644
  } else {
3114
- peg$currPos = s4;
3115
- s4 = peg$FAILED;
2645
+ peg$currPos = s5;
2646
+ s5 = peg$FAILED;
3116
2647
  }
3117
2648
  }
3118
- else s3 = peg$FAILED;
3119
- if (s3 !== peg$FAILED) s2 = input.substring(s2, peg$currPos);
3120
- else s2 = s3;
3121
- if (s2 !== peg$FAILED) {
2649
+ else s4 = peg$FAILED;
2650
+ if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
2651
+ else s3 = s4;
2652
+ if (s3 !== peg$FAILED) {
3122
2653
  peg$savedPos = peg$currPos;
3123
- s3 = peg$f76(s2);
3124
- if (s3) s3 = void 0;
3125
- else s3 = peg$FAILED;
3126
- if (s3 !== peg$FAILED) {
3127
- s4 = peg$currPos;
3128
- s5 = peg$parse_();
2654
+ s4 = peg$f49(s2, s3);
2655
+ if (s4) s4 = void 0;
2656
+ else s4 = peg$FAILED;
2657
+ if (s4 !== peg$FAILED) {
2658
+ s5 = peg$currPos;
2659
+ s6 = peg$parse_();
3129
2660
  if (input.charCodeAt(peg$currPos) === 61) {
3130
- s6 = peg$c15;
2661
+ s7 = peg$c15;
3131
2662
  peg$currPos++;
3132
2663
  } else {
3133
- s6 = peg$FAILED;
2664
+ s7 = peg$FAILED;
3134
2665
  if (peg$silentFails === 0) peg$fail(peg$e31);
3135
2666
  }
3136
- if (s6 !== peg$FAILED) {
2667
+ if (s7 !== peg$FAILED) {
3137
2668
  peg$parse_();
3138
- s8 = peg$parseAttrValue();
3139
- if (s8 !== peg$FAILED) {
3140
- peg$savedPos = s4;
3141
- s4 = peg$f77(s2, s8);
2669
+ s9 = peg$parseAttrValue();
2670
+ if (s9 !== peg$FAILED) {
2671
+ peg$savedPos = s5;
2672
+ s5 = peg$f50(s2, s3, s9);
3142
2673
  } else {
3143
- peg$currPos = s4;
3144
- s4 = peg$FAILED;
2674
+ peg$currPos = s5;
2675
+ s5 = peg$FAILED;
3145
2676
  }
3146
2677
  } else {
3147
- peg$currPos = s4;
3148
- s4 = peg$FAILED;
2678
+ peg$currPos = s5;
2679
+ s5 = peg$FAILED;
3149
2680
  }
3150
- if (s4 === peg$FAILED) s4 = null;
2681
+ if (s5 === peg$FAILED) s5 = null;
3151
2682
  peg$savedPos = s0;
3152
- s0 = peg$f78(s2, s4);
2683
+ s0 = peg$f51(s2, s3, s5);
3153
2684
  } else {
3154
2685
  peg$currPos = s0;
3155
2686
  s0 = peg$FAILED;
@@ -3161,7 +2692,7 @@ function peg$parse(input, options) {
3161
2692
  return s0;
3162
2693
  }
3163
2694
  function peg$parseAttrValue() {
3164
- let s0, s1, s2, s3, s4;
2695
+ let s0, s1, s2, s3, s4, s5;
3165
2696
  s0 = peg$currPos;
3166
2697
  if (input.charCodeAt(peg$currPos) === 34) {
3167
2698
  s1 = peg$c16;
@@ -3171,40 +2702,42 @@ function peg$parse(input, options) {
3171
2702
  if (peg$silentFails === 0) peg$fail(peg$e32);
3172
2703
  }
3173
2704
  if (s1 !== peg$FAILED) {
3174
- s2 = peg$currPos;
3175
- s3 = [];
3176
- s4 = peg$parseValuePart();
3177
- if (s4 === peg$FAILED) {
3178
- s4 = input.charAt(peg$currPos);
3179
- if (peg$r15.test(s4)) peg$currPos++;
2705
+ s2 = peg$parseHere();
2706
+ s3 = peg$currPos;
2707
+ s4 = [];
2708
+ s5 = peg$parseValuePart();
2709
+ if (s5 === peg$FAILED) {
2710
+ s5 = input.charAt(peg$currPos);
2711
+ if (peg$r15.test(s5)) peg$currPos++;
3180
2712
  else {
3181
- s4 = peg$FAILED;
2713
+ s5 = peg$FAILED;
3182
2714
  if (peg$silentFails === 0) peg$fail(peg$e33);
3183
2715
  }
3184
2716
  }
3185
- while (s4 !== peg$FAILED) {
3186
- s3.push(s4);
3187
- s4 = peg$parseValuePart();
3188
- if (s4 === peg$FAILED) {
3189
- s4 = input.charAt(peg$currPos);
3190
- if (peg$r15.test(s4)) peg$currPos++;
2717
+ while (s5 !== peg$FAILED) {
2718
+ s4.push(s5);
2719
+ s5 = peg$parseValuePart();
2720
+ if (s5 === peg$FAILED) {
2721
+ s5 = input.charAt(peg$currPos);
2722
+ if (peg$r15.test(s5)) peg$currPos++;
3191
2723
  else {
3192
- s4 = peg$FAILED;
2724
+ s5 = peg$FAILED;
3193
2725
  if (peg$silentFails === 0) peg$fail(peg$e33);
3194
2726
  }
3195
2727
  }
3196
2728
  }
3197
- s2 = input.substring(s2, peg$currPos);
2729
+ s3 = input.substring(s3, peg$currPos);
2730
+ s4 = peg$parseHere();
3198
2731
  if (input.charCodeAt(peg$currPos) === 34) {
3199
- s3 = peg$c16;
2732
+ s5 = peg$c16;
3200
2733
  peg$currPos++;
3201
2734
  } else {
3202
- s3 = peg$FAILED;
2735
+ s5 = peg$FAILED;
3203
2736
  if (peg$silentFails === 0) peg$fail(peg$e32);
3204
2737
  }
3205
- if (s3 !== peg$FAILED) {
2738
+ if (s5 !== peg$FAILED) {
3206
2739
  peg$savedPos = s0;
3207
- s0 = peg$f79(s2);
2740
+ s0 = peg$f52(s2, s3, s4);
3208
2741
  } else {
3209
2742
  peg$currPos = s0;
3210
2743
  s0 = peg$FAILED;
@@ -3223,40 +2756,42 @@ function peg$parse(input, options) {
3223
2756
  if (peg$silentFails === 0) peg$fail(peg$e34);
3224
2757
  }
3225
2758
  if (s1 !== peg$FAILED) {
3226
- s2 = peg$currPos;
3227
- s3 = [];
3228
- s4 = peg$parseValuePart();
3229
- if (s4 === peg$FAILED) {
3230
- s4 = input.charAt(peg$currPos);
3231
- if (peg$r16.test(s4)) peg$currPos++;
2759
+ s2 = peg$parseHere();
2760
+ s3 = peg$currPos;
2761
+ s4 = [];
2762
+ s5 = peg$parseValuePart();
2763
+ if (s5 === peg$FAILED) {
2764
+ s5 = input.charAt(peg$currPos);
2765
+ if (peg$r16.test(s5)) peg$currPos++;
3232
2766
  else {
3233
- s4 = peg$FAILED;
2767
+ s5 = peg$FAILED;
3234
2768
  if (peg$silentFails === 0) peg$fail(peg$e35);
3235
2769
  }
3236
2770
  }
3237
- while (s4 !== peg$FAILED) {
3238
- s3.push(s4);
3239
- s4 = peg$parseValuePart();
3240
- if (s4 === peg$FAILED) {
3241
- s4 = input.charAt(peg$currPos);
3242
- if (peg$r16.test(s4)) peg$currPos++;
2771
+ while (s5 !== peg$FAILED) {
2772
+ s4.push(s5);
2773
+ s5 = peg$parseValuePart();
2774
+ if (s5 === peg$FAILED) {
2775
+ s5 = input.charAt(peg$currPos);
2776
+ if (peg$r16.test(s5)) peg$currPos++;
3243
2777
  else {
3244
- s4 = peg$FAILED;
2778
+ s5 = peg$FAILED;
3245
2779
  if (peg$silentFails === 0) peg$fail(peg$e35);
3246
2780
  }
3247
2781
  }
3248
2782
  }
3249
- s2 = input.substring(s2, peg$currPos);
2783
+ s3 = input.substring(s3, peg$currPos);
2784
+ s4 = peg$parseHere();
3250
2785
  if (input.charCodeAt(peg$currPos) === 39) {
3251
- s3 = peg$c17;
2786
+ s5 = peg$c17;
3252
2787
  peg$currPos++;
3253
2788
  } else {
3254
- s3 = peg$FAILED;
2789
+ s5 = peg$FAILED;
3255
2790
  if (peg$silentFails === 0) peg$fail(peg$e34);
3256
2791
  }
3257
- if (s3 !== peg$FAILED) {
2792
+ if (s5 !== peg$FAILED) {
3258
2793
  peg$savedPos = s0;
3259
- s0 = peg$f80(s2);
2794
+ s0 = peg$f53(s2, s3, s4);
3260
2795
  } else {
3261
2796
  peg$currPos = s0;
3262
2797
  s0 = peg$FAILED;
@@ -3275,28 +2810,33 @@ function peg$parse(input, options) {
3275
2810
  }
3276
2811
  if (s1 !== peg$FAILED) {
3277
2812
  peg$savedPos = s0;
3278
- s1 = peg$f81(s1);
2813
+ s1 = peg$f54(s1);
3279
2814
  }
3280
2815
  s0 = s1;
3281
2816
  if (s0 === peg$FAILED) {
3282
2817
  s0 = peg$currPos;
3283
- s1 = [];
3284
- s2 = input.charAt(peg$currPos);
3285
- if (peg$r18.test(s2)) peg$currPos++;
2818
+ s1 = peg$parseHere();
2819
+ s2 = peg$currPos;
2820
+ s3 = [];
2821
+ s4 = input.charAt(peg$currPos);
2822
+ if (peg$r18.test(s4)) peg$currPos++;
3286
2823
  else {
3287
- s2 = peg$FAILED;
2824
+ s4 = peg$FAILED;
3288
2825
  if (peg$silentFails === 0) peg$fail(peg$e37);
3289
2826
  }
3290
- while (s2 !== peg$FAILED) {
3291
- s1.push(s2);
3292
- s2 = input.charAt(peg$currPos);
3293
- if (peg$r18.test(s2)) peg$currPos++;
2827
+ while (s4 !== peg$FAILED) {
2828
+ s3.push(s4);
2829
+ s4 = input.charAt(peg$currPos);
2830
+ if (peg$r18.test(s4)) peg$currPos++;
3294
2831
  else {
3295
- s2 = peg$FAILED;
2832
+ s4 = peg$FAILED;
3296
2833
  if (peg$silentFails === 0) peg$fail(peg$e37);
3297
2834
  }
3298
2835
  }
3299
- s0 = input.substring(s0, peg$currPos);
2836
+ s2 = input.substring(s2, peg$currPos);
2837
+ s3 = peg$parseHere();
2838
+ peg$savedPos = s0;
2839
+ s0 = peg$f55(s1, s2, s3);
3300
2840
  }
3301
2841
  }
3302
2842
  }
@@ -3306,7 +2846,7 @@ function peg$parse(input, options) {
3306
2846
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
3307
2847
  s0 = peg$currPos;
3308
2848
  peg$savedPos = peg$currPos;
3309
- s1 = peg$f82();
2849
+ s1 = peg$f56();
3310
2850
  if (s1) s1 = void 0;
3311
2851
  else s1 = peg$FAILED;
3312
2852
  if (s1 !== peg$FAILED) {
@@ -3335,7 +2875,7 @@ function peg$parse(input, options) {
3335
2875
  if (s2 !== peg$FAILED) {
3336
2876
  s3 = peg$currPos;
3337
2877
  peg$savedPos = peg$currPos;
3338
- s4 = peg$f83(s2);
2878
+ s4 = peg$f57(s2);
3339
2879
  if (s4) s4 = void 0;
3340
2880
  else s4 = peg$FAILED;
3341
2881
  if (s4 !== peg$FAILED) {
@@ -3374,7 +2914,7 @@ function peg$parse(input, options) {
3374
2914
  if (s0 === peg$FAILED) {
3375
2915
  s0 = peg$currPos;
3376
2916
  peg$savedPos = peg$currPos;
3377
- s1 = peg$f84();
2917
+ s1 = peg$f58();
3378
2918
  if (s1) s1 = void 0;
3379
2919
  else s1 = peg$FAILED;
3380
2920
  if (s1 !== peg$FAILED) {
@@ -3401,12 +2941,12 @@ function peg$parse(input, options) {
3401
2941
  if (s6 !== peg$FAILED) {
3402
2942
  s7 = peg$parseHere();
3403
2943
  peg$savedPos = peg$currPos;
3404
- s8 = peg$f85(s4, s7);
2944
+ s8 = peg$f59(s4, s7);
3405
2945
  if (s8) s8 = void 0;
3406
2946
  else s8 = peg$FAILED;
3407
2947
  if (s8 !== peg$FAILED) {
3408
2948
  s9 = peg$currPos;
3409
- s10 = peg$f86(s4, s7);
2949
+ s10 = peg$f60(s4, s7);
3410
2950
  s11 = peg$currPos;
3411
2951
  s12 = [];
3412
2952
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -3488,7 +3028,7 @@ function peg$parse(input, options) {
3488
3028
  if (s0 === peg$FAILED) {
3489
3029
  s0 = peg$currPos;
3490
3030
  peg$savedPos = peg$currPos;
3491
- s1 = peg$f87();
3031
+ s1 = peg$f61();
3492
3032
  if (s1) s1 = void 0;
3493
3033
  else s1 = peg$FAILED;
3494
3034
  if (s1 !== peg$FAILED) {
@@ -3579,7 +3119,7 @@ function peg$parse(input, options) {
3579
3119
  if (s0 === peg$FAILED) {
3580
3120
  s0 = peg$currPos;
3581
3121
  peg$savedPos = peg$currPos;
3582
- s1 = peg$f88();
3122
+ s1 = peg$f62();
3583
3123
  if (s1) s1 = void 0;
3584
3124
  else s1 = peg$FAILED;
3585
3125
  if (s1 !== peg$FAILED) {
@@ -3694,17 +3234,35 @@ function peg$parse(input, options) {
3694
3234
  }
3695
3235
  return -1;
3696
3236
  }
3237
+ /**
3238
+ * Where the selectors `s` are written, from `start` up to `after`, the end of
3239
+ * what Selectors consumed (the one space that may follow them is not part of
3240
+ * them): the fields of a token; none without selectors.
3241
+ */
3242
+ function selectorSpan(s, start, after) {
3243
+ if (s === NO_SELECTORS) return {};
3244
+ return {
3245
+ selectorsStart: start,
3246
+ selectorsEnd: input.charAt(after - 1) === " " ? after - 1 : after
3247
+ };
3248
+ }
3697
3249
  function skipTo(end) {
3698
3250
  skipEnd = end;
3699
3251
  return end >= 0;
3700
3252
  }
3701
- function fail(message, loc) {
3702
- error(message, loc);
3253
+ /** Fail with `message` at `loc`; `code` tells the kind of error apart (MarkupError). */
3254
+ function fail(message, loc, code) {
3255
+ try {
3256
+ error(message, loc);
3257
+ } catch (e) {
3258
+ e.code = code;
3259
+ throw e;
3260
+ }
3703
3261
  }
3704
3262
  function attrs(list) {
3705
3263
  const attributes = {};
3706
3264
  const seen = /* @__PURE__ */ new Set();
3707
- for (const [name, value] of list) {
3265
+ for (const { name, value } of list) {
3708
3266
  const lower = name.toLowerCase();
3709
3267
  if (seen.has(lower)) continue;
3710
3268
  seen.add(lower);
@@ -3717,38 +3275,6 @@ function peg$parse(input, options) {
3717
3275
  }
3718
3276
  return attributes;
3719
3277
  }
3720
- /** Check the body of a macro or element against its opening tag. */
3721
- function checkBody(open, body) {
3722
- for (const branch of body.branches) {
3723
- const parent = BRANCH_PARENT[branch.tag.lower];
3724
- if (open.lex !== "macro" || open.lower !== parent) fail(label(branch.tag) + " must be directly inside {" + parent + RB + ", not inside " + label(open), branch.tag.loc);
3725
- }
3726
- if (!body.end) fail("Unclosed " + label(open) + ": no " + closerOf(open) + " closes it", open.loc);
3727
- if (!sameName(open, body.end)) fail(label(body.end) + " found where " + closerOf(open) + " should close the " + label(open) + " opened at " + at(open.loc), body.end.loc);
3728
- }
3729
- function macroNode(tag, body) {
3730
- const node = {
3731
- type: "macro",
3732
- name: tag.lower,
3733
- rawArgs: tag.rawArgs,
3734
- children: []
3735
- };
3736
- if (!body) return withSelectors(node, tag);
3737
- checkBody(tag, body);
3738
- node.children = body.children;
3739
- if (BRANCHING.has(tag.lower)) {
3740
- node.branches = [withSelectors({
3741
- rawArgs: tag.rawArgs,
3742
- children: body.children
3743
- }, tag)];
3744
- for (const b of body.branches) node.branches.push(withSelectors({
3745
- rawArgs: b.tag.rawArgs,
3746
- children: b.children
3747
- }, b.tag));
3748
- node.children = [];
3749
- } else withSelectors(node, tag);
3750
- return node;
3751
- }
3752
3278
  peg$result = peg$startRuleFunction();
3753
3279
  const peg$success = peg$result !== peg$FAILED && peg$currPos === input.length;
3754
3280
  function peg$throw() {
@@ -3806,6 +3332,10 @@ var NameSet = class {
3806
3332
  };
3807
3333
  //#endregion
3808
3334
  //#region src/markup/ast.ts
3335
+ /**
3336
+ * The passage AST (built by parse.ts), and the registry of block macros:
3337
+ * those whose body the parser nests up to their `{/name}`.
3338
+ */
3809
3339
  /** Macros that require a closing tag and can contain children */
3810
3340
  var BLOCK_MACROS = new NameSet([
3811
3341
  "if",
@@ -3823,10 +3353,271 @@ var BLOCK_MACROS = new NameSet([
3823
3353
  "span",
3824
3354
  "nobr"
3825
3355
  ]);
3356
+ /** Macros whose body is JavaScript source, kept verbatim. */
3357
+ var RAW_BODY_MACROS = new Set(["do"]);
3358
+ /** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
3359
+ function isRawMacro(name) {
3360
+ return RAW_BODY_MACROS.has(name);
3361
+ }
3826
3362
  /** Whether a macro takes a body closed by `{/name}`. */
3827
3363
  function isBlockMacro(name) {
3828
3364
  return BLOCK_MACROS.has(name);
3829
3365
  }
3366
+ /** Macros whose branches render as one: the node holds one per branch. */
3367
+ var BRANCHING = new Set([
3368
+ "if",
3369
+ "switch",
3370
+ "timed"
3371
+ ]);
3372
+ /** `value` as a quoted macro argument. */
3373
+ var quoteArg = (value) => `"${value.replace(/[\\"]/g, "\\$&")}"`;
3374
+ /** The AST of paired markup (see pair.ts): what the renderer runs. */
3375
+ function buildAst(nodes) {
3376
+ return nodes.map(astNode);
3377
+ }
3378
+ function astNode({ token, body }) {
3379
+ switch (token.type) {
3380
+ case "text": return token.comment ? {
3381
+ type: "text",
3382
+ value: token.value,
3383
+ comment: true
3384
+ } : {
3385
+ type: "text",
3386
+ value: token.value
3387
+ };
3388
+ case "link": return withSelectors$1({
3389
+ type: "macro",
3390
+ name: "link",
3391
+ rawArgs: `${quoteArg(token.display)} ${quoteArg(token.target)}`,
3392
+ children: []
3393
+ }, token);
3394
+ case "variable": return withSelectors$1({
3395
+ type: "variable",
3396
+ name: token.name,
3397
+ scope: token.scope
3398
+ }, token);
3399
+ case "expression": return withSelectors$1({
3400
+ type: "expression",
3401
+ expression: token.expression
3402
+ }, token);
3403
+ case "html": return {
3404
+ type: "html",
3405
+ tag: token.tag,
3406
+ attributes: token.attributes,
3407
+ children: body ? buildAst(body.children) : []
3408
+ };
3409
+ case "macro": {
3410
+ const name = token.name.toLowerCase();
3411
+ const node = {
3412
+ type: "macro",
3413
+ name,
3414
+ rawArgs: token.rawArgs,
3415
+ children: []
3416
+ };
3417
+ if (!body) return withSelectors$1(node, token);
3418
+ const children = buildAst(body.children);
3419
+ if (!BRANCHING.has(name)) {
3420
+ node.children = children;
3421
+ return withSelectors$1(node, token);
3422
+ }
3423
+ const branch = (tag, branchChildren) => withSelectors$1({
3424
+ rawArgs: tag.rawArgs,
3425
+ children: branchChildren
3426
+ }, tag);
3427
+ node.branches = [branch(token, children), ...body.branches.map(({ tag, children: c }) => branch(tag, buildAst(c)))];
3428
+ return node;
3429
+ }
3430
+ }
3431
+ }
3432
+ //#endregion
3433
+ //#region src/markup/line-column.ts
3434
+ /** 1-based line and column of `offset` in `text`. */
3435
+ function lineColumn(text, offset) {
3436
+ let line = 1;
3437
+ let lineStart = 0;
3438
+ for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
3439
+ line++;
3440
+ lineStart = i + 1;
3441
+ i = text.indexOf("\n", lineStart);
3442
+ }
3443
+ return {
3444
+ line,
3445
+ column: offset - lineStart + 1
3446
+ };
3447
+ }
3448
+ //#endregion
3449
+ //#region src/markup/pair.ts
3450
+ /**
3451
+ * Pairing: which closer closes which opener among the flat tokens of markup
3452
+ * (parse.ts tokenizeMarkup), and which branch (`{else}`, `{case}`) belongs to
3453
+ * which macro. The runtime AST (ast.ts) is built from this, and editor tooling
3454
+ * reads the same tree (`pairMarkup` in tooling.ts), so both agree on where a
3455
+ * block starts and ends.
3456
+ *
3457
+ * It never throws: a problem is an entry of `errors`, and the tree is
3458
+ * recovered around it. A closer closes the innermost open element, as the
3459
+ * runtime reads it, or, when it matches one further out, closes that one and
3460
+ * what was open inside it stays unclosed.
3461
+ */
3462
+ /** The last of `items`. */
3463
+ var last$1 = (items) => items[items.length - 1];
3464
+ /** The macro each branch macro belongs to. */
3465
+ var BRANCH_PARENT = {
3466
+ elseif: "if",
3467
+ else: "if",
3468
+ case: "switch",
3469
+ default: "switch",
3470
+ next: "timed"
3471
+ };
3472
+ var isBranchTag = (token) => token.type === "macro" && !token.isClose && Object.prototype.hasOwnProperty.call(BRANCH_PARENT, token.name.toLowerCase());
3473
+ var lowerName = (token) => nameOf(token).toLowerCase();
3474
+ /** The macro name or HTML tag of `tag`, as written. */
3475
+ var nameOf = (tag) => tag.type === "macro" ? tag.name : tag.tag;
3476
+ /** How a tag reads in an error message. */
3477
+ function tagLabel(tag) {
3478
+ return tag.type === "html" ? `${tag.isClose ? "</" : "<"}${tag.tag}>` : `{${tag.isClose ? "/" : ""}${tag.name}}`;
3479
+ }
3480
+ /** The tag that closes the element opened by `tag`. */
3481
+ var closerOf = (tag) => tag.type === "html" ? `</${tag.tag}>` : `{/${tag.name}}`;
3482
+ /** Whether `close` is the closing tag of the element opened by `open`. */
3483
+ var closes = (open, close) => open.type === close.type && lowerName(open) === lowerName(close);
3484
+ /**
3485
+ * Pair `tokens`, the tokens of `source`, into a tree: elements with their
3486
+ * bodies and branches, and the problems found (unclosed, mismatched and
3487
+ * stray closers, branches outside their macro) in the order a parser reading
3488
+ * from left to right notices them.
3489
+ */
3490
+ function pairMarkup(tokens, options = {}) {
3491
+ const isBlock = options.isBlock ?? isBlockMacro;
3492
+ const isRaw = options.isRaw ?? isRawMacro;
3493
+ const errors = [];
3494
+ const noticedAtEnd = (tokens[tokens.length - 1]?.end ?? 0) + 1;
3495
+ const where = (offset) => {
3496
+ if (options.source === void 0) return `offset ${offset}`;
3497
+ const { line, column } = lineColumn(options.source, offset);
3498
+ return `line ${line}, column ${column}`;
3499
+ };
3500
+ const report = (code, token, message, noticedAt, data) => {
3501
+ errors.push({
3502
+ code,
3503
+ message,
3504
+ start: token.start,
3505
+ end: token.end,
3506
+ noticedAt,
3507
+ data
3508
+ });
3509
+ };
3510
+ /** A branch outside its macro, or inside another element `inside`. */
3511
+ const misplaced = (tag, inside, noticedAt) => {
3512
+ const parent = BRANCH_PARENT[tag.name.toLowerCase()];
3513
+ const where = inside ? `, not inside ${tagLabel(inside)}` : "";
3514
+ report("misplaced-branch", tag, `${tagLabel(tag)} must be directly inside {${parent}}${where}`, noticedAt, {
3515
+ name: tag.name,
3516
+ parent,
3517
+ ...inside && { inside: nameOf(inside) }
3518
+ });
3519
+ };
3520
+ const root = [];
3521
+ const stack = [];
3522
+ const add = (node) => (last$1(stack)?.into ?? root).push(node);
3523
+ /**
3524
+ * End the element on top of the stack, with `close` if it has one: its
3525
+ * misplaced branches are reported first, then how it ends.
3526
+ */
3527
+ const end = (ending, close, owns = ending === "closed") => {
3528
+ const { node, body } = stack.pop();
3529
+ const open = node.token;
3530
+ const noticedAt = close ? close.end : noticedAtEnd;
3531
+ for (const { tag } of body.branches) {
3532
+ const parent = BRANCH_PARENT[tag.name.toLowerCase()];
3533
+ if (open.type !== "macro" || lowerName(open) !== parent) misplaced(tag, open, noticedAt);
3534
+ }
3535
+ if (ending === "unclosed") report("unclosed-block", open, `Unclosed ${tagLabel(open)}: no ${closerOf(open)} closes it`, noticedAt, { name: nameOf(open) });
3536
+ else if (ending === "mismatch") report("mismatched-closer", close, `${tagLabel(close)} found where ${closerOf(open)} should close the ${tagLabel(open)} opened at ${where(open.start)}`, noticedAt, {
3537
+ name: nameOf(open),
3538
+ closer: nameOf(close)
3539
+ });
3540
+ if (owns) body.close = close;
3541
+ node.end = body.close?.end ?? lastEnd(body) ?? open.end;
3542
+ add(node);
3543
+ };
3544
+ for (let i = 0; i < tokens.length; i++) {
3545
+ const token = tokens[i];
3546
+ if ((token.type === "macro" || token.type === "html") && token.isClose) {
3547
+ const top = last$1(stack);
3548
+ if (!top) report("stray-closer", token, `${tagLabel(token)} closes nothing: no ${token.type === "html" ? `<${token.tag}>` : `{${token.name}}`} is open here`, token.start, { name: nameOf(token) });
3549
+ else if (closes(top.node.token, token)) end("closed", token);
3550
+ else {
3551
+ let outer = stack.length - 1;
3552
+ while (outer >= 0 && !closes(stack[outer].node.token, token)) outer--;
3553
+ end("mismatch", token, outer === -1);
3554
+ if (outer !== -1) {
3555
+ while (stack.length > outer + 1) end("cut", token);
3556
+ end("closed", token);
3557
+ }
3558
+ }
3559
+ continue;
3560
+ }
3561
+ if (isBranchTag(token)) {
3562
+ const tag = token;
3563
+ const frame = last$1(stack);
3564
+ if (!frame) {
3565
+ misplaced(tag, void 0, tag.start);
3566
+ continue;
3567
+ }
3568
+ const branch = {
3569
+ tag,
3570
+ children: []
3571
+ };
3572
+ frame.body.branches.push(branch);
3573
+ frame.into = branch.children;
3574
+ continue;
3575
+ }
3576
+ const node = {
3577
+ token,
3578
+ start: token.start,
3579
+ end: token.end
3580
+ };
3581
+ const opens = token.type === "html" ? !token.isSelfClose : token.type === "macro" && isBlock(token.name.toLowerCase());
3582
+ if (opens && token.type === "macro" && isRaw(token.name.toLowerCase()) && !closesRawBody(token, tokens[i + 1], tokens[i + 2])) {
3583
+ report("unclosed-block", token, `Unclosed ${tagLabel(token)}: no ${closerOf(token)} closes it`, token.end, { name: nameOf(token) });
3584
+ add(node);
3585
+ continue;
3586
+ }
3587
+ if (!opens) {
3588
+ add(node);
3589
+ continue;
3590
+ }
3591
+ const body = {
3592
+ children: [],
3593
+ branches: []
3594
+ };
3595
+ node.body = body;
3596
+ stack.push({
3597
+ node,
3598
+ body,
3599
+ into: body.children
3600
+ });
3601
+ }
3602
+ while (stack.length > 0) end("unclosed");
3603
+ return {
3604
+ nodes: root,
3605
+ errors
3606
+ };
3607
+ }
3608
+ /**
3609
+ * Whether the tokens after the opening tag `open` of a raw macro are its
3610
+ * body (one text token, if it is not empty) and its closer.
3611
+ */
3612
+ function closesRawBody(open, next, after) {
3613
+ const closer = (t) => t?.type === "macro" && t.isClose && closes(open, t);
3614
+ return closer(next) || next?.type === "text" && closer(after);
3615
+ }
3616
+ /** The end of the last thing in `body`. */
3617
+ function lastEnd(body) {
3618
+ const branch = last$1(body.branches);
3619
+ return last$1(branch?.children ?? body.children)?.end ?? branch?.tag.end;
3620
+ }
3830
3621
  //#endregion
3831
3622
  //#region node_modules/acorn/dist/acorn.mjs
3832
3623
  var astralIdentifierCodes = [
@@ -9962,39 +9753,26 @@ function splitSigilTemplate(template) {
9962
9753
  * hooks plugged in. It builds the AST directly and reports malformed markup
9963
9754
  * as a MarkupError carrying its line and column.
9964
9755
  */
9965
- /** Macros whose body is JavaScript source, kept verbatim. */
9966
- var RAW_BODY_MACROS = new Set(["do"]);
9967
9756
  var defaultHooks = {
9968
9757
  ...defaultCodeEnd,
9969
9758
  isBlock: isBlockMacro,
9970
- isRaw: (name) => RAW_BODY_MACROS.has(name),
9759
+ isRaw: isRawMacro,
9971
9760
  isCodeAttribute
9972
9761
  };
9973
9762
  /** Malformed markup, with where it starts (1-based line and column). */
9974
9763
  var MarkupError = class extends Error {
9975
- constructor(reason, offset, line, column) {
9764
+ constructor(reason, offset, line, column, code = "syntax", end = offset, data = {}) {
9976
9765
  super(`${reason} (line ${line}, column ${column})`);
9977
9766
  this.reason = reason;
9978
9767
  this.offset = offset;
9979
9768
  this.line = line;
9980
9769
  this.column = column;
9770
+ this.code = code;
9771
+ this.end = end;
9772
+ this.data = data;
9981
9773
  this.name = "MarkupError";
9982
9774
  }
9983
9775
  };
9984
- /** 1-based line and column of `offset` in `text`. */
9985
- function lineColumn(text, offset) {
9986
- let line = 1;
9987
- let lineStart = 0;
9988
- for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
9989
- line++;
9990
- lineStart = i + 1;
9991
- i = text.indexOf("\n", lineStart);
9992
- }
9993
- return {
9994
- line,
9995
- column: offset - lineStart + 1
9996
- };
9997
- }
9998
9776
  function run(source, startRule, options) {
9999
9777
  const hooks = options.hooks ? {
10000
9778
  ...defaultHooks,
@@ -10007,21 +9785,61 @@ function run(source, startRule, options) {
10007
9785
  hooks
10008
9786
  });
10009
9787
  } catch (err) {
10010
- const location = err.location;
9788
+ const { location, code } = err;
10011
9789
  if (err instanceof Error && err.name === "SyntaxError" && location) {
10012
9790
  const { offset } = location.start;
10013
9791
  const { line, column } = lineColumn(source, offset);
10014
- throw new MarkupError(err.message, offset, line, column);
9792
+ throw new MarkupError(err.message, offset, line, column, code, location.end.offset);
10015
9793
  }
10016
9794
  throw err;
10017
9795
  }
10018
9796
  }
10019
9797
  /**
9798
+ * Read markup that may be malformed: its tokens, their pairing and every
9799
+ * error (malformed tags, and closers and branches that pair with nothing),
9800
+ * with offsets in `source`. Markup inside a malformed tag is not read as such,
9801
+ * so it has no errors of its own.
9802
+ */
9803
+ function analyzeMarkup(source, options = {}) {
9804
+ const { tokens, errors, damage } = scan(source, options);
9805
+ const hooks = {
9806
+ ...defaultHooks,
9807
+ ...options.hooks
9808
+ };
9809
+ const paired = pairMarkup(tokens, {
9810
+ isBlock: hooks.isBlock,
9811
+ isRaw: hooks.isRaw,
9812
+ source
9813
+ });
9814
+ if (errors.length === 0 && paired.errors.length === 0) return {
9815
+ tokens,
9816
+ nodes: paired.nodes,
9817
+ errors
9818
+ };
9819
+ const inDamage = (start) => errors.some((e, i) => start >= damage[i] && start <= e.offset);
9820
+ const noticed = errors.map((e, i) => [damage[i] + .5, e]);
9821
+ for (const error of paired.errors) if (!inDamage(error.start)) noticed.push([error.noticedAt, pairingError(source, error)]);
9822
+ noticed.sort((a, b) => a[0] - b[0]);
9823
+ return {
9824
+ tokens,
9825
+ nodes: paired.nodes,
9826
+ errors: noticed.map(([, e]) => e)
9827
+ };
9828
+ }
9829
+ /**
10020
9830
  * Parse markup into its AST: macros with their bodies and branches, HTML
10021
- * elements with their children. Throws a MarkupError for malformed markup.
9831
+ * elements with their children. Throws a MarkupError for malformed markup:
9832
+ * the first problem a parser reading from left to right meets.
10022
9833
  */
10023
9834
  function parseMarkup(source, options = {}) {
10024
- return run(source, "Markup", options);
9835
+ const { nodes, errors } = analyzeMarkup(source, options);
9836
+ if (errors.length > 0) throw errors[0];
9837
+ return buildAst(nodes);
9838
+ }
9839
+ /** A pairing problem as the MarkupError it is for `source`. */
9840
+ function pairingError(source, error) {
9841
+ const { line, column } = lineColumn(source, error.start);
9842
+ return new MarkupError(error.message, error.start, line, column, error.code, error.end, error.data);
10025
9843
  }
10026
9844
  /**
10027
9845
  * The flat tokens of markup, without nesting, so unclosed or mismatched
@@ -10052,8 +9870,21 @@ function parseSelectors(source, at = 0) {
10052
9870
  * markup the tokens are those of `tokenizeMarkup` and there are no errors.
10053
9871
  */
10054
9872
  function tokenizeMarkupTolerant(source, options = {}) {
9873
+ const { tokens, errors } = scan(source, options);
9874
+ return {
9875
+ tokens,
9876
+ errors
9877
+ };
9878
+ }
9879
+ /**
9880
+ * The tokens of tolerant tokenizing, the errors, and where the damage of
9881
+ * each error starts: the tag that is malformed, which an error inside it
9882
+ * (an attribute value) is after.
9883
+ */
9884
+ function scan(source, options) {
10055
9885
  const tokens = [];
10056
9886
  const errors = [];
9887
+ const damage = [];
10057
9888
  const lastBrace = source.lastIndexOf("}");
10058
9889
  const { closeBrace } = {
10059
9890
  ...defaultHooks,
@@ -10069,7 +9900,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10069
9900
  return tokenizeMarkup(text, {
10070
9901
  ...options,
10071
9902
  hooks
10072
- }).map((token) => shift(token, base));
9903
+ }).map((token) => shiftOffsets(token, base));
10073
9904
  } catch (error) {
10074
9905
  if (!(error instanceof MarkupError)) throw error;
10075
9906
  return error;
@@ -10085,7 +9916,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10085
9916
  }
10086
9917
  const at = base + result.offset;
10087
9918
  const { line, column } = lineColumn(source, at);
10088
- errors.push(new MarkupError(result.reason, at, line, column));
9919
+ errors.push(new MarkupError(result.reason, at, line, column, result.code, base + result.end));
10089
9920
  let cut = result.offset;
10090
9921
  let prefix = attempt(rest.slice(0, cut), base);
10091
9922
  while (!Array.isArray(prefix)) {
@@ -10093,6 +9924,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10093
9924
  prefix = attempt(rest.slice(0, cut), base);
10094
9925
  }
10095
9926
  tokens.push(...prefix);
9927
+ damage.push(base + cut);
10096
9928
  if (cut < rest.length) {
10097
9929
  const start = base + cut;
10098
9930
  tokens.push({
@@ -10106,23 +9938,23 @@ function tokenizeMarkupTolerant(source, options = {}) {
10106
9938
  }
10107
9939
  return {
10108
9940
  tokens,
10109
- errors
9941
+ errors,
9942
+ damage
10110
9943
  };
10111
9944
  }
10112
- /** `token` with its offsets moved `by` on. */
10113
- function shift(token, by) {
10114
- if (by === 0) return token;
10115
- const moved = {
10116
- ...token,
10117
- start: token.start + by,
10118
- end: token.end + by
10119
- };
10120
- if (moved.type === "link") {
10121
- moved.targetStart += by;
10122
- moved.targetEnd += by;
10123
- }
9945
+ /** The offset fields of a token (and of an attribute): `start`, `nameEnd`… */
9946
+ var OFFSET_FIELD = /^(start|end|[A-Za-z]*(Start|End))$/;
9947
+ /** `token` (or an attribute of it) with each of its offsets turned by `map`. */
9948
+ function mapOffsets(token, map) {
9949
+ const moved = { ...token };
9950
+ for (const [key, value] of Object.entries(moved)) if (typeof value === "number" && OFFSET_FIELD.test(key)) moved[key] = map(value);
9951
+ else if (key === "attributeSpans") moved[key] = value.map((span) => mapOffsets(span, map));
10124
9952
  return moved;
10125
9953
  }
9954
+ /** `token` (or an attribute of it) with its offsets moved `by` on. */
9955
+ function shiftOffsets(token, by) {
9956
+ return by === 0 ? token : mapOffsets(token, (offset) => offset + by);
9957
+ }
10126
9958
  //#endregion
10127
9959
  //#region src/utils/parse-delay.ts
10128
9960
  /**
@@ -10414,7 +10246,7 @@ function unset(param) {
10414
10246
  return param.type === "options" ? {} : void 0;
10415
10247
  }
10416
10248
  var WORD_RE = /\w+/y;
10417
- var NUMBER_RE = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
10249
+ var NUMBER_RE$1 = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
10418
10250
  var WORD_OR_PUNCT_RE = /\S+/y;
10419
10251
  /** Match the sticky regex `re` at `pos`, returning the matched text. */
10420
10252
  function matchAt(re, src, pos) {
@@ -10443,7 +10275,7 @@ function readOptions(params, src, { at, spans }) {
10443
10275
  let j = i;
10444
10276
  while (j < src.length && isWhitespace(src[j])) j++;
10445
10277
  const quoted = readQuoted(src, j);
10446
- const digits = quoted || j === i ? null : matchAt(NUMBER_RE, src, j);
10278
+ const digits = quoted || j === i ? null : matchAt(NUMBER_RE$1, src, j);
10447
10279
  if (quoted) {
10448
10280
  val = quoted.value;
10449
10281
  i = quoted.end;
@@ -10653,6 +10485,14 @@ function parseOrError(code, goal) {
10653
10485
  parses?.set(key, result);
10654
10486
  return result;
10655
10487
  }
10488
+ /** Where character `index` of the code or text of `piece` is in the source. */
10489
+ function pieceOffset(piece, index) {
10490
+ return piece.sourceOffsets?.[index] ?? piece.offset + index;
10491
+ }
10492
+ /** How much of a piece's own text or code there is (not its source extent). */
10493
+ function extentOf(piece) {
10494
+ return piece.kind === "code" ? piece.code.length : piece.kind === "text" ? piece.text.length : piece.length;
10495
+ }
10656
10496
  /** Macros whose whole argument text is one expression: branch conditions. */
10657
10497
  var CONDITION_MACROS = new Set([
10658
10498
  "if",
@@ -10729,48 +10569,34 @@ function* codeAndText(src, tokens, parametersOf) {
10729
10569
  macro: "link",
10730
10570
  label: src.slice(token.start, token.end)
10731
10571
  };
10732
- if (token.display.includes("{")) yield {
10733
- kind: "text",
10734
- text: token.display,
10735
- offset: locate(src, token.display, token.start),
10736
- where: "In the label of a link: "
10737
- };
10572
+ if (token.display.includes("{")) yield textPiece(token.display, token.displayStart, "In the label of a link: ");
10738
10573
  } else if (token.type === "expression") yield {
10739
10574
  kind: "code",
10740
10575
  code: token.expression,
10741
- offset: token.end - 1 - token.expression.length,
10576
+ offset: token.expressionStart,
10742
10577
  goal: "expression",
10743
10578
  label: `{${token.expression}}`
10744
10579
  };
10745
- else if (token.type === "html") {
10746
- let cursor = token.start;
10747
- for (const [name, value] of Object.entries(token.attributes)) {
10748
- const at = locate(src, value, cursor);
10749
- cursor = at + value.length;
10750
- if (!isCodeAttribute(name)) {
10751
- yield {
10752
- kind: "text",
10753
- text: value,
10754
- offset: at,
10755
- where: `In the ${name} attribute of <${token.tag}>: `
10756
- };
10757
- continue;
10758
- }
10759
- let from = 0;
10760
- for (const part of splitSigilTemplate(value)) {
10761
- if (!("expr" in part)) continue;
10762
- const k = locate(value, part.expr, from);
10763
- from = k + part.expr.length;
10764
- yield {
10765
- kind: "code",
10766
- code: part.expr,
10767
- offset: at + k,
10768
- goal: "expression",
10769
- label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
10770
- };
10771
- }
10580
+ else if (token.type === "html") for (const { name, value, at } of attributeValues(src, token)) {
10581
+ if (!isCodeAttribute(name)) {
10582
+ yield textPiece(value, at, `In the ${name} attribute of <${token.tag}>: `);
10583
+ continue;
10584
+ }
10585
+ let from = 0;
10586
+ for (const part of splitSigilTemplate(value)) {
10587
+ if (!("expr" in part)) continue;
10588
+ const k = locate(value, part.expr, from);
10589
+ from = k + part.expr.length;
10590
+ yield {
10591
+ kind: "code",
10592
+ code: part.expr,
10593
+ offset: at + k,
10594
+ goal: "expression",
10595
+ label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
10596
+ };
10772
10597
  }
10773
- } else if (token.type === "macro" && !token.isClose) {
10598
+ }
10599
+ else if (token.type === "macro" && !token.isClose) {
10774
10600
  const name = token.name.toLowerCase();
10775
10601
  if (name === "do") {
10776
10602
  const close = closeOf(t, name);
@@ -10804,8 +10630,7 @@ function* codeAndText(src, tokens, parametersOf) {
10804
10630
  }
10805
10631
  if (!args) continue;
10806
10632
  const label = `{${token.name} ${args}}`;
10807
- const tag = src.slice(token.start, token.end - 1);
10808
- const argsAt = token.start + tag.trimEnd().length - args.length;
10633
+ const argsAt = token.argsStart;
10809
10634
  if (CONDITION_MACROS.has(name)) {
10810
10635
  yield {
10811
10636
  kind: "code",
@@ -10821,8 +10646,95 @@ function* codeAndText(src, tokens, parametersOf) {
10821
10646
  }
10822
10647
  }
10823
10648
  }
10649
+ /**
10650
+ * `codeAndText`, with the markup in the texts read too: a text piece (a label,
10651
+ * an attribute value) with a `{` in it carries its tokens and errors, and is
10652
+ * followed by the pieces of that markup, `nested`, in the offsets of the whole
10653
+ * `src`. In source order, a nested piece after the text it is in.
10654
+ */
10655
+ function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
10656
+ yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0);
10657
+ }
10658
+ /**
10659
+ * The pieces of `tokens`, the tokens of `src`, which is the text described by
10660
+ * `where` (none for `root`, the markup of the whole passage), and whose
10661
+ * offsets `toRoot` turns into offsets in `root`.
10662
+ */
10663
+ function* expand(root, src, tokens, parametersOf, options, toRoot, where) {
10664
+ for (const flat of codeAndText(src, tokens, parametersOf)) {
10665
+ const piece = where ? nestedPiece(flat, toRoot, where) : flat;
10666
+ if (flat.kind !== "text" || !flat.text.includes("{")) {
10667
+ yield piece;
10668
+ continue;
10669
+ }
10670
+ const toText = (i) => toRoot(pieceOffset(flat, i));
10671
+ const inner = analyzeMarkup(flat.text, {
10672
+ text: true,
10673
+ hooks: options.isBlock && { isBlock: options.isBlock }
10674
+ });
10675
+ yield {
10676
+ ...piece,
10677
+ tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
10678
+ errors: inner.errors.map((e) => {
10679
+ const { line, column } = lineColumn(root, toText(e.offset));
10680
+ return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
10681
+ })
10682
+ };
10683
+ yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where);
10684
+ }
10685
+ }
10686
+ /** `piece`, of a text in another, with its offsets turned by `toRoot`. */
10687
+ function nestedPiece(piece, toRoot, where) {
10688
+ const offset = toRoot(piece.offset);
10689
+ const nested = {
10690
+ offset,
10691
+ nested: true,
10692
+ where
10693
+ };
10694
+ if (piece.kind === "passage" || piece.kind === "argument-error") {
10695
+ const length = toRoot(piece.offset + piece.length) - offset;
10696
+ return {
10697
+ ...piece,
10698
+ ...nested,
10699
+ length
10700
+ };
10701
+ }
10702
+ const extent = extentOf(piece);
10703
+ const sourceOffsets = piece.sourceOffsets ? piece.sourceOffsets.map(toRoot) : toRoot(piece.offset + extent) - offset !== extent ? Array.from({ length: extent + 1 }, (_, i) => toRoot(piece.offset + i)) : void 0;
10704
+ return sourceOffsets ? {
10705
+ ...piece,
10706
+ ...nested,
10707
+ sourceOffsets
10708
+ } : {
10709
+ ...piece,
10710
+ ...nested
10711
+ };
10712
+ }
10713
+ /**
10714
+ * Where each character of `value`, the unescaped text of a quoted string
10715
+ * written as `raw` from `at` on (a backslash before a quote or a backslash
10716
+ * is dropped), is
10717
+ * in the source, and where the text ends. None when the text is where its
10718
+ * length says, or is not that string.
10719
+ */
10720
+ function escapeOffsets(raw, at, value) {
10721
+ const offsets = [];
10722
+ let escaped = false;
10723
+ let i = 0;
10724
+ while (offsets.length < value.length) {
10725
+ if (i >= raw.length) return void 0;
10726
+ offsets.push(at + i);
10727
+ if (raw[i] === "\\" && /["'\\]/.test(raw.charAt(i + 1))) {
10728
+ escaped = true;
10729
+ i += 2;
10730
+ } else i++;
10731
+ }
10732
+ offsets.push(at + i);
10733
+ return escaped ? offsets : void 0;
10734
+ }
10824
10735
  /** The code and text in the arguments `args` (at `offset`) of `macro`. */
10825
10736
  function* argPieces(args, offset, params, macro, label) {
10737
+ const name = macro.toLowerCase();
10826
10738
  let values;
10827
10739
  const spans = /* @__PURE__ */ new Map();
10828
10740
  try {
@@ -10833,11 +10745,12 @@ function* argPieces(args, offset, params, macro, label) {
10833
10745
  kind: "argument-error",
10834
10746
  message: error.message,
10835
10747
  offset,
10836
- label
10748
+ length: args.length,
10749
+ label,
10750
+ macro: name
10837
10751
  };
10838
10752
  return;
10839
10753
  }
10840
- const name = macro.toLowerCase();
10841
10754
  /** The pieces of the parameters `list`, with their values in `from`. */
10842
10755
  function* visit(list, from) {
10843
10756
  for (const param of list) {
@@ -10884,25 +10797,70 @@ function* argPieces(args, offset, params, macro, label) {
10884
10797
  }
10885
10798
  const at = offset + start + (value !== written && /^["']/.test(written) ? 1 : 0);
10886
10799
  const holds = stringHolds(param);
10887
- if (holds === "expression" || holds === "statements") yield {
10888
- kind: "code",
10889
- code: value,
10890
- offset: at,
10891
- goal: holds,
10892
- label,
10893
- inString: true
10894
- };
10895
- else if (holds === "passage") yield passage(value);
10896
- else if (holds === "markup") yield {
10897
- kind: "text",
10898
- text: value,
10899
- offset: at,
10900
- where: `In the ${param.name} of {${macro}}: `
10901
- };
10800
+ const sourceOffsets = escapeOffsets(args.slice(at - offset), at, value);
10801
+ if (holds === "expression" || holds === "statements") {
10802
+ const piece = {
10803
+ kind: "code",
10804
+ code: value,
10805
+ offset: at,
10806
+ goal: holds,
10807
+ label,
10808
+ inString: true
10809
+ };
10810
+ if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
10811
+ yield piece;
10812
+ } else if (holds === "passage") yield passage(value);
10813
+ else if (holds === "markup") {
10814
+ const piece = textPiece(value, at, `In the ${param.name} of {${macro}}: `);
10815
+ if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
10816
+ yield piece;
10817
+ }
10902
10818
  }
10903
10819
  }
10904
10820
  yield* [...visit(params, values)].sort((a, b) => a.offset - b.offset);
10905
10821
  }
10822
+ /** A text that may hold markup, at `offset`; read when it is expanded. */
10823
+ var textPiece = (text, offset, where) => ({
10824
+ kind: "text",
10825
+ text,
10826
+ offset,
10827
+ where,
10828
+ tokens: [],
10829
+ errors: []
10830
+ });
10831
+ /**
10832
+ * The attributes of an HTML tag by the values as written, with where each
10833
+ * value is: the first of equal names, which is the one in effect. A token
10834
+ * with no spans (made from an AST) has them found in `src`, in order.
10835
+ */
10836
+ function attributeValues(src, token) {
10837
+ if (token.attributeSpans.length === 0) {
10838
+ let cursor = token.start;
10839
+ return Object.entries(token.attributes).map(([name, value]) => {
10840
+ const at = locate(src, value, cursor);
10841
+ cursor = at + value.length;
10842
+ return {
10843
+ name,
10844
+ value,
10845
+ at
10846
+ };
10847
+ });
10848
+ }
10849
+ const seen = /* @__PURE__ */ new Set();
10850
+ const values = [];
10851
+ for (const span of token.attributeSpans) {
10852
+ const lower = span.name.toLowerCase();
10853
+ if (seen.has(lower)) continue;
10854
+ seen.add(lower);
10855
+ if (span.valueStart === void 0) continue;
10856
+ values.push({
10857
+ name: span.name,
10858
+ value: src.slice(span.valueStart, span.valueEnd),
10859
+ at: span.valueStart
10860
+ });
10861
+ }
10862
+ return values;
10863
+ }
10906
10864
  /**
10907
10865
  * Index of `part` in `text` from `from` on, else anywhere, else `from`: the
10908
10866
  * place to report an error in `part` at.
@@ -10913,18 +10871,10 @@ function locate(text, part, from) {
10913
10871
  const anywhere = text.indexOf(part);
10914
10872
  return anywhere >= 0 ? anywhere : from;
10915
10873
  }
10916
- /**
10917
- * The passages the markup `src` (with the `tokens` it tokenizes to) names:
10918
- * `[[…]]` links, the passage argument of `{goto}`, `{include}` and `{link}`
10919
- * (and of macros that declare one), the `goto` and `dialog` actions of
10920
- * `{watch}` (and the `string` and `text` arguments of macros that declare
10921
- * they hold one) and the body of `{dialog}`, in source order. A name written
10922
- * out is a literal; the others are expressions, which name a passage when
10923
- * they run.
10924
- */
10925
- function collectPassageReferences(src, tokens, parametersOf) {
10874
+ /** The passage references among `pieces` (see collectPassageReferences). */
10875
+ function referencesOf(pieces) {
10926
10876
  const refs = [];
10927
- for (const piece of codeAndText(src, tokens, parametersOf)) if (piece.kind === "passage") refs.push({
10877
+ for (const piece of pieces) if (piece.kind === "passage") refs.push({
10928
10878
  macro: piece.macro,
10929
10879
  target: {
10930
10880
  kind: "name",
@@ -11060,26 +11010,27 @@ function astContainsChildren(nodes, parametersOf = registeredParameters) {
11060
11010
  for (const node of nodes) {
11061
11011
  if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
11062
11012
  if (node.type === "html") {
11063
- const span = {
11064
- start: 0,
11065
- end: 0
11066
- };
11067
11013
  if (tokenTextContainsChildren({
11068
11014
  isClose: false,
11069
11015
  isSelfClose: false,
11016
+ tagNameStart: 0,
11017
+ tagNameEnd: 0,
11018
+ attributeSpans: [],
11070
11019
  ...node,
11071
- ...span
11020
+ start: 0,
11021
+ end: 0
11072
11022
  }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11073
11023
  }
11074
11024
  if (node.type === "macro") {
11075
- const span = {
11076
- start: 0,
11077
- end: 0
11078
- };
11079
11025
  if (tokenTextContainsChildren({
11080
11026
  isClose: false,
11027
+ nameStart: 0,
11028
+ nameEnd: 0,
11029
+ argsStart: 0,
11030
+ argsEnd: 0,
11081
11031
  ...node,
11082
- ...span
11032
+ start: 0,
11033
+ end: 0
11083
11034
  }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11084
11035
  if (node.branches) {
11085
11036
  for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf)) return true;
@@ -11120,37 +11071,70 @@ function widgetDef({ name = "", parameters = "" }) {
11120
11071
  function parseWidgetDef(rawArgs) {
11121
11072
  return widgetDef(parseMacroArgs(rawArgs, WIDGET_PARAMETERS));
11122
11073
  }
11074
+ /** Where the name is written in the arguments, without its quotes. */
11075
+ function nameSpan(rawArgs) {
11076
+ const spans = /* @__PURE__ */ new Map();
11077
+ parseMacroArgs(rawArgs, WIDGET_PARAMETERS, spans);
11078
+ const [start, end] = spans.get(WIDGET_PARAMETERS[0]) ?? [0, 0];
11079
+ const quote = rawArgs[start];
11080
+ return (quote === "\"" || quote === "'") && end - start >= 2 ? [start + 1, rawArgs[end - 1] === quote ? end - 1 : end] : [start, end];
11081
+ }
11123
11082
  /**
11124
- * The names of the block widgets (those whose body renders `{@children}`)
11125
- * that StoryInit and the passages tagged `widget` define. They must be
11126
- * known as block macros before any passage is parsed, so that passages
11127
- * invoking them nest their content whatever the passage order.
11083
+ * The widgets that StoryInit and the passages tagged `widget` define, in
11084
+ * source order: the ones the runtime registers, read tolerantly (a half-typed
11085
+ * definition is still reported, without a `closeStart`). Definitions whose
11086
+ * arguments cannot be read are left out.
11128
11087
  *
11129
11088
  * The passages are read as flat tokens, which need no block macros to be
11130
11089
  * known, so a `{@children}` in an HTML comment or in a `{do}` body is text
11131
- * here as it is to the parser, and does not make a block widget (#387).
11090
+ * here as it is to the parser, and does not make a block widget (#387). In
11091
+ * nested definitions, it belongs to the innermost.
11132
11092
  */
11133
- function blockWidgetNames(passages, parametersOf = registeredParameters) {
11134
- const names = [];
11093
+ function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
11094
+ const found = [];
11135
11095
  for (const passage of passages) {
11136
11096
  if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
11137
11097
  const open = [];
11138
- for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
11139
- if (!token.isClose) {
11140
- open.push({
11141
- rawArgs: token.rawArgs,
11142
- isBlock: false
11143
- });
11144
- continue;
11145
- }
11098
+ const done = [];
11099
+ for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") if (!token.isClose) open.push({
11100
+ token,
11101
+ isBlock: false
11102
+ });
11103
+ else {
11146
11104
  const def = open.pop();
11147
- if (!def?.isBlock) continue;
11148
- try {
11149
- names.push(parseWidgetDef(def.rawArgs).name);
11150
- } catch {}
11151
- } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
11105
+ if (def) done.push({
11106
+ ...def,
11107
+ closeStart: token.start
11108
+ });
11109
+ }
11110
+ else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
11111
+ done.push(...open);
11112
+ const defs = [];
11113
+ for (const { token, isBlock, closeStart } of done) try {
11114
+ const [from, to] = nameSpan(token.rawArgs);
11115
+ defs.push({
11116
+ ...parseWidgetDef(token.rawArgs),
11117
+ block: isBlock,
11118
+ passage: passage.name,
11119
+ start: token.start,
11120
+ end: token.end,
11121
+ nameStart: token.argsStart + from,
11122
+ nameEnd: token.argsStart + to,
11123
+ ...closeStart === void 0 ? {} : { closeStart }
11124
+ });
11125
+ } catch {}
11126
+ found.push(...defs.sort((a, b) => a.start - b.start));
11152
11127
  }
11153
- return names;
11128
+ return found;
11129
+ }
11130
+ /**
11131
+ * The names of the block widgets (those whose body renders `{@children}`)
11132
+ * that StoryInit and the passages tagged `widget` define, closed. They must
11133
+ * be known as block macros before any passage is parsed, so that passages
11134
+ * invoking them nest their content whatever the passage order.
11135
+ */
11136
+ function blockWidgetNames(passages, parametersOf = registeredParameters) {
11137
+ return widgetDefinitions$1(passages, parametersOf).filter((def) => def.block && def.closeStart !== void 0).map((def) => def.name);
11154
11138
  }
11155
11139
  //#endregion
11156
11140
  //#region src/markup/validate.ts
@@ -11194,13 +11178,10 @@ function distance(a, b) {
11194
11178
  }
11195
11179
  return prev[b.length];
11196
11180
  }
11197
- /**
11198
- * " Did you mean …?" with the known name closest to `name`, written by
11199
- * `quote`, if one is close.
11200
- */
11201
- function didYouMean(name, names, quote) {
11181
+ /** The known name closest to `name`, if one is close. */
11182
+ function closestName(name, names) {
11202
11183
  const lower = name.toLowerCase();
11203
- let best = "";
11184
+ let best;
11204
11185
  let bestDistance = Math.max(2, Math.floor(lower.length / 3)) + 1;
11205
11186
  for (const candidate of names) {
11206
11187
  const d = distance(lower, candidate.toLowerCase());
@@ -11209,8 +11190,10 @@ function didYouMean(name, names, quote) {
11209
11190
  bestDistance = d;
11210
11191
  }
11211
11192
  }
11212
- return best ? ` Did you mean ${quote(best)}?` : "";
11193
+ return best;
11213
11194
  }
11195
+ /** " Did you mean …?" with `best`, written by `quote`, if there is one. */
11196
+ var didYouMean = (best, quote) => best ? ` Did you mean ${quote(best)}?` : "";
11214
11197
  /** What a passage argument may be, after an error in one. */
11215
11198
  var PASSAGE_ARGUMENT_HINT = " (a passage name is a quoted string or an expression)";
11216
11199
  /** A passage argument that is one bare word (`{goto Kitchen}`). */
@@ -11230,14 +11213,18 @@ function widgetName(rawArgs) {
11230
11213
  function validateMarkup(passages, options) {
11231
11214
  const diagnostics = [];
11232
11215
  const hooks = options.isBlockMacro ? { isBlock: options.isBlockMacro } : void 0;
11233
- const report = (passage, offset, message) => {
11234
- const { line, column } = lineColumn(passage.content, offset);
11216
+ const report = (passage, start, end, code, message, data) => {
11217
+ const { line, column } = lineColumn(passage.content, start);
11235
11218
  const d = {
11236
11219
  passage: passage.name,
11237
11220
  line,
11238
11221
  column,
11239
- message
11222
+ message,
11223
+ code,
11224
+ start,
11225
+ end
11240
11226
  };
11227
+ if (data) d.data = data;
11241
11228
  const file = passage.metadata?.["data-source-file"];
11242
11229
  if (file) {
11243
11230
  d.file = file;
@@ -11246,6 +11233,8 @@ function validateMarkup(passages, options) {
11246
11233
  }
11247
11234
  diagnostics.push(d);
11248
11235
  };
11236
+ /** Report malformed markup. */
11237
+ const reportError = (passage, err, where) => report(passage, err.offset, err.end, err.code, where + err.reason, err.data);
11249
11238
  const parsed = [];
11250
11239
  const widgets = /* @__PURE__ */ new Set();
11251
11240
  const passageNames = /* @__PURE__ */ new Set();
@@ -11267,63 +11256,75 @@ function validateMarkup(passages, options) {
11267
11256
  parsed.push([passage, tokens]);
11268
11257
  } catch (err) {
11269
11258
  if (!(err instanceof MarkupError)) throw err;
11270
- if (reported) report(passage, err.offset, err.reason);
11259
+ if (reported) reportError(passage, err, "");
11271
11260
  }
11272
11261
  }
11273
11262
  const names = [...options.macroNames ?? [], ...widgets];
11274
- /** Report the unknown macros among `tokens`, which start at `base`. */
11275
- const checkMacros = (passage, tokens, base, where) => {
11263
+ /** Report the unknown macros among `tokens`, with `where` in front. */
11264
+ const checkMacros = (passage, tokens, where) => {
11276
11265
  for (const token of tokens) {
11277
11266
  if (token.type !== "macro" || token.isClose) continue;
11278
11267
  const lower = token.name.toLowerCase();
11279
11268
  if (BRANCH_MACROS.has(lower) || widgets.has(lower) || options.isKnownMacro(lower)) continue;
11280
- report(passage, base + token.start, `${where}Unknown macro {${token.name}}.${didYouMean(token.name, names, (n) => `{${n}}`)}`);
11269
+ const best = closestName(token.name, names);
11270
+ report(passage, token.start, token.end, "unknown-macro", `${where}Unknown macro {${token.name}}.${didYouMean(best, (n) => `{${n}}`)}`, {
11271
+ name: token.name,
11272
+ suggestions: best ? [best] : []
11273
+ });
11281
11274
  }
11282
11275
  };
11283
11276
  const parametersOf = options.parametersOf ?? (() => void 0);
11284
11277
  /**
11285
- * Check `tokens`, the tokens of `src`, which starts at `base` in the
11286
- * passage: their macros, the code in them and the markup in their text.
11278
+ * Check the pieces of a passage: its macros, the code in them, the passage
11279
+ * names they write out and the markup in their text.
11287
11280
  */
11288
- const checkTokens = (passage, src, tokens, base, where) => {
11289
- checkMacros(passage, tokens, base, where);
11290
- for (const piece of codeAndText(src, tokens, parametersOf)) {
11291
- const at = base + piece.offset;
11292
- if (piece.kind === "argument-error") {
11293
- report(passage, at, `${where}${piece.message} in ${piece.label}`);
11294
- continue;
11295
- }
11296
- if (piece.kind === "passage") {
11297
- if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
11298
- const hint = didYouMean(piece.name, passageNames, JSON.stringify);
11299
- report(passage, at, `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${hint}`);
11300
- }
11301
- continue;
11302
- }
11303
- if (piece.kind === "code") {
11304
- const result = parseOrError(piece.code, piece.goal);
11305
- const code = piece.code.trim();
11306
- if (result instanceof CodeSyntaxError) {
11307
- const reason = result.reasonIn(passage.content, at);
11308
- report(passage, at + result.pos, `${where}${reason} in ${piece.label}` + (piece.passage ? PASSAGE_ARGUMENT_HINT : ""));
11309
- } else if (piece.passage && BARE_WORD_RE.test(code)) report(passage, at, `${where}Unquoted passage name in ${piece.label}: write ${JSON.stringify(code)}${PASSAGE_ARGUMENT_HINT}`);
11310
- continue;
11311
- }
11312
- if (!piece.text.includes("{")) continue;
11313
- try {
11314
- parseMarkup(piece.text, {
11315
- text: true,
11316
- hooks
11317
- });
11318
- const inner = tokenizeMarkup(piece.text, { text: true });
11319
- checkTokens(passage, piece.text, inner, at, piece.where);
11320
- } catch (err) {
11321
- if (!(err instanceof MarkupError)) throw err;
11322
- report(passage, at + err.offset, piece.where + err.reason);
11281
+ const checkPassage = (passage, tokens) => {
11282
+ checkMacros(passage, tokens, "");
11283
+ let skipTo = 0;
11284
+ for (const piece of passagePiecesOf(passage.content, tokens, parametersOf, { isBlock: options.isBlockMacro })) {
11285
+ if (piece.nested && piece.offset < skipTo) continue;
11286
+ const at = piece.offset;
11287
+ const where = piece.where && piece.nested ? piece.where : "";
11288
+ switch (piece.kind) {
11289
+ case "argument-error":
11290
+ report(passage, at, at + piece.length, "argument-error", `${where}${piece.message} in ${piece.label}`, { macro: piece.macro });
11291
+ break;
11292
+ case "passage":
11293
+ if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
11294
+ const best = closestName(piece.name, passageNames);
11295
+ report(passage, at, at + piece.length, "unknown-passage", `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${didYouMean(best, JSON.stringify)}`, {
11296
+ name: piece.name,
11297
+ macro: piece.macro,
11298
+ suggestions: best ? [best] : []
11299
+ });
11300
+ }
11301
+ break;
11302
+ case "code":
11303
+ checkCode(passage, piece, where);
11304
+ break;
11305
+ case "text": if (piece.errors.length > 0) {
11306
+ reportError(passage, piece.errors[0], piece.where);
11307
+ skipTo = pieceOffset(piece, piece.text.length);
11308
+ } else checkMacros(passage, piece.tokens, piece.where);
11323
11309
  }
11324
11310
  }
11325
11311
  };
11326
- for (const [passage, tokens] of parsed) withParseCache(() => checkTokens(passage, passage.content, tokens, 0, ""));
11312
+ const checkCode = (passage, piece, where) => {
11313
+ const at = piece.offset;
11314
+ const result = parseOrError(piece.code, piece.goal);
11315
+ const code = piece.code.trim();
11316
+ if (result instanceof CodeSyntaxError) {
11317
+ const offending = /^(?:[\w$]+|\S)/.exec(piece.code.slice(result.pos));
11318
+ report(passage, pieceOffset(piece, result.pos), pieceOffset(piece, result.pos + (offending?.[0].length ?? 0)), "code-syntax", `${where}${result.reasonIn(passage.content, at)} in ${piece.label}` + (piece.passage ? PASSAGE_ARGUMENT_HINT : ""), piece.macro ? { macro: piece.macro } : void 0);
11319
+ } else if (piece.passage && BARE_WORD_RE.test(code)) {
11320
+ const lead = piece.code.length - piece.code.trimStart().length;
11321
+ report(passage, pieceOffset(piece, lead), pieceOffset(piece, lead + code.length), "unquoted-passage-name", `${where}Unquoted passage name in ${piece.label}: write ${JSON.stringify(code)}${PASSAGE_ARGUMENT_HINT}`, {
11322
+ name: code,
11323
+ macro: piece.macro ?? ""
11324
+ });
11325
+ }
11326
+ };
11327
+ for (const [passage, tokens] of parsed) withParseCache(() => checkPassage(passage, tokens));
11327
11328
  return diagnostics;
11328
11329
  }
11329
11330
  //#endregion
@@ -11356,6 +11357,251 @@ function ownEntries(sources, keep = () => true) {
11356
11357
  var createNamespace = (...sources) => ownEntries(sources);
11357
11358
  Object.freeze(createNamespace());
11358
11359
  //#endregion
11360
+ //#region src/static-literal.ts
11361
+ /**
11362
+ * The shape of a JavaScript literal, read from its text without running it:
11363
+ * what a StoryVariables initializer is when it is a literal, or an array or
11364
+ * object literal of literals (see parseDeclarations in story-variables.ts).
11365
+ *
11366
+ * The reader is deliberately small. Anything it does not recognise (a call,
11367
+ * an operator, a reference, a spread) is "not static", which is no error: the
11368
+ * value is simply not known without running the code.
11369
+ */
11370
+ var NUMBER_RE = /(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(?:[eE][+-]?\d+)?)(n?)/y;
11371
+ var IDENT_RE = /[A-Za-z_$][\w$]*/y;
11372
+ var ARROW_RE = /(?:async\s+)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*=>/y;
11373
+ /** Read `src`, one literal and nothing else. */
11374
+ function staticLiteral(src) {
11375
+ const reader = new Reader(src);
11376
+ const value = reader.value();
11377
+ reader.space();
11378
+ return reader.i === src.length ? value : void 0;
11379
+ }
11380
+ var Reader = class {
11381
+ constructor(src) {
11382
+ this.src = src;
11383
+ this.i = 0;
11384
+ }
11385
+ /** Skip whitespace and comments. */
11386
+ space() {
11387
+ const { src } = this;
11388
+ for (;;) {
11389
+ while (/\s/.test(src.charAt(this.i))) this.i++;
11390
+ if (src.startsWith("//", this.i)) {
11391
+ const end = src.indexOf("\n", this.i);
11392
+ this.i = end < 0 ? src.length : end;
11393
+ } else if (src.startsWith("/*", this.i)) {
11394
+ const end = src.indexOf("*/", this.i + 2);
11395
+ this.i = end < 0 ? src.length : end + 2;
11396
+ } else return;
11397
+ }
11398
+ }
11399
+ /** The value at the cursor, which is left after it (or anywhere, if not static). */
11400
+ value() {
11401
+ const { src } = this;
11402
+ this.space();
11403
+ const c = src.charAt(this.i);
11404
+ if (c === "\"" || c === "'") return this.string().closed ? { shape: { type: "string" } } : void 0;
11405
+ if (c === "`") return this.template();
11406
+ if (c === "[") return this.skipBalanced() ? { shape: { type: "array" } } : void 0;
11407
+ if (c === "{") return this.object();
11408
+ if (/[\d.+-]/.test(c)) return this.number();
11409
+ if (/[A-Za-z_$(]/.test(c)) return this.word();
11410
+ }
11411
+ /** Skip the string literal at the cursor: its body, and whether it is closed. */
11412
+ string() {
11413
+ const { end, closed } = scanStringLiteral(this.src, this.i);
11414
+ const body = this.src.slice(this.i + 1, closed ? end - 1 : end);
11415
+ this.i = end;
11416
+ return {
11417
+ body,
11418
+ closed
11419
+ };
11420
+ }
11421
+ /** A template literal: a string, but for `${}`. */
11422
+ template() {
11423
+ const { src } = this;
11424
+ for (let i = this.i + 1; i < src.length; i++) {
11425
+ const c = src.charAt(i);
11426
+ if (c === "\\") i++;
11427
+ else if (c === "`") {
11428
+ this.i = i + 1;
11429
+ return { shape: { type: "string" } };
11430
+ } else if (c === "$" && src.charAt(i + 1) === "{") return void 0;
11431
+ }
11432
+ }
11433
+ /** A number, or a sign and one. */
11434
+ number() {
11435
+ const { src } = this;
11436
+ let i = this.i;
11437
+ if (src.charAt(i) === "+" || src.charAt(i) === "-") {
11438
+ i++;
11439
+ while (/\s/.test(src.charAt(i))) i++;
11440
+ }
11441
+ NUMBER_RE.lastIndex = i;
11442
+ const match = NUMBER_RE.exec(src);
11443
+ if (match) {
11444
+ this.i = NUMBER_RE.lastIndex;
11445
+ return match[1] ? { unsupported: "bigint" } : { shape: { type: "number" } };
11446
+ }
11447
+ IDENT_RE.lastIndex = i;
11448
+ if (IDENT_RE.exec(src)?.[0] === "Infinity") {
11449
+ this.i = IDENT_RE.lastIndex;
11450
+ return { shape: { type: "number" } };
11451
+ }
11452
+ }
11453
+ /** A keyword, a function, or a name (which is not static). */
11454
+ word() {
11455
+ const { src } = this;
11456
+ ARROW_RE.lastIndex = this.i;
11457
+ if (ARROW_RE.test(src)) return this.function();
11458
+ IDENT_RE.lastIndex = this.i;
11459
+ const word = IDENT_RE.exec(src)?.[0];
11460
+ if (word === void 0) return void 0;
11461
+ const end = IDENT_RE.lastIndex;
11462
+ switch (word) {
11463
+ case "true":
11464
+ case "false":
11465
+ this.i = end;
11466
+ return { shape: { type: "boolean" } };
11467
+ case "null":
11468
+ this.i = end;
11469
+ return { shape: { type: "null" } };
11470
+ case "NaN":
11471
+ this.i = end;
11472
+ return { shape: { type: "number" } };
11473
+ case "undefined":
11474
+ this.i = end;
11475
+ return { unsupported: "undefined" };
11476
+ case "function":
11477
+ case "class":
11478
+ case "async": return this.function();
11479
+ }
11480
+ }
11481
+ /** A function (or class): the rest is its body, which is not read. */
11482
+ function() {
11483
+ return this.unsupported({ unsupported: "function" });
11484
+ }
11485
+ /** `value`, which makes the whole literal unsupported: the rest is not read. */
11486
+ unsupported(value) {
11487
+ this.i = this.src.length;
11488
+ return value;
11489
+ }
11490
+ /** An object literal: the members that are static. */
11491
+ object() {
11492
+ const { src } = this;
11493
+ const fields = /* @__PURE__ */ new Map();
11494
+ this.i++;
11495
+ for (;;) {
11496
+ this.space();
11497
+ const c = src.charAt(this.i);
11498
+ if (c === "}") {
11499
+ this.i++;
11500
+ return { shape: {
11501
+ type: "object",
11502
+ fields
11503
+ } };
11504
+ }
11505
+ if (c === ",") {
11506
+ this.i++;
11507
+ continue;
11508
+ }
11509
+ if (this.i >= src.length) return void 0;
11510
+ const key = this.key();
11511
+ this.space();
11512
+ if (key !== void 0 && src.charAt(this.i) === ":") {
11513
+ this.i++;
11514
+ const at = this.i;
11515
+ const value = this.value();
11516
+ this.space();
11517
+ if (value && "unsupported" in value) return this.unsupported(value);
11518
+ if (value && ",}".includes(src.charAt(this.i))) {
11519
+ fields.set(key, value.shape);
11520
+ continue;
11521
+ }
11522
+ this.i = at;
11523
+ } else if (key !== void 0 && src.charAt(this.i) === "(") return this.unsupported({ unsupported: "function" });
11524
+ if (!this.skipMember()) return void 0;
11525
+ }
11526
+ }
11527
+ /** The key of a member (a name, a string or a number), if it has one. */
11528
+ key() {
11529
+ const { src } = this;
11530
+ const c = src.charAt(this.i);
11531
+ if (c === "\"" || c === "'") {
11532
+ const { body, closed } = this.string();
11533
+ return closed ? body : void 0;
11534
+ }
11535
+ const word = /[\w$]+/y;
11536
+ word.lastIndex = this.i;
11537
+ const found = word.exec(src)?.[0];
11538
+ if (found === void 0) return void 0;
11539
+ this.i = word.lastIndex;
11540
+ return found;
11541
+ }
11542
+ /** Skip to the `,` or `}` that ends a member, balancing what is inside. */
11543
+ skipMember() {
11544
+ const { src } = this;
11545
+ while (this.i < src.length) {
11546
+ const c = src.charAt(this.i);
11547
+ if (c === "," || c === "}") return true;
11548
+ if (!this.skipOne()) return false;
11549
+ }
11550
+ return false;
11551
+ }
11552
+ /** Skip an array literal (or any bracketed group) at the cursor. */
11553
+ skipBalanced() {
11554
+ const { src } = this;
11555
+ const close = {
11556
+ "[": "]",
11557
+ "{": "}",
11558
+ "(": ")"
11559
+ }[src.charAt(this.i)];
11560
+ if (!close) return false;
11561
+ this.i++;
11562
+ while (this.i < src.length) {
11563
+ if (src.charAt(this.i) === close) {
11564
+ this.i++;
11565
+ return true;
11566
+ }
11567
+ if (!this.skipOne()) return false;
11568
+ }
11569
+ return false;
11570
+ }
11571
+ /** Skip one character, or one string, template, comment or group. */
11572
+ skipOne() {
11573
+ const { src } = this;
11574
+ const c = src.charAt(this.i);
11575
+ if (c === "\"" || c === "'") return this.string().closed;
11576
+ if (c === "`") return this.skipTemplate();
11577
+ if (src.startsWith("//", this.i) || src.startsWith("/*", this.i)) {
11578
+ this.space();
11579
+ return true;
11580
+ }
11581
+ if (c === "[" || c === "{" || c === "(") return this.skipBalanced();
11582
+ if (c === "]" || c === "}" || c === ")") return false;
11583
+ this.i++;
11584
+ return true;
11585
+ }
11586
+ /** Skip a template literal, with the expressions in it. */
11587
+ skipTemplate() {
11588
+ const { src } = this;
11589
+ this.i++;
11590
+ while (this.i < src.length) {
11591
+ const c = src.charAt(this.i);
11592
+ if (c === "\\") this.i += 2;
11593
+ else if (c === "`") {
11594
+ this.i++;
11595
+ return true;
11596
+ } else if (c === "$" && src.charAt(this.i + 1) === "{") {
11597
+ this.i++;
11598
+ if (!this.skipBalanced()) return false;
11599
+ } else this.i++;
11600
+ }
11601
+ return false;
11602
+ }
11603
+ };
11604
+ //#endregion
11359
11605
  //#region src/story-variables.ts
11360
11606
  function declarationRegex(sigil) {
11361
11607
  const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -11390,22 +11636,101 @@ function inferSchema(value, seen = /* @__PURE__ */ new Map()) {
11390
11636
  if (!VALID_VAR_TYPES.has(jsType)) throw new Error(`Unsupported type "${jsType}" for value ${String(value)}. Expected number, string, boolean, array, or object.`);
11391
11637
  return { type: jsType };
11392
11638
  }
11639
+ var UNSUPPORTED_TYPE = "Expected number, string, boolean, array, or object.";
11640
+ /** The schema of a literal shape (see staticLiteral). */
11641
+ function shapeSchema(shape) {
11642
+ if (!shape.fields) return { type: shape.type };
11643
+ const fields = /* @__PURE__ */ new Map();
11644
+ for (const [key, member] of shape.fields) fields.set(key, shapeSchema(member));
11645
+ return {
11646
+ type: shape.type,
11647
+ fields
11648
+ };
11649
+ }
11393
11650
  /**
11394
- * Parse a StoryVariables or StoryTransients passage content into a schema map.
11395
- * Each line: `$varName = expression` (or `%varName = expression` for transients)
11651
+ * Read the declarations of a StoryVariables (`$name = value`) or
11652
+ * StoryTransients (`%name = value`) passage, without evaluating them and
11653
+ * without throwing: every valid declaration, and every invalid line as an
11654
+ * error. It is the grammar parseStoryVariables reads with.
11655
+ *
11656
+ * A declaration is a line of the form `$name = expression`; blank lines are
11657
+ * skipped. A line that is not, and a name that cannot be a variable, are
11658
+ * errors. So is an initializer that no variable can hold (a function,
11659
+ * `undefined`), when it is a literal; whether any other initializer can only
11660
+ * be known by running it. A name declared again is an error too, but both
11661
+ * declarations are returned (the later wins when evaluated).
11396
11662
  */
11397
- function parseStoryVariables(content, sigil = "$") {
11398
- const schema = /* @__PURE__ */ new Map();
11663
+ function parseDeclarations(content, sigil = "$") {
11664
+ const declarations = [];
11665
+ const errors = [];
11399
11666
  const DECLARATION_RE = declarationRegex(sigil);
11400
- const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
11667
+ const seen = /* @__PURE__ */ new Set();
11668
+ let lineStart = 0;
11401
11669
  for (const rawLine of content.split("\n")) {
11670
+ const at = lineStart + rawLine.length - rawLine.trimStart().length;
11671
+ lineStart += rawLine.length + 1;
11402
11672
  const line = rawLine.trim();
11403
11673
  if (!line) continue;
11404
11674
  const match = line.match(DECLARATION_RE);
11405
- if (!match) throw new Error(`${passageName}: Invalid declaration: "${line}". Expected: ${sigil}name = value`);
11675
+ const error = (code, start, end, message) => errors.push({
11676
+ code,
11677
+ offset: start,
11678
+ end,
11679
+ message
11680
+ });
11681
+ if (!match) {
11682
+ error("invalid-declaration", at, at + line.length, `Invalid declaration: "${line}". Expected: ${sigil}name = value`);
11683
+ continue;
11684
+ }
11406
11685
  const [, name, expr] = match;
11686
+ const nameStart = at + sigil.length;
11687
+ const nameEnd = nameStart + name.length;
11407
11688
  const nameError = variableNameError(name, sigil + name);
11408
- if (nameError) throw new Error(`${passageName}: ${nameError}`);
11689
+ if (nameError) {
11690
+ error("invalid-name", nameStart, nameEnd, nameError);
11691
+ continue;
11692
+ }
11693
+ const valueEnd = at + line.length;
11694
+ const declaration = {
11695
+ name,
11696
+ nameStart,
11697
+ nameEnd,
11698
+ valueStart: valueEnd - expr.length,
11699
+ valueEnd
11700
+ };
11701
+ if (seen.has(name)) error("duplicate-declaration", nameStart, nameEnd, `Duplicate declaration of ${sigil}${name}`);
11702
+ seen.add(name);
11703
+ const literal = staticLiteral(expr);
11704
+ if (literal && "shape" in literal) declaration.schema = shapeSchema(literal.shape);
11705
+ else if (literal) error("unsupported-value", declaration.valueStart, valueEnd, `Unsupported type "${literal.unsupported}" for value ${expr}. ${UNSUPPORTED_TYPE}`);
11706
+ declarations.push(declaration);
11707
+ }
11708
+ return {
11709
+ declarations,
11710
+ errors
11711
+ };
11712
+ }
11713
+ /**
11714
+ * Parse a StoryVariables or StoryTransients passage content into a schema map.
11715
+ * Each line: `$varName = expression` (or `%varName = expression` for transients)
11716
+ * The expressions are evaluated; parseDeclarations reads the same lines
11717
+ * without.
11718
+ */
11719
+ function parseStoryVariables(content, sigil = "$") {
11720
+ const schema = /* @__PURE__ */ new Map();
11721
+ const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
11722
+ const { declarations, errors } = parseDeclarations(content, sigil);
11723
+ const lines = [...errors.filter((e) => e.code === "invalid-declaration" || e.code === "invalid-name").map((e) => ({
11724
+ at: e.offset,
11725
+ error: e
11726
+ })), ...declarations.map((d) => ({
11727
+ at: d.nameStart,
11728
+ declaration: d
11729
+ }))].sort((a, b) => a.at - b.at);
11730
+ for (const line of lines) {
11731
+ if ("error" in line) throw new Error(`${passageName}: ${line.error.message}`);
11732
+ const { name, valueStart, valueEnd } = line.declaration;
11733
+ const expr = content.slice(valueStart, valueEnd);
11409
11734
  let value;
11410
11735
  try {
11411
11736
  value = new Function("return (" + expr + ")")();
@@ -11538,14 +11863,46 @@ function validateStoryMarkup(passages, macros, options = {}) {
11538
11863
  checkPassageNames: options.checkPassageNames
11539
11864
  });
11540
11865
  }
11866
+ /** Whether a macro takes a body, among `macros` and the built-in ones. */
11867
+ function blockLookup(macros) {
11868
+ const blocks = new Set(macros.filter((m) => m.block).map((m) => m.name.toLowerCase()));
11869
+ return (name) => blocks.has(name.toLowerCase()) || isBlockMacro(name);
11870
+ }
11871
+ /**
11872
+ * What a passage's markup runs and names, and where: the pieces of code
11873
+ * (`{$expr}` displays, `{do}` bodies, conditions, macro arguments by their
11874
+ * declared parameter types, strings that hold code), the passage names written
11875
+ * out (links, `passage` arguments), the texts that hold markup of their own
11876
+ * (labels, attribute values) and the arguments that don't have their
11877
+ * parameters' forms, in source order with offsets (UTF-16) into `source`. The
11878
+ * markup in a text follows it, as pieces marked `nested` with offsets into
11879
+ * `source` too. Malformed tags are skipped, so it reads half-typed markup.
11880
+ * The macros are those the markup may use, built-in and user-defined.
11881
+ */
11882
+ function passagePieces(source, macros = []) {
11883
+ const all = [...macros];
11884
+ const { tokens } = tokenizeMarkupTolerant(source);
11885
+ return [...passagePiecesOf(source, tokens, parameterLookup(all), { isBlock: blockLookup(all) })];
11886
+ }
11541
11887
  /**
11542
11888
  * The passages the markup of `source` names (see PassageReference), against
11543
11889
  * the given macros: what the story-start check looks up. Malformed tags are
11544
- * skipped, so it reads half-typed markup.
11890
+ * skipped, so it reads half-typed markup. It is `passagePieces`, less what
11891
+ * names no passage.
11545
11892
  */
11546
11893
  function collectStoryPassageReferences(source, macros) {
11547
- const { tokens } = tokenizeMarkupTolerant(source);
11548
- return collectPassageReferences(source, tokens, parameterLookup(macros));
11894
+ return referencesOf(passagePieces(source, macros));
11895
+ }
11896
+ /**
11897
+ * The widgets the story defines, as the runtime reads them: those of
11898
+ * StoryInit and of the passages tagged `widget`, with their parameters,
11899
+ * whether their body renders `{@children}` (a block widget) and where they
11900
+ * are written, in source order. Half-typed definitions are reported without a
11901
+ * `closeStart`. The macros are those the markup may use, built-in and
11902
+ * user-defined (a `{@children}` in an attribute or label counts).
11903
+ */
11904
+ function widgetDefinitions(passages, macros = []) {
11905
+ return widgetDefinitions$1(passages, parameterLookup([...macros]));
11549
11906
  }
11550
11907
  //#endregion
11551
- export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, isSigil, lexJs, lexTemplate, parseSelectors, parseStoryVariables, passageTarget, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup };
11908
+ export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, isBlockMacro, isSigil, lexJs, lexTemplate, pairMarkup, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, widgetDefinitions };