@rohal12/spindle 0.59.22 → 0.59.23

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.
@@ -105,18 +105,13 @@ var VOID_TAGS = new Set([
105
105
  "track",
106
106
  "wbr"
107
107
  ]);
108
- var BRANCH_PARENT = {
108
+ var BRANCH_PARENT$1 = {
109
109
  elseif: "if",
110
110
  else: "if",
111
111
  case: "switch",
112
112
  default: "switch",
113
113
  next: "timed"
114
114
  };
115
- var BRANCHING = new Set([
116
- "if",
117
- "switch",
118
- "timed"
119
- ]);
120
115
  var LINK_SEPARATORS = [
121
116
  ["|", false],
122
117
  ["->", false],
@@ -153,6 +148,8 @@ function parseLink(inner, at, indexOf) {
153
148
  const [display, target] = targetFirst ? [after, before] : [before, after];
154
149
  return {
155
150
  display: display.value,
151
+ displayStart: display.start,
152
+ displayEnd: display.end,
156
153
  target: target.value,
157
154
  targetStart: target.start,
158
155
  targetEnd: target.end
@@ -161,14 +158,13 @@ function parseLink(inner, at, indexOf) {
161
158
  const whole = part(0, inner.length);
162
159
  return {
163
160
  display: whole.value,
161
+ displayStart: whole.start,
162
+ displayEnd: whole.end,
164
163
  target: whole.value,
165
164
  targetStart: whole.start,
166
165
  targetEnd: whole.end
167
166
  };
168
167
  }
169
- function quoteArg(value) {
170
- return "\"" + value.replace(/[\\"]/g, "\\$&") + "\"";
171
- }
172
168
  function selectorsOf(parts) {
173
169
  const classes = [];
174
170
  let id = "";
@@ -187,15 +183,6 @@ function label(tag) {
187
183
  if (tag.lex === "html") return (tag.isClose ? "</" : "<") + tag.tag + ">";
188
184
  return LB + (tag.isClose ? "/" : "") + tag.name + RB;
189
185
  }
190
- function closerOf(tag) {
191
- return tag.lex === "html" ? "</" + tag.tag + ">" : LB + "/" + tag.name + RB;
192
- }
193
- function at(loc) {
194
- return "line " + loc.start.line + ", column " + loc.start.column;
195
- }
196
- function sameName(open, close) {
197
- return open.lex === close.lex && open.lower === close.lower;
198
- }
199
186
  /** A lexeme: what one token of the flat stream holds, with its span. */
200
187
  function lexeme(lex, loc, fields) {
201
188
  fields.lex = lex;
@@ -204,35 +191,6 @@ function lexeme(lex, loc, fields) {
204
191
  fields.loc = loc;
205
192
  return fields;
206
193
  }
207
- /** The AST node of a lexeme that stands alone (not a macro or element). */
208
- function nodeOf(x) {
209
- switch (x.lex) {
210
- case "text": return x.comment ? {
211
- type: "text",
212
- value: x.value,
213
- comment: true
214
- } : {
215
- type: "text",
216
- value: x.value
217
- };
218
- case "link": return withSelectors({
219
- type: "macro",
220
- name: "link",
221
- rawArgs: quoteArg(x.display) + " " + quoteArg(x.target),
222
- children: []
223
- }, x);
224
- case "variable": return withSelectors({
225
- type: "variable",
226
- name: x.name,
227
- scope: x.scope
228
- }, x);
229
- case "expression": return withSelectors({
230
- type: "expression",
231
- expression: x.expression
232
- }, x);
233
- default: return x;
234
- }
235
- }
236
194
  /** The token of a lexeme (tokens.ts Token). */
237
195
  function tokenOf(x) {
238
196
  const span = {
@@ -240,7 +198,12 @@ function tokenOf(x) {
240
198
  end: x.end
241
199
  };
242
200
  switch (x.lex) {
243
- case "text": return {
201
+ case "text": return x.comment ? {
202
+ type: "text",
203
+ value: x.value,
204
+ comment: true,
205
+ ...span
206
+ } : {
244
207
  type: "text",
245
208
  value: x.value,
246
209
  ...span
@@ -248,33 +211,50 @@ function tokenOf(x) {
248
211
  case "link": return withSelectors({
249
212
  type: "link",
250
213
  display: x.display,
214
+ displayStart: x.displayStart,
215
+ displayEnd: x.displayEnd,
251
216
  target: x.target,
252
217
  targetStart: x.targetStart,
253
218
  targetEnd: x.targetEnd,
219
+ ...x.selectorSpan,
254
220
  ...span
255
221
  }, x);
256
222
  case "variable": return withSelectors({
257
223
  type: "variable",
258
224
  name: x.name,
225
+ nameStart: x.nameStart,
226
+ nameEnd: x.nameEnd,
259
227
  scope: x.scope,
228
+ ...x.selectorSpan,
260
229
  ...span
261
230
  }, x);
262
231
  case "expression": return withSelectors({
263
232
  type: "expression",
264
233
  expression: x.expression,
234
+ expressionStart: x.expressionStart,
235
+ expressionEnd: x.expressionEnd,
236
+ ...x.selectorSpan,
265
237
  ...span
266
238
  }, x);
267
239
  case "macro": return withSelectors({
268
240
  type: "macro",
269
241
  name: x.name,
242
+ nameStart: x.nameStart,
243
+ nameEnd: x.nameEnd,
270
244
  rawArgs: x.rawArgs,
245
+ argsStart: x.argsStart,
246
+ argsEnd: x.argsEnd,
271
247
  isClose: x.isClose,
248
+ ...x.selectorSpan,
272
249
  ...span
273
250
  }, x);
274
251
  case "html": return {
275
252
  type: "html",
276
253
  tag: x.tag,
254
+ tagNameStart: x.tagNameStart,
255
+ tagNameEnd: x.tagNameEnd,
277
256
  attributes: x.attributes,
257
+ attributeSpans: x.attributeSpans,
278
258
  isClose: x.isClose,
279
259
  isSelfClose: x.isSelfClose,
280
260
  ...span
@@ -285,7 +265,7 @@ function tokenOf(x) {
285
265
  * Flatten items (lexemes, nodes, arrays of them, nulls) and join adjacent
286
266
  * text, except escaped braces and comments, which stay a text item of their own.
287
267
  */
288
- function joinText(items, convert) {
268
+ function joinText(items) {
289
269
  const out = [];
290
270
  let last = null;
291
271
  const add = (item) => {
@@ -300,7 +280,7 @@ function joinText(items, convert) {
300
280
  last = item;
301
281
  };
302
282
  add(items);
303
- return convert ? out.map(convert) : out;
283
+ return out.map(tokenOf);
304
284
  }
305
285
  var peg$SyntaxError = class extends SyntaxError {
306
286
  constructor(message, expected, found, location) {
@@ -393,11 +373,10 @@ function peg$parse(input, options) {
393
373
  const peg$FAILED = {};
394
374
  const peg$source = options.grammarSource;
395
375
  const peg$startRuleFunctions = {
396
- Markup: peg$parseMarkup,
397
376
  Tokens: peg$parseTokens,
398
377
  SelectorsPrefix: peg$parseSelectorsPrefix
399
378
  };
400
- let peg$startRuleFunction = peg$parseMarkup;
379
+ let peg$startRuleFunction = peg$parseTokens;
401
380
  const peg$c0 = "<!--";
402
381
  const peg$c1 = ">";
403
382
  const peg$c2 = "->";
@@ -627,175 +606,74 @@ function peg$parse(input, options) {
627
606
  " ",
628
607
  ""
629
608
  ], false, false, false);
630
- function peg$f0(nodes) {
631
- return nodes;
609
+ function peg$f0(items) {
610
+ return joinText(items);
632
611
  }
633
- function peg$f1(tag) {
634
- fail(label(tag) + " must be directly inside {" + BRANCH_PARENT[tag.lower] + RB, tag.loc);
612
+ function peg$f1() {
613
+ return !textMode;
635
614
  }
636
615
  function peg$f2(tag) {
637
- fail(label(tag) + " closes nothing: no " + (tag.lex === "html" ? "<" + tag.tag + ">" : LB + tag.name + RB) + " is open here", tag.loc);
616
+ return tag;
638
617
  }
639
- function peg$f3(items) {
640
- return joinText(items, nodeOf);
618
+ function peg$f3() {
619
+ return !textMode;
641
620
  }
642
621
  function peg$f4(tag) {
643
- return tag.kind === "open";
622
+ return VOID_TAGS.has(tag.lower) ? null : tag;
644
623
  }
645
624
  function peg$f5(tag) {
646
625
  rawName = tag.lower;
647
- return hooks.isRaw(rawName);
626
+ return tag.kind === "open" && hooks.isRaw(rawName);
648
627
  }
649
628
  function peg$f6(tag, b) {
650
629
  return b;
651
630
  }
652
- function peg$f7(tag) {
653
- return hooks.isBlock(tag.lower);
654
- }
655
- function peg$f8(tag, b) {
656
- return b;
657
- }
658
- function peg$f9(tag) {
659
- return null;
660
- }
661
- function peg$f10(tag, body) {
662
- return macroNode(tag, body);
663
- }
664
- function peg$f11() {
665
- return !textMode;
666
- }
667
- function peg$f12(open) {
668
- return !open.isSelfClose;
669
- }
670
- function peg$f13(open, b) {
671
- return b;
672
- }
673
- function peg$f14(open, body) {
674
- const node = {
675
- type: "html",
676
- tag: open.tag,
677
- attributes: open.attributes,
678
- children: []
679
- };
680
- if (body) {
681
- checkBody(open, body);
682
- node.children = body.children;
683
- }
684
- return node;
685
- }
686
- function peg$f15(children, branches, end) {
687
- return {
688
- children,
689
- branches,
690
- end
691
- };
692
- }
693
- function peg$f16(tag, children) {
694
- return {
695
- tag,
696
- children
697
- };
698
- }
699
- function peg$f17() {
700
- return null;
701
- }
702
- function peg$f18(tag) {
703
- return tag.kind === "branch";
704
- }
705
- function peg$f19(tag) {
706
- return tag;
631
+ function peg$f7(tag, body) {
632
+ return body ? [tag, body] : tag;
707
633
  }
708
- function peg$f20(tag) {
634
+ function peg$f8(tag) {
709
635
  return tag.kind === "close";
710
636
  }
711
- function peg$f21(tag) {
712
- return tag;
713
- }
714
- function peg$f22() {
715
- return !textMode;
716
- }
717
- function peg$f23(tag) {
637
+ function peg$f9(tag) {
718
638
  return tag;
719
639
  }
720
- function peg$f24(start) {
721
- return skipTo(hooks.rawBodyEnd(input, start, rawName));
722
- }
723
- function peg$f25(start) {
724
- return skipEnd - offset();
725
- }
726
- function peg$f26(start, body, end) {
727
- return {
728
- children: body ? [{
729
- type: "text",
730
- value: body
731
- }] : [],
732
- branches: [],
733
- end
734
- };
735
- }
736
- function peg$f27() {
737
- return {
738
- children: [],
739
- branches: [],
740
- end: null
741
- };
742
- }
743
- function peg$f28(items) {
744
- return joinText(items, tokenOf);
745
- }
746
- function peg$f29() {
640
+ function peg$f10() {
747
641
  return !textMode;
748
642
  }
749
- function peg$f30(tag) {
643
+ function peg$f11(tag) {
750
644
  return tag;
751
645
  }
752
- function peg$f31() {
753
- return !textMode;
754
- }
755
- function peg$f32(tag) {
756
- return VOID_TAGS.has(tag.lower) ? null : tag;
757
- }
758
- function peg$f33(tag) {
759
- rawName = tag.lower;
760
- return tag.kind === "open" && hooks.isRaw(rawName);
761
- }
762
- function peg$f34(tag, b) {
763
- return b;
764
- }
765
- function peg$f35(tag, body) {
766
- return body ? [tag, body] : tag;
767
- }
768
- function peg$f36(start) {
646
+ function peg$f12(start) {
769
647
  return skipTo(hooks.rawBodyEnd(input, start, rawName));
770
648
  }
771
- function peg$f37(start) {
649
+ function peg$f13(start) {
772
650
  return skipEnd - offset();
773
651
  }
774
- function peg$f38(start, body, end) {
652
+ function peg$f14(start, body, end) {
775
653
  const loc = {
776
654
  start: { offset: start },
777
655
  end: { offset: start + body.length }
778
656
  };
779
657
  return [body ? lexeme("text", loc, { value: body }) : null, end];
780
658
  }
781
- function peg$f39() {
659
+ function peg$f15() {
782
660
  return offset();
783
661
  }
784
- function peg$f40(value) {
662
+ function peg$f16(value) {
785
663
  return lexeme("text", location(), { value });
786
664
  }
787
- function peg$f41(value) {
665
+ function peg$f17(value) {
788
666
  const node = lexeme("text", location(), { value });
789
667
  node.comment = true;
790
668
  return node;
791
669
  }
792
- function peg$f42(bs) {
670
+ function peg$f18(bs) {
793
671
  return bs.length % 2 === 1;
794
672
  }
795
- function peg$f43(bs, c) {
673
+ function peg$f19(bs, c) {
796
674
  return c;
797
675
  }
798
- function peg$f44(bs, brace) {
676
+ function peg$f20(bs, brace) {
799
677
  const loc = location();
800
678
  const next = input.charAt(loc.end.offset);
801
679
  if (textMode) {
@@ -812,76 +690,88 @@ function peg$parse(input, options) {
812
690
  escaped.escape = true;
813
691
  return bs.length > 1 ? [before, escaped] : escaped;
814
692
  }
815
- function peg$f45() {
693
+ function peg$f21() {
816
694
  return lexeme("text", location(), { value: LB });
817
695
  }
818
- function peg$f46() {
696
+ function peg$f22() {
819
697
  return !textMode;
820
698
  }
821
- function peg$f47() {
699
+ function peg$f23() {
822
700
  return lexeme("text", location(), { value: "<" });
823
701
  }
824
- function peg$f48() {
702
+ function peg$f24() {
825
703
  return lexeme("text", location(), { value: "[" });
826
704
  }
827
- function peg$f49() {
705
+ function peg$f25() {
828
706
  return !textMode;
829
707
  }
830
- function peg$f50(s, at, inner) {
831
- return withSelectors(lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator))), s);
708
+ function peg$f26(ss, s, at, inner) {
709
+ const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
710
+ link.selectorSpan = selectorSpan(s, ss, at);
711
+ return withSelectors(link, s);
832
712
  }
833
- function peg$f51() {
713
+ function peg$f27() {
834
714
  return !textMode;
835
715
  }
836
- function peg$f52() {
837
- fail("Unclosed link: [[ without ]]", location());
716
+ function peg$f28() {
717
+ fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
838
718
  }
839
- function peg$f53(parts) {
719
+ function peg$f29(parts) {
840
720
  return selectorsOf(parts);
841
721
  }
842
- function peg$f54() {
722
+ function peg$f30() {
843
723
  return NO_SELECTORS;
844
724
  }
845
- function peg$f55(s, end) {
725
+ function peg$f31(s, end) {
846
726
  return {
847
727
  ...s,
848
728
  end
849
729
  };
850
730
  }
851
- function peg$f56(prefix, name) {
731
+ function peg$f32(prefix, name) {
852
732
  return [prefix, name];
853
733
  }
854
- function peg$f57(s, sigil, name) {
855
- return withSelectors(lexeme("variable", location(), {
734
+ function peg$f33(ss, s, sigil, nameStart, name) {
735
+ const variable = lexeme("variable", location(), {
856
736
  name,
737
+ nameStart,
738
+ nameEnd: nameStart + name.length,
857
739
  scope: SIGIL_SCOPES[sigil]
858
- }), s);
859
- }
860
- function peg$f58(s, expression) {
861
- return withSelectors(lexeme("expression", location(), { expression }), s);
740
+ });
741
+ variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
742
+ return withSelectors(variable, s);
743
+ }
744
+ function peg$f34(ss, s, after, expression) {
745
+ const node = lexeme("expression", location(), {
746
+ expression,
747
+ expressionStart: after,
748
+ expressionEnd: after + expression.length
749
+ });
750
+ node.selectorSpan = selectorSpan(s, ss, after);
751
+ return withSelectors(node, s);
862
752
  }
863
- function peg$f59() {
864
- fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location());
753
+ function peg$f35() {
754
+ fail("Unclosed " + LB + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
865
755
  }
866
- function peg$f60(start) {
756
+ function peg$f36(start) {
867
757
  return skipTo(hooks.closeBrace(input, start, start));
868
758
  }
869
- function peg$f61(start) {
759
+ function peg$f37(start) {
870
760
  return skipEnd - offset();
871
761
  }
872
- function peg$f62(start, code) {
762
+ function peg$f38(start, code) {
873
763
  return code;
874
764
  }
875
- function peg$f63(s, start, close, name, nameEnd) {
765
+ function peg$f39(ss, s, start, close, name, nameEnd) {
876
766
  return skipTo(hooks.closeBrace(input, nameEnd, start));
877
767
  }
878
- function peg$f64(s, start, close, name, nameEnd) {
768
+ function peg$f40(ss, s, start, close, name, nameEnd) {
879
769
  return skipEnd - offset();
880
770
  }
881
- function peg$f65(s, start, close, name, nameEnd, args) {
771
+ function peg$f41(ss, s, start, close, name, nameEnd, args) {
882
772
  return args;
883
773
  }
884
- function peg$f66(s, start, close, name, nameEnd, tail) {
774
+ function peg$f42(ss, s, start, close, name, nameEnd, tail) {
885
775
  const loc = location();
886
776
  const lower = name.toLowerCase();
887
777
  const tag = lexeme("macro", loc, {
@@ -890,49 +780,48 @@ function peg$parse(input, options) {
890
780
  rawArgs: "",
891
781
  isClose: !!close
892
782
  });
893
- if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc);
783
+ tag.nameStart = nameEnd - name.length;
784
+ tag.nameEnd = nameEnd;
785
+ tag.selectorSpan = selectorSpan(s, ss, start);
786
+ if (tail === null) fail("Unclosed " + LB + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
894
787
  tag.rawArgs = tail.trim();
788
+ tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
789
+ tag.argsEnd = tag.argsStart + tag.rawArgs.length;
895
790
  if (close) {
896
- if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc);
897
- if (tag.rawArgs) fail("A closing tag takes no arguments: " + LB + "/" + name + " " + tag.rawArgs + RB, loc);
791
+ if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc, "closer-with-selectors");
792
+ if (tag.rawArgs) fail("A closing tag takes no arguments: " + LB + "/" + name + " " + tag.rawArgs + RB, loc, "closer-with-arguments");
898
793
  tag.kind = "close";
899
794
  } else {
900
795
  withSelectors(tag, s);
901
- tag.kind = Object.prototype.hasOwnProperty.call(BRANCH_PARENT, lower) ? "branch" : "open";
796
+ tag.kind = Object.prototype.hasOwnProperty.call(BRANCH_PARENT$1, lower) ? "branch" : "open";
902
797
  }
903
798
  return tag;
904
799
  }
905
- function peg$f67(s) {
906
- fail("A closing tag starts with a letter after " + LB + "/", location());
800
+ function peg$f43(s) {
801
+ fail("A closing tag starts with a letter after " + LB + "/", location(), "invalid-closer");
907
802
  }
908
- function peg$f68(value) {
803
+ function peg$f44(value) {
909
804
  return EMAIL_AUTOLINK.test(value);
910
805
  }
911
- function peg$f69(value) {
806
+ function peg$f45(value) {
912
807
  return lexeme("text", location(), { value });
913
808
  }
914
- function peg$f70() {
915
- return !textMode;
916
- }
917
- function peg$f71(tag) {
918
- return VOID_TAGS.has(tag.lower);
919
- }
920
- function peg$f72(tag) {
921
- return null;
922
- }
923
- function peg$f73(tag, list, slash) {
809
+ function peg$f46(tagStart, tag, list, slash) {
924
810
  const lower = tag.toLowerCase();
925
811
  return lexeme("html", location(), {
926
812
  tag,
927
813
  lower,
814
+ tagNameStart: tagStart,
815
+ tagNameEnd: tagStart + tag.length,
928
816
  attributes: attrs(list),
817
+ attributeSpans: list,
929
818
  isClose: false,
930
819
  isSelfClose: !!slash || VOID_TAGS.has(lower)
931
820
  });
932
821
  }
933
- function peg$f74(tag, bad) {
822
+ function peg$f47(tag, bad) {
934
823
  const c = input.charAt(bad);
935
- if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location());
824
+ if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
936
825
  const at = {
937
826
  source: location().source,
938
827
  start: {
@@ -946,55 +835,86 @@ function peg$parse(input, options) {
946
835
  column: 0
947
836
  }
948
837
  };
949
- fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at);
838
+ fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
950
839
  }
951
- function peg$f75(tag) {
840
+ function peg$f48(tagStart, tag) {
952
841
  return lexeme("html", location(), {
953
842
  tag,
954
843
  lower: tag.toLowerCase(),
844
+ tagNameStart: tagStart,
845
+ tagNameEnd: tagStart + tag.length,
955
846
  attributes: {},
847
+ attributeSpans: [],
956
848
  isClose: true,
957
849
  isSelfClose: false
958
850
  });
959
851
  }
960
- function peg$f76(name) {
852
+ function peg$f49(nameStart, name) {
961
853
  attrCode = hooks.isCodeAttribute(name);
962
854
  return true;
963
855
  }
964
- function peg$f77(name, v) {
856
+ function peg$f50(nameStart, name, v) {
965
857
  return v;
966
858
  }
967
- function peg$f78(name, value) {
968
- return [name, value ?? ""];
859
+ function peg$f51(nameStart, name, value) {
860
+ const attribute = {
861
+ name,
862
+ value: value ? value.value : "",
863
+ nameStart,
864
+ nameEnd: nameStart + name.length
865
+ };
866
+ if (value) {
867
+ attribute.valueStart = value.start;
868
+ attribute.valueEnd = value.end;
869
+ if (value.quote) attribute.quote = value.quote;
870
+ }
871
+ return attribute;
969
872
  }
970
- function peg$f79(v) {
971
- return v;
873
+ function peg$f52(start, value, end) {
874
+ return {
875
+ value,
876
+ start,
877
+ end,
878
+ quote: "\""
879
+ };
972
880
  }
973
- function peg$f80(v) {
974
- return v;
881
+ function peg$f53(start, value, end) {
882
+ return {
883
+ value,
884
+ start,
885
+ end,
886
+ quote: "'"
887
+ };
888
+ }
889
+ function peg$f54(q) {
890
+ fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
975
891
  }
976
- function peg$f81(q) {
977
- fail("Unclosed attribute value: the " + q + " here has no closing " + q, location());
892
+ function peg$f55(start, value, end) {
893
+ return {
894
+ value,
895
+ start,
896
+ end
897
+ };
978
898
  }
979
- function peg$f82() {
899
+ function peg$f56() {
980
900
  return !attrCode;
981
901
  }
982
- function peg$f83(bs) {
902
+ function peg$f57(bs) {
983
903
  return bs.length % 2 === 1;
984
904
  }
985
- function peg$f84() {
905
+ function peg$f58() {
986
906
  return !attrCode;
987
907
  }
988
- function peg$f85(start, nameEnd) {
908
+ function peg$f59(start, nameEnd) {
989
909
  return skipTo(hooks.closeBrace(input, nameEnd, start));
990
910
  }
991
- function peg$f86(start, nameEnd) {
911
+ function peg$f60(start, nameEnd) {
992
912
  return skipEnd - offset();
993
913
  }
994
- function peg$f87() {
914
+ function peg$f61() {
995
915
  return !attrCode;
996
916
  }
997
- function peg$f88() {
917
+ function peg$f62() {
998
918
  return attrCode;
999
919
  }
1000
920
  let peg$currPos = options.peg$currPos | 0;
@@ -1110,73 +1030,22 @@ function peg$parse(input, options) {
1110
1030
  function peg$buildStructuredError(expected, found, location) {
1111
1031
  return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1112
1032
  }
1113
- function peg$parseMarkup() {
1114
- let s0, s1, s2;
1115
- s0 = peg$currPos;
1116
- s1 = peg$parseContent();
1117
- s2 = peg$parseTail();
1118
- if (s2 !== peg$FAILED) {
1119
- peg$savedPos = s0;
1120
- s0 = peg$f0(s1);
1121
- } else {
1122
- peg$currPos = s0;
1123
- s0 = peg$FAILED;
1124
- }
1125
- return s0;
1126
- }
1127
- function peg$parseTail() {
1128
- let s0, s1;
1129
- s0 = peg$currPos;
1130
- peg$silentFails++;
1131
- if (input.length > peg$currPos) {
1132
- s1 = input.charAt(peg$currPos);
1133
- peg$currPos++;
1134
- } else {
1135
- s1 = peg$FAILED;
1136
- if (peg$silentFails === 0) peg$fail(peg$e0);
1137
- }
1138
- peg$silentFails--;
1139
- if (s1 === peg$FAILED) s0 = void 0;
1140
- else {
1141
- peg$currPos = s0;
1142
- s0 = peg$FAILED;
1143
- }
1144
- if (s0 === peg$FAILED) {
1145
- s0 = peg$currPos;
1146
- s1 = peg$parseBranchTag();
1147
- if (s1 !== peg$FAILED) {
1148
- peg$savedPos = s0;
1149
- s1 = peg$f1(s1);
1150
- }
1151
- s0 = s1;
1152
- if (s0 === peg$FAILED) {
1153
- s0 = peg$currPos;
1154
- s1 = peg$parseCloseTag();
1155
- if (s1 !== peg$FAILED) {
1156
- peg$savedPos = s0;
1157
- s1 = peg$f2(s1);
1158
- }
1159
- s0 = s1;
1160
- }
1161
- }
1162
- return s0;
1163
- }
1164
- function peg$parseContent() {
1033
+ function peg$parseTokens() {
1165
1034
  let s0, s1, s2;
1166
1035
  s0 = peg$currPos;
1167
1036
  s1 = [];
1168
- s2 = peg$parseItem();
1037
+ s2 = peg$parseTokenItem();
1169
1038
  while (s2 !== peg$FAILED) {
1170
1039
  s1.push(s2);
1171
- s2 = peg$parseItem();
1040
+ s2 = peg$parseTokenItem();
1172
1041
  }
1173
1042
  peg$savedPos = s0;
1174
- s1 = peg$f3(s1);
1043
+ s1 = peg$f0(s1);
1175
1044
  s0 = s1;
1176
1045
  return s0;
1177
1046
  }
1178
- function peg$parseItem() {
1179
- let s0;
1047
+ function peg$parseTokenItem() {
1048
+ let s0, s1, s2, s3, s4;
1180
1049
  s0 = peg$parseTextRun();
1181
1050
  if (s0 === peg$FAILED) {
1182
1051
  s0 = peg$parseEscape();
@@ -1187,13 +1056,74 @@ function peg$parse(input, options) {
1187
1056
  if (s0 === peg$FAILED) {
1188
1057
  s0 = peg$parseEmailAutolink();
1189
1058
  if (s0 === peg$FAILED) {
1190
- s0 = peg$parseHtmlElement();
1059
+ s0 = peg$currPos;
1060
+ peg$savedPos = peg$currPos;
1061
+ s1 = peg$f1();
1062
+ if (s1) s1 = void 0;
1063
+ else s1 = peg$FAILED;
1064
+ if (s1 !== peg$FAILED) {
1065
+ s2 = peg$parseHtmlOpen();
1066
+ if (s2 !== peg$FAILED) {
1067
+ peg$savedPos = s0;
1068
+ s0 = peg$f2(s2);
1069
+ } else {
1070
+ peg$currPos = s0;
1071
+ s0 = peg$FAILED;
1072
+ }
1073
+ } else {
1074
+ peg$currPos = s0;
1075
+ s0 = peg$FAILED;
1076
+ }
1191
1077
  if (s0 === peg$FAILED) {
1192
- s0 = peg$parseVoidCloser();
1078
+ s0 = peg$currPos;
1079
+ peg$savedPos = peg$currPos;
1080
+ s1 = peg$f3();
1081
+ if (s1) s1 = void 0;
1082
+ else s1 = peg$FAILED;
1083
+ if (s1 !== peg$FAILED) {
1084
+ s2 = peg$parseHtmlClose();
1085
+ if (s2 !== peg$FAILED) {
1086
+ peg$savedPos = s0;
1087
+ s0 = peg$f4(s2);
1088
+ } else {
1089
+ peg$currPos = s0;
1090
+ s0 = peg$FAILED;
1091
+ }
1092
+ } else {
1093
+ peg$currPos = s0;
1094
+ s0 = peg$FAILED;
1095
+ }
1193
1096
  if (s0 === peg$FAILED) {
1194
1097
  s0 = peg$parseValue();
1195
1098
  if (s0 === peg$FAILED) {
1196
- s0 = peg$parseMacroElement();
1099
+ s0 = peg$currPos;
1100
+ s1 = peg$parseMacroTag();
1101
+ if (s1 !== peg$FAILED) {
1102
+ s2 = peg$currPos;
1103
+ peg$savedPos = peg$currPos;
1104
+ s3 = peg$f5(s1);
1105
+ if (s3) s3 = void 0;
1106
+ else s3 = peg$FAILED;
1107
+ if (s3 !== peg$FAILED) {
1108
+ s4 = peg$parseRawTokens();
1109
+ if (s4 !== peg$FAILED) {
1110
+ peg$savedPos = s2;
1111
+ s2 = peg$f6(s1, s4);
1112
+ } else {
1113
+ peg$currPos = s2;
1114
+ s2 = peg$FAILED;
1115
+ }
1116
+ } else {
1117
+ peg$currPos = s2;
1118
+ s2 = peg$FAILED;
1119
+ }
1120
+ if (s2 === peg$FAILED) s2 = null;
1121
+ peg$savedPos = s0;
1122
+ s0 = peg$f7(s1, s2);
1123
+ } else {
1124
+ peg$currPos = s0;
1125
+ s0 = peg$FAILED;
1126
+ }
1197
1127
  if (s0 === peg$FAILED) s0 = peg$parseLiteral();
1198
1128
  }
1199
1129
  }
@@ -1205,225 +1135,18 @@ function peg$parse(input, options) {
1205
1135
  }
1206
1136
  return s0;
1207
1137
  }
1208
- function peg$parseMacroElement() {
1209
- let s0, s1, s2, s3, s4, s5;
1138
+ function peg$parseCloseTag() {
1139
+ let s0, s1, s2;
1210
1140
  s0 = peg$currPos;
1211
1141
  s1 = peg$parseMacroTag();
1212
1142
  if (s1 !== peg$FAILED) {
1213
1143
  peg$savedPos = peg$currPos;
1214
- s2 = peg$f4(s1);
1215
- if (s2) s2 = void 0;
1216
- else s2 = peg$FAILED;
1217
- if (s2 !== peg$FAILED) {
1218
- s3 = peg$currPos;
1219
- peg$savedPos = peg$currPos;
1220
- s4 = peg$f5(s1);
1221
- if (s4) s4 = void 0;
1222
- else s4 = peg$FAILED;
1223
- if (s4 !== peg$FAILED) {
1224
- s5 = peg$parseRawBody();
1225
- if (s5 !== peg$FAILED) {
1226
- peg$savedPos = s3;
1227
- s3 = peg$f6(s1, s5);
1228
- } else {
1229
- peg$currPos = s3;
1230
- s3 = peg$FAILED;
1231
- }
1232
- } else {
1233
- peg$currPos = s3;
1234
- s3 = peg$FAILED;
1235
- }
1236
- if (s3 === peg$FAILED) {
1237
- s3 = peg$currPos;
1238
- peg$savedPos = peg$currPos;
1239
- s4 = peg$f7(s1);
1240
- if (s4) s4 = void 0;
1241
- else s4 = peg$FAILED;
1242
- if (s4 !== peg$FAILED) {
1243
- s5 = peg$parseBlockBody();
1244
- if (s5 !== peg$FAILED) {
1245
- peg$savedPos = s3;
1246
- s3 = peg$f8(s1, s5);
1247
- } else {
1248
- peg$currPos = s3;
1249
- s3 = peg$FAILED;
1250
- }
1251
- } else {
1252
- peg$currPos = s3;
1253
- s3 = peg$FAILED;
1254
- }
1255
- if (s3 === peg$FAILED) {
1256
- s3 = peg$currPos;
1257
- s4 = "";
1258
- peg$savedPos = s3;
1259
- s4 = peg$f9(s1);
1260
- s3 = s4;
1261
- }
1262
- }
1263
- if (s3 !== peg$FAILED) {
1264
- peg$savedPos = s0;
1265
- s0 = peg$f10(s1, s3);
1266
- } else {
1267
- peg$currPos = s0;
1268
- s0 = peg$FAILED;
1269
- }
1270
- } else {
1271
- peg$currPos = s0;
1272
- s0 = peg$FAILED;
1273
- }
1274
- } else {
1275
- peg$currPos = s0;
1276
- s0 = peg$FAILED;
1277
- }
1278
- return s0;
1279
- }
1280
- function peg$parseHtmlElement() {
1281
- let s0, s1, s2, s3, s4, s5;
1282
- s0 = peg$currPos;
1283
- peg$savedPos = peg$currPos;
1284
- s1 = peg$f11();
1285
- if (s1) s1 = void 0;
1286
- else s1 = peg$FAILED;
1287
- if (s1 !== peg$FAILED) {
1288
- s2 = peg$parseHtmlOpen();
1289
- if (s2 !== peg$FAILED) {
1290
- s3 = peg$currPos;
1291
- peg$savedPos = peg$currPos;
1292
- s4 = peg$f12(s2);
1293
- if (s4) s4 = void 0;
1294
- else s4 = peg$FAILED;
1295
- if (s4 !== peg$FAILED) {
1296
- s5 = peg$parseBlockBody();
1297
- if (s5 !== peg$FAILED) {
1298
- peg$savedPos = s3;
1299
- s3 = peg$f13(s2, s5);
1300
- } else {
1301
- peg$currPos = s3;
1302
- s3 = peg$FAILED;
1303
- }
1304
- } else {
1305
- peg$currPos = s3;
1306
- s3 = peg$FAILED;
1307
- }
1308
- if (s3 === peg$FAILED) s3 = null;
1309
- peg$savedPos = s0;
1310
- s0 = peg$f14(s2, s3);
1311
- } else {
1312
- peg$currPos = s0;
1313
- s0 = peg$FAILED;
1314
- }
1315
- } else {
1316
- peg$currPos = s0;
1317
- s0 = peg$FAILED;
1318
- }
1319
- return s0;
1320
- }
1321
- function peg$parseBlockBody() {
1322
- let s0, s1, s2, s3;
1323
- s0 = peg$currPos;
1324
- s1 = peg$parseContent();
1325
- if (s1 !== peg$FAILED) {
1326
- s2 = [];
1327
- s3 = peg$parseBranchPart();
1328
- while (s3 !== peg$FAILED) {
1329
- s2.push(s3);
1330
- s3 = peg$parseBranchPart();
1331
- }
1332
- s3 = peg$parseBlockEnd();
1333
- if (s3 !== peg$FAILED) {
1334
- peg$savedPos = s0;
1335
- s0 = peg$f15(s1, s2, s3);
1336
- } else {
1337
- peg$currPos = s0;
1338
- s0 = peg$FAILED;
1339
- }
1340
- } else {
1341
- peg$currPos = s0;
1342
- s0 = peg$FAILED;
1343
- }
1344
- return s0;
1345
- }
1346
- function peg$parseBranchPart() {
1347
- let s0, s1, s2;
1348
- s0 = peg$currPos;
1349
- s1 = peg$parseBranchTag();
1350
- if (s1 !== peg$FAILED) {
1351
- s2 = peg$parseContent();
1352
- if (s2 !== peg$FAILED) {
1353
- peg$savedPos = s0;
1354
- s0 = peg$f16(s1, s2);
1355
- } else {
1356
- peg$currPos = s0;
1357
- s0 = peg$FAILED;
1358
- }
1359
- } else {
1360
- peg$currPos = s0;
1361
- s0 = peg$FAILED;
1362
- }
1363
- return s0;
1364
- }
1365
- function peg$parseBlockEnd() {
1366
- let s0, s1, s2;
1367
- s0 = peg$parseCloseTag();
1368
- if (s0 === peg$FAILED) {
1369
- s0 = peg$currPos;
1370
- s1 = peg$currPos;
1371
- peg$silentFails++;
1372
- if (input.length > peg$currPos) {
1373
- s2 = input.charAt(peg$currPos);
1374
- peg$currPos++;
1375
- } else {
1376
- s2 = peg$FAILED;
1377
- if (peg$silentFails === 0) peg$fail(peg$e0);
1378
- }
1379
- peg$silentFails--;
1380
- if (s2 === peg$FAILED) s1 = void 0;
1381
- else {
1382
- peg$currPos = s1;
1383
- s1 = peg$FAILED;
1384
- }
1385
- if (s1 !== peg$FAILED) {
1386
- peg$savedPos = s0;
1387
- s1 = peg$f17();
1388
- }
1389
- s0 = s1;
1390
- }
1391
- return s0;
1392
- }
1393
- function peg$parseBranchTag() {
1394
- let s0, s1, s2;
1395
- s0 = peg$currPos;
1396
- s1 = peg$parseMacroTag();
1397
- if (s1 !== peg$FAILED) {
1398
- peg$savedPos = peg$currPos;
1399
- s2 = peg$f18(s1);
1400
- if (s2) s2 = void 0;
1401
- else s2 = peg$FAILED;
1402
- if (s2 !== peg$FAILED) {
1403
- peg$savedPos = s0;
1404
- s0 = peg$f19(s1);
1405
- } else {
1406
- peg$currPos = s0;
1407
- s0 = peg$FAILED;
1408
- }
1409
- } else {
1410
- peg$currPos = s0;
1411
- s0 = peg$FAILED;
1412
- }
1413
- return s0;
1414
- }
1415
- function peg$parseCloseTag() {
1416
- let s0, s1, s2;
1417
- s0 = peg$currPos;
1418
- s1 = peg$parseMacroTag();
1419
- if (s1 !== peg$FAILED) {
1420
- peg$savedPos = peg$currPos;
1421
- s2 = peg$f20(s1);
1144
+ s2 = peg$f8(s1);
1422
1145
  if (s2) s2 = void 0;
1423
1146
  else s2 = peg$FAILED;
1424
1147
  if (s2 !== peg$FAILED) {
1425
1148
  peg$savedPos = s0;
1426
- s0 = peg$f21(s1);
1149
+ s0 = peg$f9(s1);
1427
1150
  } else {
1428
1151
  peg$currPos = s0;
1429
1152
  s0 = peg$FAILED;
@@ -1435,14 +1158,14 @@ function peg$parse(input, options) {
1435
1158
  if (s0 === peg$FAILED) {
1436
1159
  s0 = peg$currPos;
1437
1160
  peg$savedPos = peg$currPos;
1438
- s1 = peg$f22();
1161
+ s1 = peg$f10();
1439
1162
  if (s1) s1 = void 0;
1440
1163
  else s1 = peg$FAILED;
1441
1164
  if (s1 !== peg$FAILED) {
1442
1165
  s2 = peg$parseHtmlClose();
1443
1166
  if (s2 !== peg$FAILED) {
1444
1167
  peg$savedPos = s0;
1445
- s0 = peg$f23(s2);
1168
+ s0 = peg$f11(s2);
1446
1169
  } else {
1447
1170
  peg$currPos = s0;
1448
1171
  s0 = peg$FAILED;
@@ -1454,187 +1177,17 @@ function peg$parse(input, options) {
1454
1177
  }
1455
1178
  return s0;
1456
1179
  }
1457
- function peg$parseRawBody() {
1458
- let s0, s1, s2, s3, s4, s5, s6, s7;
1459
- s0 = peg$currPos;
1460
- s1 = peg$parseHere();
1461
- peg$savedPos = peg$currPos;
1462
- s2 = peg$f24(s1);
1463
- if (s2) s2 = void 0;
1464
- else s2 = peg$FAILED;
1465
- if (s2 !== peg$FAILED) {
1466
- s3 = peg$currPos;
1467
- s4 = peg$f25(s1);
1468
- s5 = peg$currPos;
1469
- s6 = [];
1470
- if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
1471
- else if (input.length > peg$currPos) {
1472
- s7 = input.charAt(peg$currPos);
1473
- peg$currPos++;
1474
- } else {
1475
- s7 = peg$FAILED;
1476
- if (peg$silentFails === 0) peg$fail(peg$e0);
1477
- }
1478
- while (s7 !== peg$FAILED) {
1479
- s6.push(s7);
1480
- if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
1481
- else if (input.length > peg$currPos) {
1482
- s7 = input.charAt(peg$currPos);
1483
- peg$currPos++;
1484
- } else {
1485
- s7 = peg$FAILED;
1486
- if (peg$silentFails === 0) peg$fail(peg$e0);
1487
- }
1488
- }
1489
- if (s6.length < (s4 | 0)) {
1490
- peg$currPos = s5;
1491
- s5 = peg$FAILED;
1492
- } else s5 = s6;
1493
- s4 = s5;
1494
- if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
1495
- else s3 = s4;
1496
- if (s3 !== peg$FAILED) {
1497
- s4 = peg$parseCloseTag();
1498
- if (s4 !== peg$FAILED) {
1499
- peg$savedPos = s0;
1500
- s0 = peg$f26(s1, s3, s4);
1501
- } else {
1502
- peg$currPos = s0;
1503
- s0 = peg$FAILED;
1504
- }
1505
- } else {
1506
- peg$currPos = s0;
1507
- s0 = peg$FAILED;
1508
- }
1509
- } else {
1510
- peg$currPos = s0;
1511
- s0 = peg$FAILED;
1512
- }
1513
- if (s0 === peg$FAILED) {
1514
- s0 = peg$currPos;
1515
- s1 = "";
1516
- peg$savedPos = s0;
1517
- s1 = peg$f27();
1518
- s0 = s1;
1519
- }
1520
- return s0;
1521
- }
1522
- function peg$parseTokens() {
1523
- let s0, s1, s2;
1524
- s0 = peg$currPos;
1525
- s1 = [];
1526
- s2 = peg$parseTokenItem();
1527
- while (s2 !== peg$FAILED) {
1528
- s1.push(s2);
1529
- s2 = peg$parseTokenItem();
1530
- }
1531
- peg$savedPos = s0;
1532
- s1 = peg$f28(s1);
1533
- s0 = s1;
1534
- return s0;
1535
- }
1536
- function peg$parseTokenItem() {
1537
- let s0, s1, s2, s3, s4;
1538
- s0 = peg$parseTextRun();
1539
- if (s0 === peg$FAILED) {
1540
- s0 = peg$parseEscape();
1541
- if (s0 === peg$FAILED) {
1542
- s0 = peg$parseComment();
1543
- if (s0 === peg$FAILED) {
1544
- s0 = peg$parseLinkLexeme();
1545
- if (s0 === peg$FAILED) {
1546
- s0 = peg$parseEmailAutolink();
1547
- if (s0 === peg$FAILED) {
1548
- s0 = peg$currPos;
1549
- peg$savedPos = peg$currPos;
1550
- s1 = peg$f29();
1551
- if (s1) s1 = void 0;
1552
- else s1 = peg$FAILED;
1553
- if (s1 !== peg$FAILED) {
1554
- s2 = peg$parseHtmlOpen();
1555
- if (s2 !== peg$FAILED) {
1556
- peg$savedPos = s0;
1557
- s0 = peg$f30(s2);
1558
- } else {
1559
- peg$currPos = s0;
1560
- s0 = peg$FAILED;
1561
- }
1562
- } else {
1563
- peg$currPos = s0;
1564
- s0 = peg$FAILED;
1565
- }
1566
- if (s0 === peg$FAILED) {
1567
- s0 = peg$currPos;
1568
- peg$savedPos = peg$currPos;
1569
- s1 = peg$f31();
1570
- if (s1) s1 = void 0;
1571
- else s1 = peg$FAILED;
1572
- if (s1 !== peg$FAILED) {
1573
- s2 = peg$parseHtmlClose();
1574
- if (s2 !== peg$FAILED) {
1575
- peg$savedPos = s0;
1576
- s0 = peg$f32(s2);
1577
- } else {
1578
- peg$currPos = s0;
1579
- s0 = peg$FAILED;
1580
- }
1581
- } else {
1582
- peg$currPos = s0;
1583
- s0 = peg$FAILED;
1584
- }
1585
- if (s0 === peg$FAILED) {
1586
- s0 = peg$parseValue();
1587
- if (s0 === peg$FAILED) {
1588
- s0 = peg$currPos;
1589
- s1 = peg$parseMacroTag();
1590
- if (s1 !== peg$FAILED) {
1591
- s2 = peg$currPos;
1592
- peg$savedPos = peg$currPos;
1593
- s3 = peg$f33(s1);
1594
- if (s3) s3 = void 0;
1595
- else s3 = peg$FAILED;
1596
- if (s3 !== peg$FAILED) {
1597
- s4 = peg$parseRawTokens();
1598
- if (s4 !== peg$FAILED) {
1599
- peg$savedPos = s2;
1600
- s2 = peg$f34(s1, s4);
1601
- } else {
1602
- peg$currPos = s2;
1603
- s2 = peg$FAILED;
1604
- }
1605
- } else {
1606
- peg$currPos = s2;
1607
- s2 = peg$FAILED;
1608
- }
1609
- if (s2 === peg$FAILED) s2 = null;
1610
- peg$savedPos = s0;
1611
- s0 = peg$f35(s1, s2);
1612
- } else {
1613
- peg$currPos = s0;
1614
- s0 = peg$FAILED;
1615
- }
1616
- if (s0 === peg$FAILED) s0 = peg$parseLiteral();
1617
- }
1618
- }
1619
- }
1620
- }
1621
- }
1622
- }
1623
- }
1624
- }
1625
- return s0;
1626
- }
1627
1180
  function peg$parseRawTokens() {
1628
1181
  let s0, s1, s2, s3, s4, s5, s6, s7;
1629
1182
  s0 = peg$currPos;
1630
1183
  s1 = peg$parseHere();
1631
1184
  peg$savedPos = peg$currPos;
1632
- s2 = peg$f36(s1);
1185
+ s2 = peg$f12(s1);
1633
1186
  if (s2) s2 = void 0;
1634
1187
  else s2 = peg$FAILED;
1635
1188
  if (s2 !== peg$FAILED) {
1636
1189
  s3 = peg$currPos;
1637
- s4 = peg$f37(s1);
1190
+ s4 = peg$f13(s1);
1638
1191
  s5 = peg$currPos;
1639
1192
  s6 = [];
1640
1193
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -1667,7 +1220,7 @@ function peg$parse(input, options) {
1667
1220
  s4 = peg$parseCloseTag();
1668
1221
  if (s4 !== peg$FAILED) {
1669
1222
  peg$savedPos = s0;
1670
- s0 = peg$f38(s1, s3, s4);
1223
+ s0 = peg$f14(s1, s3, s4);
1671
1224
  } else {
1672
1225
  peg$currPos = s0;
1673
1226
  s0 = peg$FAILED;
@@ -1687,7 +1240,7 @@ function peg$parse(input, options) {
1687
1240
  s0 = peg$currPos;
1688
1241
  s1 = "";
1689
1242
  peg$savedPos = s0;
1690
- s1 = peg$f39();
1243
+ s1 = peg$f15();
1691
1244
  s0 = s1;
1692
1245
  return s0;
1693
1246
  }
@@ -1716,7 +1269,7 @@ function peg$parse(input, options) {
1716
1269
  else s1 = s2;
1717
1270
  if (s1 !== peg$FAILED) {
1718
1271
  peg$savedPos = s0;
1719
- s1 = peg$f40(s1);
1272
+ s1 = peg$f16(s1);
1720
1273
  }
1721
1274
  s0 = s1;
1722
1275
  return s0;
@@ -1856,7 +1409,7 @@ function peg$parse(input, options) {
1856
1409
  else s1 = s2;
1857
1410
  if (s1 !== peg$FAILED) {
1858
1411
  peg$savedPos = s0;
1859
- s1 = peg$f41(s1);
1412
+ s1 = peg$f17(s1);
1860
1413
  }
1861
1414
  s0 = s1;
1862
1415
  return s0;
@@ -1889,7 +1442,7 @@ function peg$parse(input, options) {
1889
1442
  if (s1 !== peg$FAILED) {
1890
1443
  s2 = peg$currPos;
1891
1444
  peg$savedPos = peg$currPos;
1892
- s3 = peg$f42(s1);
1445
+ s3 = peg$f18(s1);
1893
1446
  if (s3) s3 = void 0;
1894
1447
  else s3 = peg$FAILED;
1895
1448
  if (s3 !== peg$FAILED) {
@@ -1901,7 +1454,7 @@ function peg$parse(input, options) {
1901
1454
  }
1902
1455
  if (s4 !== peg$FAILED) {
1903
1456
  peg$savedPos = s2;
1904
- s2 = peg$f43(s1, s4);
1457
+ s2 = peg$f19(s1, s4);
1905
1458
  } else {
1906
1459
  peg$currPos = s2;
1907
1460
  s2 = peg$FAILED;
@@ -1912,7 +1465,7 @@ function peg$parse(input, options) {
1912
1465
  }
1913
1466
  if (s2 === peg$FAILED) s2 = null;
1914
1467
  peg$savedPos = s0;
1915
- s0 = peg$f44(s1, s2);
1468
+ s0 = peg$f20(s1, s2);
1916
1469
  } else {
1917
1470
  peg$currPos = s0;
1918
1471
  s0 = peg$FAILED;
@@ -1960,7 +1513,7 @@ function peg$parse(input, options) {
1960
1513
  }
1961
1514
  if (s2 !== peg$FAILED) {
1962
1515
  peg$savedPos = s0;
1963
- s0 = peg$f45();
1516
+ s0 = peg$f21();
1964
1517
  } else {
1965
1518
  peg$currPos = s0;
1966
1519
  s0 = peg$FAILED;
@@ -1975,7 +1528,7 @@ function peg$parse(input, options) {
1975
1528
  peg$silentFails++;
1976
1529
  s2 = peg$currPos;
1977
1530
  peg$savedPos = peg$currPos;
1978
- s3 = peg$f46();
1531
+ s3 = peg$f22();
1979
1532
  if (s3) s3 = void 0;
1980
1533
  else s3 = peg$FAILED;
1981
1534
  if (s3 !== peg$FAILED) {
@@ -2007,7 +1560,7 @@ function peg$parse(input, options) {
2007
1560
  }
2008
1561
  if (s2 !== peg$FAILED) {
2009
1562
  peg$savedPos = s0;
2010
- s0 = peg$f47();
1563
+ s0 = peg$f23();
2011
1564
  } else {
2012
1565
  peg$currPos = s0;
2013
1566
  s0 = peg$FAILED;
@@ -2027,7 +1580,7 @@ function peg$parse(input, options) {
2027
1580
  }
2028
1581
  if (s1 !== peg$FAILED) {
2029
1582
  peg$savedPos = s0;
2030
- s1 = peg$f48();
1583
+ s1 = peg$f24();
2031
1584
  }
2032
1585
  s0 = s1;
2033
1586
  }
@@ -2035,10 +1588,10 @@ function peg$parse(input, options) {
2035
1588
  return s0;
2036
1589
  }
2037
1590
  function peg$parseLinkLexeme() {
2038
- let s0, s1, s2, s3, s4, s5, s6;
1591
+ let s0, s1, s2, s3, s4, s5, s6, s7;
2039
1592
  s0 = peg$currPos;
2040
1593
  peg$savedPos = peg$currPos;
2041
- s1 = peg$f49();
1594
+ s1 = peg$f25();
2042
1595
  if (s1) s1 = void 0;
2043
1596
  else s1 = peg$FAILED;
2044
1597
  if (s1 !== peg$FAILED) {
@@ -2050,22 +1603,23 @@ function peg$parse(input, options) {
2050
1603
  if (peg$silentFails === 0) peg$fail(peg$e12);
2051
1604
  }
2052
1605
  if (s2 !== peg$FAILED) {
2053
- s3 = peg$parseSelectors();
2054
- if (s3 !== peg$FAILED) {
2055
- s4 = peg$parseHere();
2056
- s5 = peg$currPos;
2057
- s6 = peg$parseLinkText();
2058
- s5 = input.substring(s5, peg$currPos);
1606
+ s3 = peg$parseHere();
1607
+ s4 = peg$parseSelectors();
1608
+ if (s4 !== peg$FAILED) {
1609
+ s5 = peg$parseHere();
1610
+ s6 = peg$currPos;
1611
+ s7 = peg$parseLinkText();
1612
+ s6 = input.substring(s6, peg$currPos);
2059
1613
  if (input.substr(peg$currPos, 2) === peg$c9) {
2060
- s6 = peg$c9;
1614
+ s7 = peg$c9;
2061
1615
  peg$currPos += 2;
2062
1616
  } else {
2063
- s6 = peg$FAILED;
1617
+ s7 = peg$FAILED;
2064
1618
  if (peg$silentFails === 0) peg$fail(peg$e13);
2065
1619
  }
2066
- if (s6 !== peg$FAILED) {
1620
+ if (s7 !== peg$FAILED) {
2067
1621
  peg$savedPos = s0;
2068
- s0 = peg$f50(s3, s4, s5);
1622
+ s0 = peg$f26(s3, s4, s5, s6);
2069
1623
  } else {
2070
1624
  peg$currPos = s0;
2071
1625
  s0 = peg$FAILED;
@@ -2085,7 +1639,7 @@ function peg$parse(input, options) {
2085
1639
  if (s0 === peg$FAILED) {
2086
1640
  s0 = peg$currPos;
2087
1641
  peg$savedPos = peg$currPos;
2088
- s1 = peg$f51();
1642
+ s1 = peg$f27();
2089
1643
  if (s1) s1 = void 0;
2090
1644
  else s1 = peg$FAILED;
2091
1645
  if (s1 !== peg$FAILED) {
@@ -2098,7 +1652,7 @@ function peg$parse(input, options) {
2098
1652
  }
2099
1653
  if (s2 !== peg$FAILED) {
2100
1654
  peg$savedPos = s0;
2101
- s0 = peg$f52();
1655
+ s0 = peg$f28();
2102
1656
  } else {
2103
1657
  peg$currPos = s0;
2104
1658
  s0 = peg$FAILED;
@@ -2222,7 +1776,7 @@ function peg$parse(input, options) {
2222
1776
  }
2223
1777
  if (s2 === peg$FAILED) s2 = null;
2224
1778
  peg$savedPos = s0;
2225
- s0 = peg$f53(s1);
1779
+ s0 = peg$f29(s1);
2226
1780
  } else {
2227
1781
  peg$currPos = s0;
2228
1782
  s0 = peg$FAILED;
@@ -2231,7 +1785,7 @@ function peg$parse(input, options) {
2231
1785
  s0 = peg$currPos;
2232
1786
  s1 = "";
2233
1787
  peg$savedPos = s0;
2234
- s1 = peg$f54();
1788
+ s1 = peg$f30();
2235
1789
  s0 = s1;
2236
1790
  }
2237
1791
  return s0;
@@ -2261,7 +1815,7 @@ function peg$parse(input, options) {
2261
1815
  }
2262
1816
  }
2263
1817
  peg$savedPos = s0;
2264
- s0 = peg$f55(s1, s2);
1818
+ s0 = peg$f31(s1, s2);
2265
1819
  } else {
2266
1820
  peg$currPos = s0;
2267
1821
  s0 = peg$FAILED;
@@ -2287,7 +1841,7 @@ function peg$parse(input, options) {
2287
1841
  }
2288
1842
  s2 = input.substring(s2, peg$currPos);
2289
1843
  peg$savedPos = s0;
2290
- s0 = peg$f56(s1, s2);
1844
+ s0 = peg$f32(s1, s2);
2291
1845
  } else {
2292
1846
  peg$currPos = s0;
2293
1847
  s0 = peg$FAILED;
@@ -2366,7 +1920,7 @@ function peg$parse(input, options) {
2366
1920
  return s0;
2367
1921
  }
2368
1922
  function peg$parseValue() {
2369
- let s0, s1, s2, s3, s4, s5, s6;
1923
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
2370
1924
  s0 = peg$currPos;
2371
1925
  if (input.charCodeAt(peg$currPos) === 123) {
2372
1926
  s1 = peg$c5;
@@ -2376,43 +1930,45 @@ function peg$parse(input, options) {
2376
1930
  if (peg$silentFails === 0) peg$fail(peg$e8);
2377
1931
  }
2378
1932
  if (s1 !== peg$FAILED) {
2379
- s2 = peg$parseSelectors();
2380
- if (s2 !== peg$FAILED) {
2381
- s3 = input.charAt(peg$currPos);
2382
- if (peg$r5.test(s3)) peg$currPos++;
1933
+ s2 = peg$parseHere();
1934
+ s3 = peg$parseSelectors();
1935
+ if (s3 !== peg$FAILED) {
1936
+ s4 = input.charAt(peg$currPos);
1937
+ if (peg$r5.test(s4)) peg$currPos++;
2383
1938
  else {
2384
- s3 = peg$FAILED;
1939
+ s4 = peg$FAILED;
2385
1940
  if (peg$silentFails === 0) peg$fail(peg$e17);
2386
1941
  }
2387
- if (s3 !== peg$FAILED) {
2388
- s4 = peg$currPos;
2389
- s5 = [];
2390
- s6 = input.charAt(peg$currPos);
2391
- if (peg$r6.test(s6)) peg$currPos++;
1942
+ if (s4 !== peg$FAILED) {
1943
+ s5 = peg$parseHere();
1944
+ s6 = peg$currPos;
1945
+ s7 = [];
1946
+ s8 = input.charAt(peg$currPos);
1947
+ if (peg$r6.test(s8)) peg$currPos++;
2392
1948
  else {
2393
- s6 = peg$FAILED;
1949
+ s8 = peg$FAILED;
2394
1950
  if (peg$silentFails === 0) peg$fail(peg$e18);
2395
1951
  }
2396
- while (s6 !== peg$FAILED) {
2397
- s5.push(s6);
2398
- s6 = input.charAt(peg$currPos);
2399
- if (peg$r6.test(s6)) peg$currPos++;
1952
+ while (s8 !== peg$FAILED) {
1953
+ s7.push(s8);
1954
+ s8 = input.charAt(peg$currPos);
1955
+ if (peg$r6.test(s8)) peg$currPos++;
2400
1956
  else {
2401
- s6 = peg$FAILED;
1957
+ s8 = peg$FAILED;
2402
1958
  if (peg$silentFails === 0) peg$fail(peg$e18);
2403
1959
  }
2404
1960
  }
2405
- s4 = input.substring(s4, peg$currPos);
1961
+ s6 = input.substring(s6, peg$currPos);
2406
1962
  if (input.charCodeAt(peg$currPos) === 125) {
2407
- s5 = peg$c11;
1963
+ s7 = peg$c11;
2408
1964
  peg$currPos++;
2409
1965
  } else {
2410
- s5 = peg$FAILED;
1966
+ s7 = peg$FAILED;
2411
1967
  if (peg$silentFails === 0) peg$fail(peg$e19);
2412
1968
  }
2413
- if (s5 !== peg$FAILED) {
1969
+ if (s7 !== peg$FAILED) {
2414
1970
  peg$savedPos = s0;
2415
- s0 = peg$f57(s2, s3, s4);
1971
+ s0 = peg$f33(s2, s3, s4, s5, s6);
2416
1972
  } else {
2417
1973
  peg$currPos = s0;
2418
1974
  s0 = peg$FAILED;
@@ -2439,34 +1995,36 @@ function peg$parse(input, options) {
2439
1995
  if (peg$silentFails === 0) peg$fail(peg$e8);
2440
1996
  }
2441
1997
  if (s1 !== peg$FAILED) {
2442
- s2 = peg$parseSelectors();
2443
- if (s2 !== peg$FAILED) {
2444
- s3 = peg$currPos;
1998
+ s2 = peg$parseHere();
1999
+ s3 = peg$parseSelectors();
2000
+ if (s3 !== peg$FAILED) {
2001
+ s4 = peg$parseHere();
2002
+ s5 = peg$currPos;
2445
2003
  peg$silentFails++;
2446
- s4 = input.charAt(peg$currPos);
2447
- if (peg$r7.test(s4)) peg$currPos++;
2004
+ s6 = input.charAt(peg$currPos);
2005
+ if (peg$r7.test(s6)) peg$currPos++;
2448
2006
  else {
2449
- s4 = peg$FAILED;
2007
+ s6 = peg$FAILED;
2450
2008
  if (peg$silentFails === 0) peg$fail(peg$e20);
2451
2009
  }
2452
2010
  peg$silentFails--;
2453
- if (s4 !== peg$FAILED) {
2454
- peg$currPos = s3;
2455
- s3 = void 0;
2456
- } else s3 = peg$FAILED;
2457
- if (s3 !== peg$FAILED) {
2458
- s4 = peg$parseCodeToBrace();
2459
- if (s4 !== peg$FAILED) {
2011
+ if (s6 !== peg$FAILED) {
2012
+ peg$currPos = s5;
2013
+ s5 = void 0;
2014
+ } else s5 = peg$FAILED;
2015
+ if (s5 !== peg$FAILED) {
2016
+ s6 = peg$parseCodeToBrace();
2017
+ if (s6 !== peg$FAILED) {
2460
2018
  if (input.charCodeAt(peg$currPos) === 125) {
2461
- s5 = peg$c11;
2019
+ s7 = peg$c11;
2462
2020
  peg$currPos++;
2463
2021
  } else {
2464
- s5 = peg$FAILED;
2022
+ s7 = peg$FAILED;
2465
2023
  if (peg$silentFails === 0) peg$fail(peg$e19);
2466
2024
  }
2467
- if (s5 !== peg$FAILED) {
2025
+ if (s7 !== peg$FAILED) {
2468
2026
  peg$savedPos = s0;
2469
- s0 = peg$f58(s2, s4);
2027
+ s0 = peg$f34(s2, s3, s4, s6);
2470
2028
  } else {
2471
2029
  peg$currPos = s0;
2472
2030
  s0 = peg$FAILED;
@@ -2514,7 +2072,7 @@ function peg$parse(input, options) {
2514
2072
  } else s3 = peg$FAILED;
2515
2073
  if (s3 !== peg$FAILED) {
2516
2074
  peg$savedPos = s0;
2517
- s0 = peg$f59();
2075
+ s0 = peg$f35();
2518
2076
  } else {
2519
2077
  peg$currPos = s0;
2520
2078
  s0 = peg$FAILED;
@@ -2536,12 +2094,12 @@ function peg$parse(input, options) {
2536
2094
  s0 = peg$currPos;
2537
2095
  s1 = peg$parseHere();
2538
2096
  peg$savedPos = peg$currPos;
2539
- s2 = peg$f60(s1);
2097
+ s2 = peg$f36(s1);
2540
2098
  if (s2) s2 = void 0;
2541
2099
  else s2 = peg$FAILED;
2542
2100
  if (s2 !== peg$FAILED) {
2543
2101
  s3 = peg$currPos;
2544
- s4 = peg$f61(s1);
2102
+ s4 = peg$f37(s1);
2545
2103
  s5 = peg$currPos;
2546
2104
  s6 = [];
2547
2105
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -2572,7 +2130,7 @@ function peg$parse(input, options) {
2572
2130
  else s3 = s4;
2573
2131
  if (s3 !== peg$FAILED) {
2574
2132
  peg$savedPos = s0;
2575
- s0 = peg$f62(s1, s3);
2133
+ s0 = peg$f38(s1, s3);
2576
2134
  } else {
2577
2135
  peg$currPos = s0;
2578
2136
  s0 = peg$FAILED;
@@ -2584,7 +2142,7 @@ function peg$parse(input, options) {
2584
2142
  return s0;
2585
2143
  }
2586
2144
  function peg$parseMacroTag() {
2587
- let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
2145
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
2588
2146
  s0 = peg$currPos;
2589
2147
  if (input.charCodeAt(peg$currPos) === 123) {
2590
2148
  s1 = peg$c5;
@@ -2594,82 +2152,83 @@ function peg$parse(input, options) {
2594
2152
  if (peg$silentFails === 0) peg$fail(peg$e8);
2595
2153
  }
2596
2154
  if (s1 !== peg$FAILED) {
2597
- s2 = peg$parseSelectors();
2598
- if (s2 !== peg$FAILED) {
2599
- s3 = peg$parseHere();
2155
+ s2 = peg$parseHere();
2156
+ s3 = peg$parseSelectors();
2157
+ if (s3 !== peg$FAILED) {
2158
+ s4 = peg$parseHere();
2600
2159
  if (input.charCodeAt(peg$currPos) === 47) {
2601
- s4 = peg$c12;
2160
+ s5 = peg$c12;
2602
2161
  peg$currPos++;
2603
2162
  } else {
2604
- s4 = peg$FAILED;
2163
+ s5 = peg$FAILED;
2605
2164
  if (peg$silentFails === 0) peg$fail(peg$e21);
2606
2165
  }
2607
- if (s4 === peg$FAILED) s4 = null;
2608
- s5 = peg$parseMacroName();
2609
- if (s5 !== peg$FAILED) {
2610
- s6 = peg$parseHere();
2611
- s7 = peg$currPos;
2166
+ if (s5 === peg$FAILED) s5 = null;
2167
+ s6 = peg$parseMacroName();
2168
+ if (s6 !== peg$FAILED) {
2169
+ s7 = peg$parseHere();
2170
+ s8 = peg$currPos;
2612
2171
  peg$savedPos = peg$currPos;
2613
- s8 = peg$f63(s2, s3, s4, s5, s6);
2614
- if (s8) s8 = void 0;
2615
- else s8 = peg$FAILED;
2616
- if (s8 !== peg$FAILED) {
2617
- s9 = peg$currPos;
2618
- s10 = peg$f64(s2, s3, s4, s5, s6);
2619
- s11 = peg$currPos;
2620
- s12 = [];
2621
- if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
2172
+ s9 = peg$f39(s2, s3, s4, s5, s6, s7);
2173
+ if (s9) s9 = void 0;
2174
+ else s9 = peg$FAILED;
2175
+ if (s9 !== peg$FAILED) {
2176
+ s10 = peg$currPos;
2177
+ s11 = peg$f40(s2, s3, s4, s5, s6, s7);
2178
+ s12 = peg$currPos;
2179
+ s13 = [];
2180
+ if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
2622
2181
  else if (input.length > peg$currPos) {
2623
- s13 = input.charAt(peg$currPos);
2182
+ s14 = input.charAt(peg$currPos);
2624
2183
  peg$currPos++;
2625
2184
  } else {
2626
- s13 = peg$FAILED;
2185
+ s14 = peg$FAILED;
2627
2186
  if (peg$silentFails === 0) peg$fail(peg$e0);
2628
2187
  }
2629
- while (s13 !== peg$FAILED) {
2630
- s12.push(s13);
2631
- if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
2188
+ while (s14 !== peg$FAILED) {
2189
+ s13.push(s14);
2190
+ if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
2632
2191
  else if (input.length > peg$currPos) {
2633
- s13 = input.charAt(peg$currPos);
2192
+ s14 = input.charAt(peg$currPos);
2634
2193
  peg$currPos++;
2635
2194
  } else {
2636
- s13 = peg$FAILED;
2195
+ s14 = peg$FAILED;
2637
2196
  if (peg$silentFails === 0) peg$fail(peg$e0);
2638
2197
  }
2639
2198
  }
2640
- if (s12.length < (s10 | 0)) {
2641
- peg$currPos = s11;
2642
- s11 = peg$FAILED;
2643
- } else s11 = s12;
2644
- s10 = s11;
2645
- if (s10 !== peg$FAILED) s9 = input.substring(s9, peg$currPos);
2646
- else s9 = s10;
2647
- if (s9 !== peg$FAILED) {
2199
+ if (s13.length < (s11 | 0)) {
2200
+ peg$currPos = s12;
2201
+ s12 = peg$FAILED;
2202
+ } else s12 = s13;
2203
+ s11 = s12;
2204
+ if (s11 !== peg$FAILED) s10 = input.substring(s10, peg$currPos);
2205
+ else s10 = s11;
2206
+ if (s10 !== peg$FAILED) {
2648
2207
  if (input.charCodeAt(peg$currPos) === 125) {
2649
- s10 = peg$c11;
2208
+ s11 = peg$c11;
2650
2209
  peg$currPos++;
2651
2210
  } else {
2652
- s10 = peg$FAILED;
2211
+ s11 = peg$FAILED;
2653
2212
  if (peg$silentFails === 0) peg$fail(peg$e19);
2654
2213
  }
2655
- if (s10 !== peg$FAILED) {
2656
- peg$savedPos = s7;
2657
- s7 = peg$f65(s2, s3, s4, s5, s6, s9);
2214
+ if (s11 !== peg$FAILED) {
2215
+ peg$savedPos = s8;
2216
+ s8 = peg$f41(s2, s3, s4, s5, s6, s7, s10);
2658
2217
  } else {
2659
- peg$currPos = s7;
2660
- s7 = peg$FAILED;
2218
+ peg$currPos = s8;
2219
+ s8 = peg$FAILED;
2661
2220
  }
2662
2221
  } else {
2663
- peg$currPos = s7;
2664
- s7 = peg$FAILED;
2222
+ peg$currPos = s8;
2223
+ s8 = peg$FAILED;
2665
2224
  }
2666
2225
  } else {
2667
- peg$currPos = s7;
2668
- s7 = peg$FAILED;
2226
+ peg$currPos = s8;
2227
+ s8 = peg$FAILED;
2669
2228
  }
2670
- if (s7 === peg$FAILED) s7 = null;
2229
+ if (s8 === peg$FAILED) s8 = null;
2671
2230
  peg$savedPos = s0;
2672
- s0 = peg$f66(s2, s3, s4, s5, s6, s7);
2231
+ s0 = peg$f42(s2, s3, s4, s5, s6, s7, s8);
2673
2232
  } else {
2674
2233
  peg$currPos = s0;
2675
2234
  s0 = peg$FAILED;
@@ -2703,7 +2262,7 @@ function peg$parse(input, options) {
2703
2262
  }
2704
2263
  if (s3 !== peg$FAILED) {
2705
2264
  peg$savedPos = s0;
2706
- s0 = peg$f67(s2);
2265
+ s0 = peg$f43(s2);
2707
2266
  } else {
2708
2267
  peg$currPos = s0;
2709
2268
  s0 = peg$FAILED;
@@ -2845,51 +2404,20 @@ function peg$parse(input, options) {
2845
2404
  peg$currPos = s2;
2846
2405
  s2 = peg$FAILED;
2847
2406
  }
2848
- } else {
2849
- peg$currPos = s2;
2850
- s2 = peg$FAILED;
2851
- }
2852
- if (s2 !== peg$FAILED) s1 = input.substring(s1, peg$currPos);
2853
- else s1 = s2;
2854
- if (s1 !== peg$FAILED) {
2855
- peg$savedPos = peg$currPos;
2856
- s2 = peg$f68(s1);
2857
- if (s2) s2 = void 0;
2858
- else s2 = peg$FAILED;
2859
- if (s2 !== peg$FAILED) {
2860
- peg$savedPos = s0;
2861
- s0 = peg$f69(s1);
2862
- } else {
2863
- peg$currPos = s0;
2864
- s0 = peg$FAILED;
2865
- }
2866
- } else {
2867
- peg$currPos = s0;
2868
- s0 = peg$FAILED;
2407
+ } else {
2408
+ peg$currPos = s2;
2409
+ s2 = peg$FAILED;
2869
2410
  }
2870
- return s0;
2871
- }
2872
- function peg$parseVoidCloser() {
2873
- let s0, s1, s2, s3;
2874
- s0 = peg$currPos;
2875
- peg$savedPos = peg$currPos;
2876
- s1 = peg$f70();
2877
- if (s1) s1 = void 0;
2878
- else s1 = peg$FAILED;
2411
+ if (s2 !== peg$FAILED) s1 = input.substring(s1, peg$currPos);
2412
+ else s1 = s2;
2879
2413
  if (s1 !== peg$FAILED) {
2880
- s2 = peg$parseHtmlClose();
2414
+ peg$savedPos = peg$currPos;
2415
+ s2 = peg$f44(s1);
2416
+ if (s2) s2 = void 0;
2417
+ else s2 = peg$FAILED;
2881
2418
  if (s2 !== peg$FAILED) {
2882
- peg$savedPos = peg$currPos;
2883
- s3 = peg$f71(s2);
2884
- if (s3) s3 = void 0;
2885
- else s3 = peg$FAILED;
2886
- if (s3 !== peg$FAILED) {
2887
- peg$savedPos = s0;
2888
- s0 = peg$f72(s2);
2889
- } else {
2890
- peg$currPos = s0;
2891
- s0 = peg$FAILED;
2892
- }
2419
+ peg$savedPos = s0;
2420
+ s0 = peg$f45(s1);
2893
2421
  } else {
2894
2422
  peg$currPos = s0;
2895
2423
  s0 = peg$FAILED;
@@ -2901,7 +2429,7 @@ function peg$parse(input, options) {
2901
2429
  return s0;
2902
2430
  }
2903
2431
  function peg$parseHtmlOpen() {
2904
- let s0, s1, s2, s3, s4, s5, s6;
2432
+ let s0, s1, s2, s3, s4, s5, s6, s7;
2905
2433
  s0 = peg$currPos;
2906
2434
  if (input.charCodeAt(peg$currPos) === 60) {
2907
2435
  s1 = peg$c6;
@@ -2911,33 +2439,34 @@ function peg$parse(input, options) {
2911
2439
  if (peg$silentFails === 0) peg$fail(peg$e10);
2912
2440
  }
2913
2441
  if (s1 !== peg$FAILED) {
2914
- s2 = peg$parseTagName();
2915
- if (s2 !== peg$FAILED) {
2916
- s3 = [];
2917
- s4 = peg$parseAttribute();
2918
- while (s4 !== peg$FAILED) {
2919
- s3.push(s4);
2920
- s4 = peg$parseAttribute();
2442
+ s2 = peg$parseHere();
2443
+ s3 = peg$parseTagName();
2444
+ if (s3 !== peg$FAILED) {
2445
+ s4 = [];
2446
+ s5 = peg$parseAttribute();
2447
+ while (s5 !== peg$FAILED) {
2448
+ s4.push(s5);
2449
+ s5 = peg$parseAttribute();
2921
2450
  }
2922
- s4 = peg$parse_();
2451
+ s5 = peg$parse_();
2923
2452
  if (input.charCodeAt(peg$currPos) === 47) {
2924
- s5 = peg$c12;
2453
+ s6 = peg$c12;
2925
2454
  peg$currPos++;
2926
2455
  } else {
2927
- s5 = peg$FAILED;
2456
+ s6 = peg$FAILED;
2928
2457
  if (peg$silentFails === 0) peg$fail(peg$e21);
2929
2458
  }
2930
- if (s5 === peg$FAILED) s5 = null;
2459
+ if (s6 === peg$FAILED) s6 = null;
2931
2460
  if (input.charCodeAt(peg$currPos) === 62) {
2932
- s6 = peg$c1;
2461
+ s7 = peg$c1;
2933
2462
  peg$currPos++;
2934
2463
  } else {
2935
- s6 = peg$FAILED;
2464
+ s7 = peg$FAILED;
2936
2465
  if (peg$silentFails === 0) peg$fail(peg$e3);
2937
2466
  }
2938
- if (s6 !== peg$FAILED) {
2467
+ if (s7 !== peg$FAILED) {
2939
2468
  peg$savedPos = s0;
2940
- s0 = peg$f73(s2, s3, s5);
2469
+ s0 = peg$f46(s2, s3, s4, s6);
2941
2470
  } else {
2942
2471
  peg$currPos = s0;
2943
2472
  s0 = peg$FAILED;
@@ -3002,7 +2531,7 @@ function peg$parse(input, options) {
3002
2531
  s5 = peg$parse_();
3003
2532
  s6 = peg$parseHere();
3004
2533
  peg$savedPos = s0;
3005
- s0 = peg$f74(s2, s6);
2534
+ s0 = peg$f47(s2, s6);
3006
2535
  } else {
3007
2536
  peg$currPos = s0;
3008
2537
  s0 = peg$FAILED;
@@ -3019,7 +2548,7 @@ function peg$parse(input, options) {
3019
2548
  return s0;
3020
2549
  }
3021
2550
  function peg$parseHtmlClose() {
3022
- let s0, s1, s2, s4;
2551
+ let s0, s1, s2, s3, s5;
3023
2552
  s0 = peg$currPos;
3024
2553
  if (input.substr(peg$currPos, 2) === peg$c14) {
3025
2554
  s1 = peg$c14;
@@ -3029,19 +2558,20 @@ function peg$parse(input, options) {
3029
2558
  if (peg$silentFails === 0) peg$fail(peg$e28);
3030
2559
  }
3031
2560
  if (s1 !== peg$FAILED) {
3032
- s2 = peg$parseTagName();
3033
- if (s2 !== peg$FAILED) {
2561
+ s2 = peg$parseHere();
2562
+ s3 = peg$parseTagName();
2563
+ if (s3 !== peg$FAILED) {
3034
2564
  peg$parse_();
3035
2565
  if (input.charCodeAt(peg$currPos) === 62) {
3036
- s4 = peg$c1;
2566
+ s5 = peg$c1;
3037
2567
  peg$currPos++;
3038
2568
  } else {
3039
- s4 = peg$FAILED;
2569
+ s5 = peg$FAILED;
3040
2570
  if (peg$silentFails === 0) peg$fail(peg$e3);
3041
2571
  }
3042
- if (s4 !== peg$FAILED) {
2572
+ if (s5 !== peg$FAILED) {
3043
2573
  peg$savedPos = s0;
3044
- s0 = peg$f75(s2);
2574
+ s0 = peg$f48(s2, s3);
3045
2575
  } else {
3046
2576
  peg$currPos = s0;
3047
2577
  s0 = peg$FAILED;
@@ -3094,117 +2624,118 @@ function peg$parse(input, options) {
3094
2624
  return s0;
3095
2625
  }
3096
2626
  function peg$parseAttribute() {
3097
- let s0, s2, s3, s4, s5, s6, s8;
2627
+ let s0, s2, s3, s4, s5, s6, s7, s9;
3098
2628
  s0 = peg$currPos;
3099
2629
  peg$parse_();
3100
- s2 = peg$currPos;
3101
- s3 = [];
3102
- s4 = peg$currPos;
2630
+ s2 = peg$parseHere();
2631
+ s3 = peg$currPos;
2632
+ s4 = [];
3103
2633
  s5 = peg$currPos;
2634
+ s6 = peg$currPos;
3104
2635
  peg$silentFails++;
3105
- s6 = input.charAt(peg$currPos);
3106
- if (peg$r14.test(s6)) peg$currPos++;
2636
+ s7 = input.charAt(peg$currPos);
2637
+ if (peg$r14.test(s7)) peg$currPos++;
3107
2638
  else {
3108
- s6 = peg$FAILED;
2639
+ s7 = peg$FAILED;
3109
2640
  if (peg$silentFails === 0) peg$fail(peg$e30);
3110
2641
  }
3111
2642
  peg$silentFails--;
3112
- if (s6 === peg$FAILED) s5 = void 0;
2643
+ if (s7 === peg$FAILED) s6 = void 0;
3113
2644
  else {
3114
- peg$currPos = s5;
3115
- s5 = peg$FAILED;
2645
+ peg$currPos = s6;
2646
+ s6 = peg$FAILED;
3116
2647
  }
3117
- if (s5 !== peg$FAILED) {
2648
+ if (s6 !== peg$FAILED) {
3118
2649
  if (input.length > peg$currPos) {
3119
- s6 = input.charAt(peg$currPos);
2650
+ s7 = input.charAt(peg$currPos);
3120
2651
  peg$currPos++;
3121
2652
  } else {
3122
- s6 = peg$FAILED;
2653
+ s7 = peg$FAILED;
3123
2654
  if (peg$silentFails === 0) peg$fail(peg$e0);
3124
2655
  }
3125
- if (s6 !== peg$FAILED) {
3126
- s5 = [s5, s6];
3127
- s4 = s5;
2656
+ if (s7 !== peg$FAILED) {
2657
+ s6 = [s6, s7];
2658
+ s5 = s6;
3128
2659
  } else {
3129
- peg$currPos = s4;
3130
- s4 = peg$FAILED;
2660
+ peg$currPos = s5;
2661
+ s5 = peg$FAILED;
3131
2662
  }
3132
2663
  } else {
3133
- peg$currPos = s4;
3134
- s4 = peg$FAILED;
2664
+ peg$currPos = s5;
2665
+ s5 = peg$FAILED;
3135
2666
  }
3136
- if (s4 !== peg$FAILED) while (s4 !== peg$FAILED) {
3137
- s3.push(s4);
3138
- s4 = peg$currPos;
2667
+ if (s5 !== peg$FAILED) while (s5 !== peg$FAILED) {
2668
+ s4.push(s5);
3139
2669
  s5 = peg$currPos;
2670
+ s6 = peg$currPos;
3140
2671
  peg$silentFails++;
3141
- s6 = input.charAt(peg$currPos);
3142
- if (peg$r14.test(s6)) peg$currPos++;
2672
+ s7 = input.charAt(peg$currPos);
2673
+ if (peg$r14.test(s7)) peg$currPos++;
3143
2674
  else {
3144
- s6 = peg$FAILED;
2675
+ s7 = peg$FAILED;
3145
2676
  if (peg$silentFails === 0) peg$fail(peg$e30);
3146
2677
  }
3147
2678
  peg$silentFails--;
3148
- if (s6 === peg$FAILED) s5 = void 0;
2679
+ if (s7 === peg$FAILED) s6 = void 0;
3149
2680
  else {
3150
- peg$currPos = s5;
3151
- s5 = peg$FAILED;
2681
+ peg$currPos = s6;
2682
+ s6 = peg$FAILED;
3152
2683
  }
3153
- if (s5 !== peg$FAILED) {
2684
+ if (s6 !== peg$FAILED) {
3154
2685
  if (input.length > peg$currPos) {
3155
- s6 = input.charAt(peg$currPos);
2686
+ s7 = input.charAt(peg$currPos);
3156
2687
  peg$currPos++;
3157
2688
  } else {
3158
- s6 = peg$FAILED;
2689
+ s7 = peg$FAILED;
3159
2690
  if (peg$silentFails === 0) peg$fail(peg$e0);
3160
2691
  }
3161
- if (s6 !== peg$FAILED) {
3162
- s5 = [s5, s6];
3163
- s4 = s5;
2692
+ if (s7 !== peg$FAILED) {
2693
+ s6 = [s6, s7];
2694
+ s5 = s6;
3164
2695
  } else {
3165
- peg$currPos = s4;
3166
- s4 = peg$FAILED;
2696
+ peg$currPos = s5;
2697
+ s5 = peg$FAILED;
3167
2698
  }
3168
2699
  } else {
3169
- peg$currPos = s4;
3170
- s4 = peg$FAILED;
2700
+ peg$currPos = s5;
2701
+ s5 = peg$FAILED;
3171
2702
  }
3172
2703
  }
3173
- else s3 = peg$FAILED;
3174
- if (s3 !== peg$FAILED) s2 = input.substring(s2, peg$currPos);
3175
- else s2 = s3;
3176
- if (s2 !== peg$FAILED) {
2704
+ else s4 = peg$FAILED;
2705
+ if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
2706
+ else s3 = s4;
2707
+ if (s3 !== peg$FAILED) {
3177
2708
  peg$savedPos = peg$currPos;
3178
- s3 = peg$f76(s2);
3179
- if (s3) s3 = void 0;
3180
- else s3 = peg$FAILED;
3181
- if (s3 !== peg$FAILED) {
3182
- s4 = peg$currPos;
3183
- s5 = peg$parse_();
2709
+ s4 = peg$f49(s2, s3);
2710
+ if (s4) s4 = void 0;
2711
+ else s4 = peg$FAILED;
2712
+ if (s4 !== peg$FAILED) {
2713
+ s5 = peg$currPos;
2714
+ s6 = peg$parse_();
3184
2715
  if (input.charCodeAt(peg$currPos) === 61) {
3185
- s6 = peg$c15;
2716
+ s7 = peg$c15;
3186
2717
  peg$currPos++;
3187
2718
  } else {
3188
- s6 = peg$FAILED;
2719
+ s7 = peg$FAILED;
3189
2720
  if (peg$silentFails === 0) peg$fail(peg$e31);
3190
2721
  }
3191
- if (s6 !== peg$FAILED) {
2722
+ if (s7 !== peg$FAILED) {
3192
2723
  peg$parse_();
3193
- s8 = peg$parseAttrValue();
3194
- if (s8 !== peg$FAILED) {
3195
- peg$savedPos = s4;
3196
- s4 = peg$f77(s2, s8);
2724
+ s9 = peg$parseAttrValue();
2725
+ if (s9 !== peg$FAILED) {
2726
+ peg$savedPos = s5;
2727
+ s5 = peg$f50(s2, s3, s9);
3197
2728
  } else {
3198
- peg$currPos = s4;
3199
- s4 = peg$FAILED;
2729
+ peg$currPos = s5;
2730
+ s5 = peg$FAILED;
3200
2731
  }
3201
2732
  } else {
3202
- peg$currPos = s4;
3203
- s4 = peg$FAILED;
2733
+ peg$currPos = s5;
2734
+ s5 = peg$FAILED;
3204
2735
  }
3205
- if (s4 === peg$FAILED) s4 = null;
2736
+ if (s5 === peg$FAILED) s5 = null;
3206
2737
  peg$savedPos = s0;
3207
- s0 = peg$f78(s2, s4);
2738
+ s0 = peg$f51(s2, s3, s5);
3208
2739
  } else {
3209
2740
  peg$currPos = s0;
3210
2741
  s0 = peg$FAILED;
@@ -3216,7 +2747,7 @@ function peg$parse(input, options) {
3216
2747
  return s0;
3217
2748
  }
3218
2749
  function peg$parseAttrValue() {
3219
- let s0, s1, s2, s3, s4;
2750
+ let s0, s1, s2, s3, s4, s5;
3220
2751
  s0 = peg$currPos;
3221
2752
  if (input.charCodeAt(peg$currPos) === 34) {
3222
2753
  s1 = peg$c16;
@@ -3226,40 +2757,42 @@ function peg$parse(input, options) {
3226
2757
  if (peg$silentFails === 0) peg$fail(peg$e32);
3227
2758
  }
3228
2759
  if (s1 !== peg$FAILED) {
3229
- s2 = peg$currPos;
3230
- s3 = [];
3231
- s4 = peg$parseValuePart();
3232
- if (s4 === peg$FAILED) {
3233
- s4 = input.charAt(peg$currPos);
3234
- if (peg$r15.test(s4)) peg$currPos++;
2760
+ s2 = peg$parseHere();
2761
+ s3 = peg$currPos;
2762
+ s4 = [];
2763
+ s5 = peg$parseValuePart();
2764
+ if (s5 === peg$FAILED) {
2765
+ s5 = input.charAt(peg$currPos);
2766
+ if (peg$r15.test(s5)) peg$currPos++;
3235
2767
  else {
3236
- s4 = peg$FAILED;
2768
+ s5 = peg$FAILED;
3237
2769
  if (peg$silentFails === 0) peg$fail(peg$e33);
3238
2770
  }
3239
2771
  }
3240
- while (s4 !== peg$FAILED) {
3241
- s3.push(s4);
3242
- s4 = peg$parseValuePart();
3243
- if (s4 === peg$FAILED) {
3244
- s4 = input.charAt(peg$currPos);
3245
- if (peg$r15.test(s4)) peg$currPos++;
2772
+ while (s5 !== peg$FAILED) {
2773
+ s4.push(s5);
2774
+ s5 = peg$parseValuePart();
2775
+ if (s5 === peg$FAILED) {
2776
+ s5 = input.charAt(peg$currPos);
2777
+ if (peg$r15.test(s5)) peg$currPos++;
3246
2778
  else {
3247
- s4 = peg$FAILED;
2779
+ s5 = peg$FAILED;
3248
2780
  if (peg$silentFails === 0) peg$fail(peg$e33);
3249
2781
  }
3250
2782
  }
3251
2783
  }
3252
- s2 = input.substring(s2, peg$currPos);
2784
+ s3 = input.substring(s3, peg$currPos);
2785
+ s4 = peg$parseHere();
3253
2786
  if (input.charCodeAt(peg$currPos) === 34) {
3254
- s3 = peg$c16;
2787
+ s5 = peg$c16;
3255
2788
  peg$currPos++;
3256
2789
  } else {
3257
- s3 = peg$FAILED;
2790
+ s5 = peg$FAILED;
3258
2791
  if (peg$silentFails === 0) peg$fail(peg$e32);
3259
2792
  }
3260
- if (s3 !== peg$FAILED) {
2793
+ if (s5 !== peg$FAILED) {
3261
2794
  peg$savedPos = s0;
3262
- s0 = peg$f79(s2);
2795
+ s0 = peg$f52(s2, s3, s4);
3263
2796
  } else {
3264
2797
  peg$currPos = s0;
3265
2798
  s0 = peg$FAILED;
@@ -3278,40 +2811,42 @@ function peg$parse(input, options) {
3278
2811
  if (peg$silentFails === 0) peg$fail(peg$e34);
3279
2812
  }
3280
2813
  if (s1 !== peg$FAILED) {
3281
- s2 = peg$currPos;
3282
- s3 = [];
3283
- s4 = peg$parseValuePart();
3284
- if (s4 === peg$FAILED) {
3285
- s4 = input.charAt(peg$currPos);
3286
- if (peg$r16.test(s4)) peg$currPos++;
2814
+ s2 = peg$parseHere();
2815
+ s3 = peg$currPos;
2816
+ s4 = [];
2817
+ s5 = peg$parseValuePart();
2818
+ if (s5 === peg$FAILED) {
2819
+ s5 = input.charAt(peg$currPos);
2820
+ if (peg$r16.test(s5)) peg$currPos++;
3287
2821
  else {
3288
- s4 = peg$FAILED;
2822
+ s5 = peg$FAILED;
3289
2823
  if (peg$silentFails === 0) peg$fail(peg$e35);
3290
2824
  }
3291
2825
  }
3292
- while (s4 !== peg$FAILED) {
3293
- s3.push(s4);
3294
- s4 = peg$parseValuePart();
3295
- if (s4 === peg$FAILED) {
3296
- s4 = input.charAt(peg$currPos);
3297
- if (peg$r16.test(s4)) peg$currPos++;
2826
+ while (s5 !== peg$FAILED) {
2827
+ s4.push(s5);
2828
+ s5 = peg$parseValuePart();
2829
+ if (s5 === peg$FAILED) {
2830
+ s5 = input.charAt(peg$currPos);
2831
+ if (peg$r16.test(s5)) peg$currPos++;
3298
2832
  else {
3299
- s4 = peg$FAILED;
2833
+ s5 = peg$FAILED;
3300
2834
  if (peg$silentFails === 0) peg$fail(peg$e35);
3301
2835
  }
3302
2836
  }
3303
2837
  }
3304
- s2 = input.substring(s2, peg$currPos);
2838
+ s3 = input.substring(s3, peg$currPos);
2839
+ s4 = peg$parseHere();
3305
2840
  if (input.charCodeAt(peg$currPos) === 39) {
3306
- s3 = peg$c17;
2841
+ s5 = peg$c17;
3307
2842
  peg$currPos++;
3308
2843
  } else {
3309
- s3 = peg$FAILED;
2844
+ s5 = peg$FAILED;
3310
2845
  if (peg$silentFails === 0) peg$fail(peg$e34);
3311
2846
  }
3312
- if (s3 !== peg$FAILED) {
2847
+ if (s5 !== peg$FAILED) {
3313
2848
  peg$savedPos = s0;
3314
- s0 = peg$f80(s2);
2849
+ s0 = peg$f53(s2, s3, s4);
3315
2850
  } else {
3316
2851
  peg$currPos = s0;
3317
2852
  s0 = peg$FAILED;
@@ -3330,28 +2865,33 @@ function peg$parse(input, options) {
3330
2865
  }
3331
2866
  if (s1 !== peg$FAILED) {
3332
2867
  peg$savedPos = s0;
3333
- s1 = peg$f81(s1);
2868
+ s1 = peg$f54(s1);
3334
2869
  }
3335
2870
  s0 = s1;
3336
2871
  if (s0 === peg$FAILED) {
3337
2872
  s0 = peg$currPos;
3338
- s1 = [];
3339
- s2 = input.charAt(peg$currPos);
3340
- if (peg$r18.test(s2)) peg$currPos++;
2873
+ s1 = peg$parseHere();
2874
+ s2 = peg$currPos;
2875
+ s3 = [];
2876
+ s4 = input.charAt(peg$currPos);
2877
+ if (peg$r18.test(s4)) peg$currPos++;
3341
2878
  else {
3342
- s2 = peg$FAILED;
2879
+ s4 = peg$FAILED;
3343
2880
  if (peg$silentFails === 0) peg$fail(peg$e37);
3344
2881
  }
3345
- while (s2 !== peg$FAILED) {
3346
- s1.push(s2);
3347
- s2 = input.charAt(peg$currPos);
3348
- if (peg$r18.test(s2)) peg$currPos++;
2882
+ while (s4 !== peg$FAILED) {
2883
+ s3.push(s4);
2884
+ s4 = input.charAt(peg$currPos);
2885
+ if (peg$r18.test(s4)) peg$currPos++;
3349
2886
  else {
3350
- s2 = peg$FAILED;
2887
+ s4 = peg$FAILED;
3351
2888
  if (peg$silentFails === 0) peg$fail(peg$e37);
3352
2889
  }
3353
2890
  }
3354
- s0 = input.substring(s0, peg$currPos);
2891
+ s2 = input.substring(s2, peg$currPos);
2892
+ s3 = peg$parseHere();
2893
+ peg$savedPos = s0;
2894
+ s0 = peg$f55(s1, s2, s3);
3355
2895
  }
3356
2896
  }
3357
2897
  }
@@ -3361,7 +2901,7 @@ function peg$parse(input, options) {
3361
2901
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
3362
2902
  s0 = peg$currPos;
3363
2903
  peg$savedPos = peg$currPos;
3364
- s1 = peg$f82();
2904
+ s1 = peg$f56();
3365
2905
  if (s1) s1 = void 0;
3366
2906
  else s1 = peg$FAILED;
3367
2907
  if (s1 !== peg$FAILED) {
@@ -3390,7 +2930,7 @@ function peg$parse(input, options) {
3390
2930
  if (s2 !== peg$FAILED) {
3391
2931
  s3 = peg$currPos;
3392
2932
  peg$savedPos = peg$currPos;
3393
- s4 = peg$f83(s2);
2933
+ s4 = peg$f57(s2);
3394
2934
  if (s4) s4 = void 0;
3395
2935
  else s4 = peg$FAILED;
3396
2936
  if (s4 !== peg$FAILED) {
@@ -3429,7 +2969,7 @@ function peg$parse(input, options) {
3429
2969
  if (s0 === peg$FAILED) {
3430
2970
  s0 = peg$currPos;
3431
2971
  peg$savedPos = peg$currPos;
3432
- s1 = peg$f84();
2972
+ s1 = peg$f58();
3433
2973
  if (s1) s1 = void 0;
3434
2974
  else s1 = peg$FAILED;
3435
2975
  if (s1 !== peg$FAILED) {
@@ -3456,12 +2996,12 @@ function peg$parse(input, options) {
3456
2996
  if (s6 !== peg$FAILED) {
3457
2997
  s7 = peg$parseHere();
3458
2998
  peg$savedPos = peg$currPos;
3459
- s8 = peg$f85(s4, s7);
2999
+ s8 = peg$f59(s4, s7);
3460
3000
  if (s8) s8 = void 0;
3461
3001
  else s8 = peg$FAILED;
3462
3002
  if (s8 !== peg$FAILED) {
3463
3003
  s9 = peg$currPos;
3464
- s10 = peg$f86(s4, s7);
3004
+ s10 = peg$f60(s4, s7);
3465
3005
  s11 = peg$currPos;
3466
3006
  s12 = [];
3467
3007
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -3543,7 +3083,7 @@ function peg$parse(input, options) {
3543
3083
  if (s0 === peg$FAILED) {
3544
3084
  s0 = peg$currPos;
3545
3085
  peg$savedPos = peg$currPos;
3546
- s1 = peg$f87();
3086
+ s1 = peg$f61();
3547
3087
  if (s1) s1 = void 0;
3548
3088
  else s1 = peg$FAILED;
3549
3089
  if (s1 !== peg$FAILED) {
@@ -3634,7 +3174,7 @@ function peg$parse(input, options) {
3634
3174
  if (s0 === peg$FAILED) {
3635
3175
  s0 = peg$currPos;
3636
3176
  peg$savedPos = peg$currPos;
3637
- s1 = peg$f88();
3177
+ s1 = peg$f62();
3638
3178
  if (s1) s1 = void 0;
3639
3179
  else s1 = peg$FAILED;
3640
3180
  if (s1 !== peg$FAILED) {
@@ -3749,17 +3289,35 @@ function peg$parse(input, options) {
3749
3289
  }
3750
3290
  return -1;
3751
3291
  }
3292
+ /**
3293
+ * Where the selectors `s` are written, from `start` up to `after`, the end of
3294
+ * what Selectors consumed (the one space that may follow them is not part of
3295
+ * them): the fields of a token; none without selectors.
3296
+ */
3297
+ function selectorSpan(s, start, after) {
3298
+ if (s === NO_SELECTORS) return {};
3299
+ return {
3300
+ selectorsStart: start,
3301
+ selectorsEnd: input.charAt(after - 1) === " " ? after - 1 : after
3302
+ };
3303
+ }
3752
3304
  function skipTo(end) {
3753
3305
  skipEnd = end;
3754
3306
  return end >= 0;
3755
3307
  }
3756
- function fail(message, loc) {
3757
- error(message, loc);
3308
+ /** Fail with `message` at `loc`; `code` tells the kind of error apart (MarkupError). */
3309
+ function fail(message, loc, code) {
3310
+ try {
3311
+ error(message, loc);
3312
+ } catch (e) {
3313
+ e.code = code;
3314
+ throw e;
3315
+ }
3758
3316
  }
3759
3317
  function attrs(list) {
3760
3318
  const attributes = {};
3761
3319
  const seen = /* @__PURE__ */ new Set();
3762
- for (const [name, value] of list) {
3320
+ for (const { name, value } of list) {
3763
3321
  const lower = name.toLowerCase();
3764
3322
  if (seen.has(lower)) continue;
3765
3323
  seen.add(lower);
@@ -3772,38 +3330,6 @@ function peg$parse(input, options) {
3772
3330
  }
3773
3331
  return attributes;
3774
3332
  }
3775
- /** Check the body of a macro or element against its opening tag. */
3776
- function checkBody(open, body) {
3777
- for (const branch of body.branches) {
3778
- const parent = BRANCH_PARENT[branch.tag.lower];
3779
- if (open.lex !== "macro" || open.lower !== parent) fail(label(branch.tag) + " must be directly inside {" + parent + RB + ", not inside " + label(open), branch.tag.loc);
3780
- }
3781
- if (!body.end) fail("Unclosed " + label(open) + ": no " + closerOf(open) + " closes it", open.loc);
3782
- 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);
3783
- }
3784
- function macroNode(tag, body) {
3785
- const node = {
3786
- type: "macro",
3787
- name: tag.lower,
3788
- rawArgs: tag.rawArgs,
3789
- children: []
3790
- };
3791
- if (!body) return withSelectors(node, tag);
3792
- checkBody(tag, body);
3793
- node.children = body.children;
3794
- if (BRANCHING.has(tag.lower)) {
3795
- node.branches = [withSelectors({
3796
- rawArgs: tag.rawArgs,
3797
- children: body.children
3798
- }, tag)];
3799
- for (const b of body.branches) node.branches.push(withSelectors({
3800
- rawArgs: b.tag.rawArgs,
3801
- children: b.children
3802
- }, b.tag));
3803
- node.children = [];
3804
- } else withSelectors(node, tag);
3805
- return node;
3806
- }
3807
3333
  peg$result = peg$startRuleFunction();
3808
3334
  const peg$success = peg$result !== peg$FAILED && peg$currPos === input.length;
3809
3335
  function peg$throw() {
@@ -3858,33 +3384,298 @@ var NameSet = class {
3858
3384
  delete(name) {
3859
3385
  this.names.delete(name);
3860
3386
  }
3861
- };
3862
- //#endregion
3863
- //#region src/markup/ast.ts
3864
- /** Macros that require a closing tag and can contain children */
3865
- var BLOCK_MACROS = new NameSet([
3866
- "if",
3867
- "for",
3868
- "do",
3869
- "button",
3870
- "link",
3871
- "listbox",
3872
- "cycle",
3873
- "switch",
3874
- "timed",
3875
- "repeat",
3876
- "type",
3877
- "widget",
3878
- "span",
3879
- "nobr"
3880
- ]);
3881
- /** Whether a macro takes a body closed by `{/name}`. */
3882
- function isBlockMacro(name) {
3883
- return BLOCK_MACROS.has(name);
3387
+ };
3388
+ //#endregion
3389
+ //#region src/markup/ast.ts
3390
+ /**
3391
+ * The passage AST (built by parse.ts), and the registry of block macros:
3392
+ * those whose body the parser nests up to their `{/name}`.
3393
+ */
3394
+ /** Macros that require a closing tag and can contain children */
3395
+ var BLOCK_MACROS = new NameSet([
3396
+ "if",
3397
+ "for",
3398
+ "do",
3399
+ "button",
3400
+ "link",
3401
+ "listbox",
3402
+ "cycle",
3403
+ "switch",
3404
+ "timed",
3405
+ "repeat",
3406
+ "type",
3407
+ "widget",
3408
+ "span",
3409
+ "nobr"
3410
+ ]);
3411
+ /** Macros whose body is JavaScript source, kept verbatim. */
3412
+ var RAW_BODY_MACROS = new Set(["do"]);
3413
+ /** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
3414
+ function isRawMacro(name) {
3415
+ return RAW_BODY_MACROS.has(name);
3416
+ }
3417
+ /** Whether a macro takes a body closed by `{/name}`. */
3418
+ function isBlockMacro(name) {
3419
+ return BLOCK_MACROS.has(name);
3420
+ }
3421
+ /** Register a custom macro as a block macro so the parser nests children. */
3422
+ function registerBlockMacro(name) {
3423
+ BLOCK_MACROS.add(name);
3424
+ }
3425
+ /** Macros whose branches render as one: the node holds one per branch. */
3426
+ var BRANCHING = new Set([
3427
+ "if",
3428
+ "switch",
3429
+ "timed"
3430
+ ]);
3431
+ /** `value` as a quoted macro argument. */
3432
+ var quoteArg = (value) => `"${value.replace(/[\\"]/g, "\\$&")}"`;
3433
+ /** The AST of paired markup (see pair.ts): what the renderer runs. */
3434
+ function buildAst(nodes) {
3435
+ return nodes.map(astNode);
3436
+ }
3437
+ function astNode({ token, body }) {
3438
+ switch (token.type) {
3439
+ case "text": return token.comment ? {
3440
+ type: "text",
3441
+ value: token.value,
3442
+ comment: true
3443
+ } : {
3444
+ type: "text",
3445
+ value: token.value
3446
+ };
3447
+ case "link": return withSelectors$1({
3448
+ type: "macro",
3449
+ name: "link",
3450
+ rawArgs: `${quoteArg(token.display)} ${quoteArg(token.target)}`,
3451
+ children: []
3452
+ }, token);
3453
+ case "variable": return withSelectors$1({
3454
+ type: "variable",
3455
+ name: token.name,
3456
+ scope: token.scope
3457
+ }, token);
3458
+ case "expression": return withSelectors$1({
3459
+ type: "expression",
3460
+ expression: token.expression
3461
+ }, token);
3462
+ case "html": return {
3463
+ type: "html",
3464
+ tag: token.tag,
3465
+ attributes: token.attributes,
3466
+ children: body ? buildAst(body.children) : []
3467
+ };
3468
+ case "macro": {
3469
+ const name = token.name.toLowerCase();
3470
+ const node = {
3471
+ type: "macro",
3472
+ name,
3473
+ rawArgs: token.rawArgs,
3474
+ children: []
3475
+ };
3476
+ if (!body) return withSelectors$1(node, token);
3477
+ const children = buildAst(body.children);
3478
+ if (!BRANCHING.has(name)) {
3479
+ node.children = children;
3480
+ return withSelectors$1(node, token);
3481
+ }
3482
+ const branch = (tag, branchChildren) => withSelectors$1({
3483
+ rawArgs: tag.rawArgs,
3484
+ children: branchChildren
3485
+ }, tag);
3486
+ node.branches = [branch(token, children), ...body.branches.map(({ tag, children: c }) => branch(tag, buildAst(c)))];
3487
+ return node;
3488
+ }
3489
+ }
3490
+ }
3491
+ //#endregion
3492
+ //#region src/markup/line-column.ts
3493
+ /** 1-based line and column of `offset` in `text`. */
3494
+ function lineColumn(text, offset) {
3495
+ let line = 1;
3496
+ let lineStart = 0;
3497
+ for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
3498
+ line++;
3499
+ lineStart = i + 1;
3500
+ i = text.indexOf("\n", lineStart);
3501
+ }
3502
+ return {
3503
+ line,
3504
+ column: offset - lineStart + 1
3505
+ };
3506
+ }
3507
+ //#endregion
3508
+ //#region src/markup/pair.ts
3509
+ /**
3510
+ * Pairing: which closer closes which opener among the flat tokens of markup
3511
+ * (parse.ts tokenizeMarkup), and which branch (`{else}`, `{case}`) belongs to
3512
+ * which macro. The runtime AST (ast.ts) is built from this, and editor tooling
3513
+ * reads the same tree (`pairMarkup` in tooling.ts), so both agree on where a
3514
+ * block starts and ends.
3515
+ *
3516
+ * It never throws: a problem is an entry of `errors`, and the tree is
3517
+ * recovered around it. A closer closes the innermost open element, as the
3518
+ * runtime reads it, or, when it matches one further out, closes that one and
3519
+ * what was open inside it stays unclosed.
3520
+ */
3521
+ /** The last of `items`. */
3522
+ var last$1 = (items) => items[items.length - 1];
3523
+ /** The macro each branch macro belongs to. */
3524
+ var BRANCH_PARENT = {
3525
+ elseif: "if",
3526
+ else: "if",
3527
+ case: "switch",
3528
+ default: "switch",
3529
+ next: "timed"
3530
+ };
3531
+ var isBranchTag = (token) => token.type === "macro" && !token.isClose && Object.prototype.hasOwnProperty.call(BRANCH_PARENT, token.name.toLowerCase());
3532
+ var lowerName = (token) => nameOf(token).toLowerCase();
3533
+ /** The macro name or HTML tag of `tag`, as written. */
3534
+ var nameOf = (tag) => tag.type === "macro" ? tag.name : tag.tag;
3535
+ /** How a tag reads in an error message. */
3536
+ function tagLabel(tag) {
3537
+ return tag.type === "html" ? `${tag.isClose ? "</" : "<"}${tag.tag}>` : `{${tag.isClose ? "/" : ""}${tag.name}}`;
3538
+ }
3539
+ /** The tag that closes the element opened by `tag`. */
3540
+ var closerOf = (tag) => tag.type === "html" ? `</${tag.tag}>` : `{/${tag.name}}`;
3541
+ /** Whether `close` is the closing tag of the element opened by `open`. */
3542
+ var closes = (open, close) => open.type === close.type && lowerName(open) === lowerName(close);
3543
+ /**
3544
+ * Pair `tokens`, the tokens of `source`, into a tree: elements with their
3545
+ * bodies and branches, and the problems found (unclosed, mismatched and
3546
+ * stray closers, branches outside their macro) in the order a parser reading
3547
+ * from left to right notices them.
3548
+ */
3549
+ function pairMarkup(tokens, options = {}) {
3550
+ const isBlock = options.isBlock ?? isBlockMacro;
3551
+ const isRaw = options.isRaw ?? isRawMacro;
3552
+ const errors = [];
3553
+ const noticedAtEnd = (tokens[tokens.length - 1]?.end ?? 0) + 1;
3554
+ const where = (offset) => {
3555
+ if (options.source === void 0) return `offset ${offset}`;
3556
+ const { line, column } = lineColumn(options.source, offset);
3557
+ return `line ${line}, column ${column}`;
3558
+ };
3559
+ const report = (code, token, message, noticedAt, data) => {
3560
+ errors.push({
3561
+ code,
3562
+ message,
3563
+ start: token.start,
3564
+ end: token.end,
3565
+ noticedAt,
3566
+ data
3567
+ });
3568
+ };
3569
+ /** A branch outside its macro, or inside another element `inside`. */
3570
+ const misplaced = (tag, inside, noticedAt) => {
3571
+ const parent = BRANCH_PARENT[tag.name.toLowerCase()];
3572
+ const where = inside ? `, not inside ${tagLabel(inside)}` : "";
3573
+ report("misplaced-branch", tag, `${tagLabel(tag)} must be directly inside {${parent}}${where}`, noticedAt, {
3574
+ name: tag.name,
3575
+ parent,
3576
+ ...inside && { inside: nameOf(inside) }
3577
+ });
3578
+ };
3579
+ const root = [];
3580
+ const stack = [];
3581
+ const add = (node) => (last$1(stack)?.into ?? root).push(node);
3582
+ /**
3583
+ * End the element on top of the stack, with `close` if it has one: its
3584
+ * misplaced branches are reported first, then how it ends.
3585
+ */
3586
+ const end = (ending, close, owns = ending === "closed") => {
3587
+ const { node, body } = stack.pop();
3588
+ const open = node.token;
3589
+ const noticedAt = close ? close.end : noticedAtEnd;
3590
+ for (const { tag } of body.branches) {
3591
+ const parent = BRANCH_PARENT[tag.name.toLowerCase()];
3592
+ if (open.type !== "macro" || lowerName(open) !== parent) misplaced(tag, open, noticedAt);
3593
+ }
3594
+ if (ending === "unclosed") report("unclosed-block", open, `Unclosed ${tagLabel(open)}: no ${closerOf(open)} closes it`, noticedAt, { name: nameOf(open) });
3595
+ 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, {
3596
+ name: nameOf(open),
3597
+ closer: nameOf(close)
3598
+ });
3599
+ if (owns) body.close = close;
3600
+ node.end = body.close?.end ?? lastEnd(body) ?? open.end;
3601
+ add(node);
3602
+ };
3603
+ for (let i = 0; i < tokens.length; i++) {
3604
+ const token = tokens[i];
3605
+ if ((token.type === "macro" || token.type === "html") && token.isClose) {
3606
+ const top = last$1(stack);
3607
+ 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) });
3608
+ else if (closes(top.node.token, token)) end("closed", token);
3609
+ else {
3610
+ let outer = stack.length - 1;
3611
+ while (outer >= 0 && !closes(stack[outer].node.token, token)) outer--;
3612
+ end("mismatch", token, outer === -1);
3613
+ if (outer !== -1) {
3614
+ while (stack.length > outer + 1) end("cut", token);
3615
+ end("closed", token);
3616
+ }
3617
+ }
3618
+ continue;
3619
+ }
3620
+ if (isBranchTag(token)) {
3621
+ const tag = token;
3622
+ const frame = last$1(stack);
3623
+ if (!frame) {
3624
+ misplaced(tag, void 0, tag.start);
3625
+ continue;
3626
+ }
3627
+ const branch = {
3628
+ tag,
3629
+ children: []
3630
+ };
3631
+ frame.body.branches.push(branch);
3632
+ frame.into = branch.children;
3633
+ continue;
3634
+ }
3635
+ const node = {
3636
+ token,
3637
+ start: token.start,
3638
+ end: token.end
3639
+ };
3640
+ const opens = token.type === "html" ? !token.isSelfClose : token.type === "macro" && isBlock(token.name.toLowerCase());
3641
+ if (opens && token.type === "macro" && isRaw(token.name.toLowerCase()) && !closesRawBody(token, tokens[i + 1], tokens[i + 2])) {
3642
+ report("unclosed-block", token, `Unclosed ${tagLabel(token)}: no ${closerOf(token)} closes it`, token.end, { name: nameOf(token) });
3643
+ add(node);
3644
+ continue;
3645
+ }
3646
+ if (!opens) {
3647
+ add(node);
3648
+ continue;
3649
+ }
3650
+ const body = {
3651
+ children: [],
3652
+ branches: []
3653
+ };
3654
+ node.body = body;
3655
+ stack.push({
3656
+ node,
3657
+ body,
3658
+ into: body.children
3659
+ });
3660
+ }
3661
+ while (stack.length > 0) end("unclosed");
3662
+ return {
3663
+ nodes: root,
3664
+ errors
3665
+ };
3884
3666
  }
3885
- /** Register a custom macro as a block macro so the parser nests children. */
3886
- function registerBlockMacro(name) {
3887
- BLOCK_MACROS.add(name);
3667
+ /**
3668
+ * Whether the tokens after the opening tag `open` of a raw macro are its
3669
+ * body (one text token, if it is not empty) and its closer.
3670
+ */
3671
+ function closesRawBody(open, next, after) {
3672
+ const closer = (t) => t?.type === "macro" && t.isClose && closes(open, t);
3673
+ return closer(next) || next?.type === "text" && closer(after);
3674
+ }
3675
+ /** The end of the last thing in `body`. */
3676
+ function lastEnd(body) {
3677
+ const branch = last$1(body.branches);
3678
+ return last$1(branch?.children ?? body.children)?.end ?? branch?.tag.end;
3888
3679
  }
3889
3680
  //#endregion
3890
3681
  //#region node_modules/acorn/dist/acorn.mjs
@@ -10013,39 +9804,26 @@ function splitSigilTemplate(template) {
10013
9804
  * hooks plugged in. It builds the AST directly and reports malformed markup
10014
9805
  * as a MarkupError carrying its line and column.
10015
9806
  */
10016
- /** Macros whose body is JavaScript source, kept verbatim. */
10017
- var RAW_BODY_MACROS = new Set(["do"]);
10018
9807
  var defaultHooks = {
10019
9808
  ...defaultCodeEnd,
10020
9809
  isBlock: isBlockMacro,
10021
- isRaw: (name) => RAW_BODY_MACROS.has(name),
9810
+ isRaw: isRawMacro,
10022
9811
  isCodeAttribute
10023
9812
  };
10024
9813
  /** Malformed markup, with where it starts (1-based line and column). */
10025
9814
  var MarkupError = class extends Error {
10026
- constructor(reason, offset, line, column) {
9815
+ constructor(reason, offset, line, column, code = "syntax", end = offset, data = {}) {
10027
9816
  super(`${reason} (line ${line}, column ${column})`);
10028
9817
  this.reason = reason;
10029
9818
  this.offset = offset;
10030
9819
  this.line = line;
10031
9820
  this.column = column;
9821
+ this.code = code;
9822
+ this.end = end;
9823
+ this.data = data;
10032
9824
  this.name = "MarkupError";
10033
9825
  }
10034
9826
  };
10035
- /** 1-based line and column of `offset` in `text`. */
10036
- function lineColumn(text, offset) {
10037
- let line = 1;
10038
- let lineStart = 0;
10039
- for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
10040
- line++;
10041
- lineStart = i + 1;
10042
- i = text.indexOf("\n", lineStart);
10043
- }
10044
- return {
10045
- line,
10046
- column: offset - lineStart + 1
10047
- };
10048
- }
10049
9827
  function run$2(source, startRule, options) {
10050
9828
  const hooks = options.hooks ? {
10051
9829
  ...defaultHooks,
@@ -10058,21 +9836,61 @@ function run$2(source, startRule, options) {
10058
9836
  hooks
10059
9837
  });
10060
9838
  } catch (err) {
10061
- const location = err.location;
9839
+ const { location, code } = err;
10062
9840
  if (err instanceof Error && err.name === "SyntaxError" && location) {
10063
9841
  const { offset } = location.start;
10064
9842
  const { line, column } = lineColumn(source, offset);
10065
- throw new MarkupError(err.message, offset, line, column);
9843
+ throw new MarkupError(err.message, offset, line, column, code, location.end.offset);
10066
9844
  }
10067
9845
  throw err;
10068
9846
  }
10069
9847
  }
10070
9848
  /**
9849
+ * Read markup that may be malformed: its tokens, their pairing and every
9850
+ * error (malformed tags, and closers and branches that pair with nothing),
9851
+ * with offsets in `source`. Markup inside a malformed tag is not read as such,
9852
+ * so it has no errors of its own.
9853
+ */
9854
+ function analyzeMarkup(source, options = {}) {
9855
+ const { tokens, errors, damage } = scan(source, options);
9856
+ const hooks = {
9857
+ ...defaultHooks,
9858
+ ...options.hooks
9859
+ };
9860
+ const paired = pairMarkup(tokens, {
9861
+ isBlock: hooks.isBlock,
9862
+ isRaw: hooks.isRaw,
9863
+ source
9864
+ });
9865
+ if (errors.length === 0 && paired.errors.length === 0) return {
9866
+ tokens,
9867
+ nodes: paired.nodes,
9868
+ errors
9869
+ };
9870
+ const inDamage = (start) => errors.some((e, i) => start >= damage[i] && start <= e.offset);
9871
+ const noticed = errors.map((e, i) => [damage[i] + .5, e]);
9872
+ for (const error of paired.errors) if (!inDamage(error.start)) noticed.push([error.noticedAt, pairingError(source, error)]);
9873
+ noticed.sort((a, b) => a[0] - b[0]);
9874
+ return {
9875
+ tokens,
9876
+ nodes: paired.nodes,
9877
+ errors: noticed.map(([, e]) => e)
9878
+ };
9879
+ }
9880
+ /**
10071
9881
  * Parse markup into its AST: macros with their bodies and branches, HTML
10072
- * elements with their children. Throws a MarkupError for malformed markup.
9882
+ * elements with their children. Throws a MarkupError for malformed markup:
9883
+ * the first problem a parser reading from left to right meets.
10073
9884
  */
10074
9885
  function parseMarkup(source, options = {}) {
10075
- return run$2(source, "Markup", options);
9886
+ const { nodes, errors } = analyzeMarkup(source, options);
9887
+ if (errors.length > 0) throw errors[0];
9888
+ return buildAst(nodes);
9889
+ }
9890
+ /** A pairing problem as the MarkupError it is for `source`. */
9891
+ function pairingError(source, error) {
9892
+ const { line, column } = lineColumn(source, error.start);
9893
+ return new MarkupError(error.message, error.start, line, column, error.code, error.end, error.data);
10076
9894
  }
10077
9895
  /**
10078
9896
  * The flat tokens of markup, without nesting, so unclosed or mismatched
@@ -10091,8 +9909,21 @@ function tokenizeMarkup(source, options = {}) {
10091
9909
  * markup the tokens are those of `tokenizeMarkup` and there are no errors.
10092
9910
  */
10093
9911
  function tokenizeMarkupTolerant(source, options = {}) {
9912
+ const { tokens, errors } = scan(source, options);
9913
+ return {
9914
+ tokens,
9915
+ errors
9916
+ };
9917
+ }
9918
+ /**
9919
+ * The tokens of tolerant tokenizing, the errors, and where the damage of
9920
+ * each error starts: the tag that is malformed, which an error inside it
9921
+ * (an attribute value) is after.
9922
+ */
9923
+ function scan(source, options) {
10094
9924
  const tokens = [];
10095
9925
  const errors = [];
9926
+ const damage = [];
10096
9927
  const lastBrace = source.lastIndexOf("}");
10097
9928
  const { closeBrace } = {
10098
9929
  ...defaultHooks,
@@ -10108,7 +9939,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10108
9939
  return tokenizeMarkup(text, {
10109
9940
  ...options,
10110
9941
  hooks
10111
- }).map((token) => shift(token, base));
9942
+ }).map((token) => shiftOffsets(token, base));
10112
9943
  } catch (error) {
10113
9944
  if (!(error instanceof MarkupError)) throw error;
10114
9945
  return error;
@@ -10124,7 +9955,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10124
9955
  }
10125
9956
  const at = base + result.offset;
10126
9957
  const { line, column } = lineColumn(source, at);
10127
- errors.push(new MarkupError(result.reason, at, line, column));
9958
+ errors.push(new MarkupError(result.reason, at, line, column, result.code, base + result.end));
10128
9959
  let cut = result.offset;
10129
9960
  let prefix = attempt(rest.slice(0, cut), base);
10130
9961
  while (!Array.isArray(prefix)) {
@@ -10132,6 +9963,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10132
9963
  prefix = attempt(rest.slice(0, cut), base);
10133
9964
  }
10134
9965
  tokens.push(...prefix);
9966
+ damage.push(base + cut);
10135
9967
  if (cut < rest.length) {
10136
9968
  const start = base + cut;
10137
9969
  tokens.push({
@@ -10145,23 +9977,23 @@ function tokenizeMarkupTolerant(source, options = {}) {
10145
9977
  }
10146
9978
  return {
10147
9979
  tokens,
10148
- errors
9980
+ errors,
9981
+ damage
10149
9982
  };
10150
9983
  }
10151
- /** `token` with its offsets moved `by` on. */
10152
- function shift(token, by) {
10153
- if (by === 0) return token;
10154
- const moved = {
10155
- ...token,
10156
- start: token.start + by,
10157
- end: token.end + by
10158
- };
10159
- if (moved.type === "link") {
10160
- moved.targetStart += by;
10161
- moved.targetEnd += by;
10162
- }
9984
+ /** The offset fields of a token (and of an attribute): `start`, `nameEnd`… */
9985
+ var OFFSET_FIELD = /^(start|end|[A-Za-z]*(Start|End))$/;
9986
+ /** `token` (or an attribute of it) with each of its offsets turned by `map`. */
9987
+ function mapOffsets(token, map) {
9988
+ const moved = { ...token };
9989
+ for (const [key, value] of Object.entries(moved)) if (typeof value === "number" && OFFSET_FIELD.test(key)) moved[key] = map(value);
9990
+ else if (key === "attributeSpans") moved[key] = value.map((span) => mapOffsets(span, map));
10163
9991
  return moved;
10164
9992
  }
9993
+ /** `token` (or an attribute of it) with its offsets moved `by` on. */
9994
+ function shiftOffsets(token, by) {
9995
+ return by === 0 ? token : mapOffsets(token, (offset) => offset + by);
9996
+ }
10165
9997
  //#endregion
10166
9998
  //#region src/utils/namespace.ts
10167
9999
  /** The variable name no namespace can hold. */
@@ -10589,7 +10421,7 @@ function unset(param) {
10589
10421
  return param.type === "options" ? {} : void 0;
10590
10422
  }
10591
10423
  var WORD_RE = /\w+/y;
10592
- var NUMBER_RE = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
10424
+ var NUMBER_RE$1 = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
10593
10425
  var WORD_OR_PUNCT_RE = /\S+/y;
10594
10426
  /** Match the sticky regex `re` at `pos`, returning the matched text. */
10595
10427
  function matchAt(re, src, pos) {
@@ -10618,7 +10450,7 @@ function readOptions(params, src, { at, spans }) {
10618
10450
  let j = i;
10619
10451
  while (j < src.length && isWhitespace(src[j])) j++;
10620
10452
  const quoted = readQuoted(src, j);
10621
- const digits = quoted || j === i ? null : matchAt(NUMBER_RE, src, j);
10453
+ const digits = quoted || j === i ? null : matchAt(NUMBER_RE$1, src, j);
10622
10454
  if (quoted) {
10623
10455
  val = quoted.value;
10624
10456
  i = quoted.end;
@@ -10872,6 +10704,14 @@ function parseOrError(code, goal) {
10872
10704
  parses?.set(key, result);
10873
10705
  return result;
10874
10706
  }
10707
+ /** Where character `index` of the code or text of `piece` is in the source. */
10708
+ function pieceOffset(piece, index) {
10709
+ return piece.sourceOffsets?.[index] ?? piece.offset + index;
10710
+ }
10711
+ /** How much of a piece's own text or code there is (not its source extent). */
10712
+ function extentOf(piece) {
10713
+ return piece.kind === "code" ? piece.code.length : piece.kind === "text" ? piece.text.length : piece.length;
10714
+ }
10875
10715
  /** Macros whose whole argument text is one expression: branch conditions. */
10876
10716
  var CONDITION_MACROS = new Set([
10877
10717
  "if",
@@ -10948,48 +10788,34 @@ function* codeAndText(src, tokens, parametersOf) {
10948
10788
  macro: "link",
10949
10789
  label: src.slice(token.start, token.end)
10950
10790
  };
10951
- if (token.display.includes("{")) yield {
10952
- kind: "text",
10953
- text: token.display,
10954
- offset: locate(src, token.display, token.start),
10955
- where: "In the label of a link: "
10956
- };
10791
+ if (token.display.includes("{")) yield textPiece(token.display, token.displayStart, "In the label of a link: ");
10957
10792
  } else if (token.type === "expression") yield {
10958
10793
  kind: "code",
10959
10794
  code: token.expression,
10960
- offset: token.end - 1 - token.expression.length,
10795
+ offset: token.expressionStart,
10961
10796
  goal: "expression",
10962
10797
  label: `{${token.expression}}`
10963
10798
  };
10964
- else if (token.type === "html") {
10965
- let cursor = token.start;
10966
- for (const [name, value] of Object.entries(token.attributes)) {
10967
- const at = locate(src, value, cursor);
10968
- cursor = at + value.length;
10969
- if (!isCodeAttribute(name)) {
10970
- yield {
10971
- kind: "text",
10972
- text: value,
10973
- offset: at,
10974
- where: `In the ${name} attribute of <${token.tag}>: `
10975
- };
10976
- continue;
10977
- }
10978
- let from = 0;
10979
- for (const part of splitSigilTemplate(value)) {
10980
- if (!("expr" in part)) continue;
10981
- const k = locate(value, part.expr, from);
10982
- from = k + part.expr.length;
10983
- yield {
10984
- kind: "code",
10985
- code: part.expr,
10986
- offset: at + k,
10987
- goal: "expression",
10988
- label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
10989
- };
10990
- }
10799
+ else if (token.type === "html") for (const { name, value, at } of attributeValues(src, token)) {
10800
+ if (!isCodeAttribute(name)) {
10801
+ yield textPiece(value, at, `In the ${name} attribute of <${token.tag}>: `);
10802
+ continue;
10803
+ }
10804
+ let from = 0;
10805
+ for (const part of splitSigilTemplate(value)) {
10806
+ if (!("expr" in part)) continue;
10807
+ const k = locate(value, part.expr, from);
10808
+ from = k + part.expr.length;
10809
+ yield {
10810
+ kind: "code",
10811
+ code: part.expr,
10812
+ offset: at + k,
10813
+ goal: "expression",
10814
+ label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
10815
+ };
10991
10816
  }
10992
- } else if (token.type === "macro" && !token.isClose) {
10817
+ }
10818
+ else if (token.type === "macro" && !token.isClose) {
10993
10819
  const name = token.name.toLowerCase();
10994
10820
  if (name === "do") {
10995
10821
  const close = closeOf(t, name);
@@ -11023,8 +10849,7 @@ function* codeAndText(src, tokens, parametersOf) {
11023
10849
  }
11024
10850
  if (!args) continue;
11025
10851
  const label = `{${token.name} ${args}}`;
11026
- const tag = src.slice(token.start, token.end - 1);
11027
- const argsAt = token.start + tag.trimEnd().length - args.length;
10852
+ const argsAt = token.argsStart;
11028
10853
  if (CONDITION_MACROS.has(name)) {
11029
10854
  yield {
11030
10855
  kind: "code",
@@ -11040,8 +10865,95 @@ function* codeAndText(src, tokens, parametersOf) {
11040
10865
  }
11041
10866
  }
11042
10867
  }
10868
+ /**
10869
+ * `codeAndText`, with the markup in the texts read too: a text piece (a label,
10870
+ * an attribute value) with a `{` in it carries its tokens and errors, and is
10871
+ * followed by the pieces of that markup, `nested`, in the offsets of the whole
10872
+ * `src`. In source order, a nested piece after the text it is in.
10873
+ */
10874
+ function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
10875
+ yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0);
10876
+ }
10877
+ /**
10878
+ * The pieces of `tokens`, the tokens of `src`, which is the text described by
10879
+ * `where` (none for `root`, the markup of the whole passage), and whose
10880
+ * offsets `toRoot` turns into offsets in `root`.
10881
+ */
10882
+ function* expand(root, src, tokens, parametersOf, options, toRoot, where) {
10883
+ for (const flat of codeAndText(src, tokens, parametersOf)) {
10884
+ const piece = where ? nestedPiece(flat, toRoot, where) : flat;
10885
+ if (flat.kind !== "text" || !flat.text.includes("{")) {
10886
+ yield piece;
10887
+ continue;
10888
+ }
10889
+ const toText = (i) => toRoot(pieceOffset(flat, i));
10890
+ const inner = analyzeMarkup(flat.text, {
10891
+ text: true,
10892
+ hooks: options.isBlock && { isBlock: options.isBlock }
10893
+ });
10894
+ yield {
10895
+ ...piece,
10896
+ tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
10897
+ errors: inner.errors.map((e) => {
10898
+ const { line, column } = lineColumn(root, toText(e.offset));
10899
+ return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
10900
+ })
10901
+ };
10902
+ yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where);
10903
+ }
10904
+ }
10905
+ /** `piece`, of a text in another, with its offsets turned by `toRoot`. */
10906
+ function nestedPiece(piece, toRoot, where) {
10907
+ const offset = toRoot(piece.offset);
10908
+ const nested = {
10909
+ offset,
10910
+ nested: true,
10911
+ where
10912
+ };
10913
+ if (piece.kind === "passage" || piece.kind === "argument-error") {
10914
+ const length = toRoot(piece.offset + piece.length) - offset;
10915
+ return {
10916
+ ...piece,
10917
+ ...nested,
10918
+ length
10919
+ };
10920
+ }
10921
+ const extent = extentOf(piece);
10922
+ 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;
10923
+ return sourceOffsets ? {
10924
+ ...piece,
10925
+ ...nested,
10926
+ sourceOffsets
10927
+ } : {
10928
+ ...piece,
10929
+ ...nested
10930
+ };
10931
+ }
10932
+ /**
10933
+ * Where each character of `value`, the unescaped text of a quoted string
10934
+ * written as `raw` from `at` on (a backslash before a quote or a backslash
10935
+ * is dropped), is
10936
+ * in the source, and where the text ends. None when the text is where its
10937
+ * length says, or is not that string.
10938
+ */
10939
+ function escapeOffsets(raw, at, value) {
10940
+ const offsets = [];
10941
+ let escaped = false;
10942
+ let i = 0;
10943
+ while (offsets.length < value.length) {
10944
+ if (i >= raw.length) return void 0;
10945
+ offsets.push(at + i);
10946
+ if (raw[i] === "\\" && /["'\\]/.test(raw.charAt(i + 1))) {
10947
+ escaped = true;
10948
+ i += 2;
10949
+ } else i++;
10950
+ }
10951
+ offsets.push(at + i);
10952
+ return escaped ? offsets : void 0;
10953
+ }
11043
10954
  /** The code and text in the arguments `args` (at `offset`) of `macro`. */
11044
10955
  function* argPieces(args, offset, params, macro, label) {
10956
+ const name = macro.toLowerCase();
11045
10957
  let values;
11046
10958
  const spans = /* @__PURE__ */ new Map();
11047
10959
  try {
@@ -11052,11 +10964,12 @@ function* argPieces(args, offset, params, macro, label) {
11052
10964
  kind: "argument-error",
11053
10965
  message: error.message,
11054
10966
  offset,
11055
- label
10967
+ length: args.length,
10968
+ label,
10969
+ macro: name
11056
10970
  };
11057
10971
  return;
11058
10972
  }
11059
- const name = macro.toLowerCase();
11060
10973
  /** The pieces of the parameters `list`, with their values in `from`. */
11061
10974
  function* visit(list, from) {
11062
10975
  for (const param of list) {
@@ -11103,25 +11016,70 @@ function* argPieces(args, offset, params, macro, label) {
11103
11016
  }
11104
11017
  const at = offset + start + (value !== written && /^["']/.test(written) ? 1 : 0);
11105
11018
  const holds = stringHolds(param);
11106
- if (holds === "expression" || holds === "statements") yield {
11107
- kind: "code",
11108
- code: value,
11109
- offset: at,
11110
- goal: holds,
11111
- label,
11112
- inString: true
11113
- };
11114
- else if (holds === "passage") yield passage(value);
11115
- else if (holds === "markup") yield {
11116
- kind: "text",
11117
- text: value,
11118
- offset: at,
11119
- where: `In the ${param.name} of {${macro}}: `
11120
- };
11019
+ const sourceOffsets = escapeOffsets(args.slice(at - offset), at, value);
11020
+ if (holds === "expression" || holds === "statements") {
11021
+ const piece = {
11022
+ kind: "code",
11023
+ code: value,
11024
+ offset: at,
11025
+ goal: holds,
11026
+ label,
11027
+ inString: true
11028
+ };
11029
+ if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
11030
+ yield piece;
11031
+ } else if (holds === "passage") yield passage(value);
11032
+ else if (holds === "markup") {
11033
+ const piece = textPiece(value, at, `In the ${param.name} of {${macro}}: `);
11034
+ if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
11035
+ yield piece;
11036
+ }
11121
11037
  }
11122
11038
  }
11123
11039
  yield* [...visit(params, values)].sort((a, b) => a.offset - b.offset);
11124
11040
  }
11041
+ /** A text that may hold markup, at `offset`; read when it is expanded. */
11042
+ var textPiece = (text, offset, where) => ({
11043
+ kind: "text",
11044
+ text,
11045
+ offset,
11046
+ where,
11047
+ tokens: [],
11048
+ errors: []
11049
+ });
11050
+ /**
11051
+ * The attributes of an HTML tag by the values as written, with where each
11052
+ * value is: the first of equal names, which is the one in effect. A token
11053
+ * with no spans (made from an AST) has them found in `src`, in order.
11054
+ */
11055
+ function attributeValues(src, token) {
11056
+ if (token.attributeSpans.length === 0) {
11057
+ let cursor = token.start;
11058
+ return Object.entries(token.attributes).map(([name, value]) => {
11059
+ const at = locate(src, value, cursor);
11060
+ cursor = at + value.length;
11061
+ return {
11062
+ name,
11063
+ value,
11064
+ at
11065
+ };
11066
+ });
11067
+ }
11068
+ const seen = /* @__PURE__ */ new Set();
11069
+ const values = [];
11070
+ for (const span of token.attributeSpans) {
11071
+ const lower = span.name.toLowerCase();
11072
+ if (seen.has(lower)) continue;
11073
+ seen.add(lower);
11074
+ if (span.valueStart === void 0) continue;
11075
+ values.push({
11076
+ name: span.name,
11077
+ value: src.slice(span.valueStart, span.valueEnd),
11078
+ at: span.valueStart
11079
+ });
11080
+ }
11081
+ return values;
11082
+ }
11125
11083
  /**
11126
11084
  * Index of `part` in `text` from `from` on, else anywhere, else `from`: the
11127
11085
  * place to report an error in `part` at.
@@ -11277,26 +11235,27 @@ function astContainsChildren(nodes, parametersOf = registeredParameters) {
11277
11235
  for (const node of nodes) {
11278
11236
  if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
11279
11237
  if (node.type === "html") {
11280
- const span = {
11281
- start: 0,
11282
- end: 0
11283
- };
11284
11238
  if (tokenTextContainsChildren({
11285
11239
  isClose: false,
11286
11240
  isSelfClose: false,
11241
+ tagNameStart: 0,
11242
+ tagNameEnd: 0,
11243
+ attributeSpans: [],
11287
11244
  ...node,
11288
- ...span
11245
+ start: 0,
11246
+ end: 0
11289
11247
  }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11290
11248
  }
11291
11249
  if (node.type === "macro") {
11292
- const span = {
11293
- start: 0,
11294
- end: 0
11295
- };
11296
11250
  if (tokenTextContainsChildren({
11297
11251
  isClose: false,
11252
+ nameStart: 0,
11253
+ nameEnd: 0,
11254
+ argsStart: 0,
11255
+ argsEnd: 0,
11298
11256
  ...node,
11299
- ...span
11257
+ start: 0,
11258
+ end: 0
11300
11259
  }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
11301
11260
  if (node.branches) {
11302
11261
  for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf)) return true;
@@ -19875,13 +19834,10 @@ function distance(a, b) {
19875
19834
  }
19876
19835
  return prev[b.length];
19877
19836
  }
19878
- /**
19879
- * " Did you mean …?" with the known name closest to `name`, written by
19880
- * `quote`, if one is close.
19881
- */
19882
- function didYouMean(name, names, quote) {
19837
+ /** The known name closest to `name`, if one is close. */
19838
+ function closestName(name, names) {
19883
19839
  const lower = name.toLowerCase();
19884
- let best = "";
19840
+ let best;
19885
19841
  let bestDistance = Math.max(2, Math.floor(lower.length / 3)) + 1;
19886
19842
  for (const candidate of names) {
19887
19843
  const d = distance(lower, candidate.toLowerCase());
@@ -19890,8 +19846,10 @@ function didYouMean(name, names, quote) {
19890
19846
  bestDistance = d;
19891
19847
  }
19892
19848
  }
19893
- return best ? ` Did you mean ${quote(best)}?` : "";
19849
+ return best;
19894
19850
  }
19851
+ /** " Did you mean …?" with `best`, written by `quote`, if there is one. */
19852
+ var didYouMean = (best, quote) => best ? ` Did you mean ${quote(best)}?` : "";
19895
19853
  /** What a passage argument may be, after an error in one. */
19896
19854
  var PASSAGE_ARGUMENT_HINT = " (a passage name is a quoted string or an expression)";
19897
19855
  /** A passage argument that is one bare word (`{goto Kitchen}`). */
@@ -19911,14 +19869,18 @@ function widgetName(rawArgs) {
19911
19869
  function validateMarkup(passages, options) {
19912
19870
  const diagnostics = [];
19913
19871
  const hooks = options.isBlockMacro ? { isBlock: options.isBlockMacro } : void 0;
19914
- const report = (passage, offset, message) => {
19915
- const { line, column } = lineColumn(passage.content, offset);
19872
+ const report = (passage, start, end, code, message, data) => {
19873
+ const { line, column } = lineColumn(passage.content, start);
19916
19874
  const d = {
19917
19875
  passage: passage.name,
19918
19876
  line,
19919
19877
  column,
19920
- message
19878
+ message,
19879
+ code,
19880
+ start,
19881
+ end
19921
19882
  };
19883
+ if (data) d.data = data;
19922
19884
  const file = passage.metadata?.["data-source-file"];
19923
19885
  if (file) {
19924
19886
  d.file = file;
@@ -19927,6 +19889,8 @@ function validateMarkup(passages, options) {
19927
19889
  }
19928
19890
  diagnostics.push(d);
19929
19891
  };
19892
+ /** Report malformed markup. */
19893
+ const reportError = (passage, err, where) => report(passage, err.offset, err.end, err.code, where + err.reason, err.data);
19930
19894
  const parsed = [];
19931
19895
  const widgets = /* @__PURE__ */ new Set();
19932
19896
  const passageNames = /* @__PURE__ */ new Set();
@@ -19948,65 +19912,322 @@ function validateMarkup(passages, options) {
19948
19912
  parsed.push([passage, tokens]);
19949
19913
  } catch (err) {
19950
19914
  if (!(err instanceof MarkupError)) throw err;
19951
- if (reported) report(passage, err.offset, err.reason);
19915
+ if (reported) reportError(passage, err, "");
19952
19916
  }
19953
19917
  }
19954
19918
  const names = [...options.macroNames ?? [], ...widgets];
19955
- /** Report the unknown macros among `tokens`, which start at `base`. */
19956
- const checkMacros = (passage, tokens, base, where) => {
19919
+ /** Report the unknown macros among `tokens`, with `where` in front. */
19920
+ const checkMacros = (passage, tokens, where) => {
19957
19921
  for (const token of tokens) {
19958
19922
  if (token.type !== "macro" || token.isClose) continue;
19959
19923
  const lower = token.name.toLowerCase();
19960
19924
  if (BRANCH_MACROS.has(lower) || widgets.has(lower) || options.isKnownMacro(lower)) continue;
19961
- report(passage, base + token.start, `${where}Unknown macro {${token.name}}.${didYouMean(token.name, names, (n) => `{${n}}`)}`);
19925
+ const best = closestName(token.name, names);
19926
+ report(passage, token.start, token.end, "unknown-macro", `${where}Unknown macro {${token.name}}.${didYouMean(best, (n) => `{${n}}`)}`, {
19927
+ name: token.name,
19928
+ suggestions: best ? [best] : []
19929
+ });
19962
19930
  }
19963
19931
  };
19964
19932
  const parametersOf = options.parametersOf ?? (() => void 0);
19965
19933
  /**
19966
- * Check `tokens`, the tokens of `src`, which starts at `base` in the
19967
- * passage: their macros, the code in them and the markup in their text.
19934
+ * Check the pieces of a passage: its macros, the code in them, the passage
19935
+ * names they write out and the markup in their text.
19968
19936
  */
19969
- const checkTokens = (passage, src, tokens, base, where) => {
19970
- checkMacros(passage, tokens, base, where);
19971
- for (const piece of codeAndText(src, tokens, parametersOf)) {
19972
- const at = base + piece.offset;
19973
- if (piece.kind === "argument-error") {
19974
- report(passage, at, `${where}${piece.message} in ${piece.label}`);
19975
- continue;
19937
+ const checkPassage = (passage, tokens) => {
19938
+ checkMacros(passage, tokens, "");
19939
+ let skipTo = 0;
19940
+ for (const piece of passagePiecesOf(passage.content, tokens, parametersOf, { isBlock: options.isBlockMacro })) {
19941
+ if (piece.nested && piece.offset < skipTo) continue;
19942
+ const at = piece.offset;
19943
+ const where = piece.where && piece.nested ? piece.where : "";
19944
+ switch (piece.kind) {
19945
+ case "argument-error":
19946
+ report(passage, at, at + piece.length, "argument-error", `${where}${piece.message} in ${piece.label}`, { macro: piece.macro });
19947
+ break;
19948
+ case "passage":
19949
+ if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
19950
+ const best = closestName(piece.name, passageNames);
19951
+ report(passage, at, at + piece.length, "unknown-passage", `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${didYouMean(best, JSON.stringify)}`, {
19952
+ name: piece.name,
19953
+ macro: piece.macro,
19954
+ suggestions: best ? [best] : []
19955
+ });
19956
+ }
19957
+ break;
19958
+ case "code":
19959
+ checkCode(passage, piece, where);
19960
+ break;
19961
+ case "text": if (piece.errors.length > 0) {
19962
+ reportError(passage, piece.errors[0], piece.where);
19963
+ skipTo = pieceOffset(piece, piece.text.length);
19964
+ } else checkMacros(passage, piece.tokens, piece.where);
19976
19965
  }
19977
- if (piece.kind === "passage") {
19978
- if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
19979
- const hint = didYouMean(piece.name, passageNames, JSON.stringify);
19980
- report(passage, at, `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${hint}`);
19981
- }
19982
- continue;
19966
+ }
19967
+ };
19968
+ const checkCode = (passage, piece, where) => {
19969
+ const at = piece.offset;
19970
+ const result = parseOrError(piece.code, piece.goal);
19971
+ const code = piece.code.trim();
19972
+ if (result instanceof CodeSyntaxError) {
19973
+ const offending = /^(?:[\w$]+|\S)/.exec(piece.code.slice(result.pos));
19974
+ 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);
19975
+ } else if (piece.passage && BARE_WORD_RE.test(code)) {
19976
+ const lead = piece.code.length - piece.code.trimStart().length;
19977
+ 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}`, {
19978
+ name: code,
19979
+ macro: piece.macro ?? ""
19980
+ });
19981
+ }
19982
+ };
19983
+ for (const [passage, tokens] of parsed) withParseCache(() => checkPassage(passage, tokens));
19984
+ return diagnostics;
19985
+ }
19986
+ //#endregion
19987
+ //#region src/static-literal.ts
19988
+ /**
19989
+ * The shape of a JavaScript literal, read from its text without running it:
19990
+ * what a StoryVariables initializer is when it is a literal, or an array or
19991
+ * object literal of literals (see parseDeclarations in story-variables.ts).
19992
+ *
19993
+ * The reader is deliberately small. Anything it does not recognise (a call,
19994
+ * an operator, a reference, a spread) is "not static", which is no error: the
19995
+ * value is simply not known without running the code.
19996
+ */
19997
+ var NUMBER_RE = /(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(?:[eE][+-]?\d+)?)(n?)/y;
19998
+ var IDENT_RE = /[A-Za-z_$][\w$]*/y;
19999
+ var ARROW_RE = /(?:async\s+)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*=>/y;
20000
+ /** Read `src`, one literal and nothing else. */
20001
+ function staticLiteral(src) {
20002
+ const reader = new Reader(src);
20003
+ const value = reader.value();
20004
+ reader.space();
20005
+ return reader.i === src.length ? value : void 0;
20006
+ }
20007
+ var Reader = class {
20008
+ constructor(src) {
20009
+ this.src = src;
20010
+ this.i = 0;
20011
+ }
20012
+ /** Skip whitespace and comments. */
20013
+ space() {
20014
+ const { src } = this;
20015
+ for (;;) {
20016
+ while (/\s/.test(src.charAt(this.i))) this.i++;
20017
+ if (src.startsWith("//", this.i)) {
20018
+ const end = src.indexOf("\n", this.i);
20019
+ this.i = end < 0 ? src.length : end;
20020
+ } else if (src.startsWith("/*", this.i)) {
20021
+ const end = src.indexOf("*/", this.i + 2);
20022
+ this.i = end < 0 ? src.length : end + 2;
20023
+ } else return;
20024
+ }
20025
+ }
20026
+ /** The value at the cursor, which is left after it (or anywhere, if not static). */
20027
+ value() {
20028
+ const { src } = this;
20029
+ this.space();
20030
+ const c = src.charAt(this.i);
20031
+ if (c === "\"" || c === "'") return this.string().closed ? { shape: { type: "string" } } : void 0;
20032
+ if (c === "`") return this.template();
20033
+ if (c === "[") return this.skipBalanced() ? { shape: { type: "array" } } : void 0;
20034
+ if (c === "{") return this.object();
20035
+ if (/[\d.+-]/.test(c)) return this.number();
20036
+ if (/[A-Za-z_$(]/.test(c)) return this.word();
20037
+ }
20038
+ /** Skip the string literal at the cursor: its body, and whether it is closed. */
20039
+ string() {
20040
+ const { end, closed } = scanStringLiteral(this.src, this.i);
20041
+ const body = this.src.slice(this.i + 1, closed ? end - 1 : end);
20042
+ this.i = end;
20043
+ return {
20044
+ body,
20045
+ closed
20046
+ };
20047
+ }
20048
+ /** A template literal: a string, but for `${}`. */
20049
+ template() {
20050
+ const { src } = this;
20051
+ for (let i = this.i + 1; i < src.length; i++) {
20052
+ const c = src.charAt(i);
20053
+ if (c === "\\") i++;
20054
+ else if (c === "`") {
20055
+ this.i = i + 1;
20056
+ return { shape: { type: "string" } };
20057
+ } else if (c === "$" && src.charAt(i + 1) === "{") return void 0;
20058
+ }
20059
+ }
20060
+ /** A number, or a sign and one. */
20061
+ number() {
20062
+ const { src } = this;
20063
+ let i = this.i;
20064
+ if (src.charAt(i) === "+" || src.charAt(i) === "-") {
20065
+ i++;
20066
+ while (/\s/.test(src.charAt(i))) i++;
20067
+ }
20068
+ NUMBER_RE.lastIndex = i;
20069
+ const match = NUMBER_RE.exec(src);
20070
+ if (match) {
20071
+ this.i = NUMBER_RE.lastIndex;
20072
+ return match[1] ? { unsupported: "bigint" } : { shape: { type: "number" } };
20073
+ }
20074
+ IDENT_RE.lastIndex = i;
20075
+ if (IDENT_RE.exec(src)?.[0] === "Infinity") {
20076
+ this.i = IDENT_RE.lastIndex;
20077
+ return { shape: { type: "number" } };
20078
+ }
20079
+ }
20080
+ /** A keyword, a function, or a name (which is not static). */
20081
+ word() {
20082
+ const { src } = this;
20083
+ ARROW_RE.lastIndex = this.i;
20084
+ if (ARROW_RE.test(src)) return this.function();
20085
+ IDENT_RE.lastIndex = this.i;
20086
+ const word = IDENT_RE.exec(src)?.[0];
20087
+ if (word === void 0) return void 0;
20088
+ const end = IDENT_RE.lastIndex;
20089
+ switch (word) {
20090
+ case "true":
20091
+ case "false":
20092
+ this.i = end;
20093
+ return { shape: { type: "boolean" } };
20094
+ case "null":
20095
+ this.i = end;
20096
+ return { shape: { type: "null" } };
20097
+ case "NaN":
20098
+ this.i = end;
20099
+ return { shape: { type: "number" } };
20100
+ case "undefined":
20101
+ this.i = end;
20102
+ return { unsupported: "undefined" };
20103
+ case "function":
20104
+ case "class":
20105
+ case "async": return this.function();
20106
+ }
20107
+ }
20108
+ /** A function (or class): the rest is its body, which is not read. */
20109
+ function() {
20110
+ return this.unsupported({ unsupported: "function" });
20111
+ }
20112
+ /** `value`, which makes the whole literal unsupported: the rest is not read. */
20113
+ unsupported(value) {
20114
+ this.i = this.src.length;
20115
+ return value;
20116
+ }
20117
+ /** An object literal: the members that are static. */
20118
+ object() {
20119
+ const { src } = this;
20120
+ const fields = /* @__PURE__ */ new Map();
20121
+ this.i++;
20122
+ for (;;) {
20123
+ this.space();
20124
+ const c = src.charAt(this.i);
20125
+ if (c === "}") {
20126
+ this.i++;
20127
+ return { shape: {
20128
+ type: "object",
20129
+ fields
20130
+ } };
19983
20131
  }
19984
- if (piece.kind === "code") {
19985
- const result = parseOrError(piece.code, piece.goal);
19986
- const code = piece.code.trim();
19987
- if (result instanceof CodeSyntaxError) {
19988
- const reason = result.reasonIn(passage.content, at);
19989
- report(passage, at + result.pos, `${where}${reason} in ${piece.label}` + (piece.passage ? PASSAGE_ARGUMENT_HINT : ""));
19990
- } 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}`);
20132
+ if (c === ",") {
20133
+ this.i++;
19991
20134
  continue;
19992
20135
  }
19993
- if (!piece.text.includes("{")) continue;
19994
- try {
19995
- parseMarkup(piece.text, {
19996
- text: true,
19997
- hooks
19998
- });
19999
- const inner = tokenizeMarkup(piece.text, { text: true });
20000
- checkTokens(passage, piece.text, inner, at, piece.where);
20001
- } catch (err) {
20002
- if (!(err instanceof MarkupError)) throw err;
20003
- report(passage, at + err.offset, piece.where + err.reason);
20136
+ if (this.i >= src.length) return void 0;
20137
+ const key = this.key();
20138
+ this.space();
20139
+ if (key !== void 0 && src.charAt(this.i) === ":") {
20140
+ this.i++;
20141
+ const at = this.i;
20142
+ const value = this.value();
20143
+ this.space();
20144
+ if (value && "unsupported" in value) return this.unsupported(value);
20145
+ if (value && ",}".includes(src.charAt(this.i))) {
20146
+ fields.set(key, value.shape);
20147
+ continue;
20148
+ }
20149
+ this.i = at;
20150
+ } else if (key !== void 0 && src.charAt(this.i) === "(") return this.unsupported({ unsupported: "function" });
20151
+ if (!this.skipMember()) return void 0;
20152
+ }
20153
+ }
20154
+ /** The key of a member (a name, a string or a number), if it has one. */
20155
+ key() {
20156
+ const { src } = this;
20157
+ const c = src.charAt(this.i);
20158
+ if (c === "\"" || c === "'") {
20159
+ const { body, closed } = this.string();
20160
+ return closed ? body : void 0;
20161
+ }
20162
+ const word = /[\w$]+/y;
20163
+ word.lastIndex = this.i;
20164
+ const found = word.exec(src)?.[0];
20165
+ if (found === void 0) return void 0;
20166
+ this.i = word.lastIndex;
20167
+ return found;
20168
+ }
20169
+ /** Skip to the `,` or `}` that ends a member, balancing what is inside. */
20170
+ skipMember() {
20171
+ const { src } = this;
20172
+ while (this.i < src.length) {
20173
+ const c = src.charAt(this.i);
20174
+ if (c === "," || c === "}") return true;
20175
+ if (!this.skipOne()) return false;
20176
+ }
20177
+ return false;
20178
+ }
20179
+ /** Skip an array literal (or any bracketed group) at the cursor. */
20180
+ skipBalanced() {
20181
+ const { src } = this;
20182
+ const close = {
20183
+ "[": "]",
20184
+ "{": "}",
20185
+ "(": ")"
20186
+ }[src.charAt(this.i)];
20187
+ if (!close) return false;
20188
+ this.i++;
20189
+ while (this.i < src.length) {
20190
+ if (src.charAt(this.i) === close) {
20191
+ this.i++;
20192
+ return true;
20004
20193
  }
20194
+ if (!this.skipOne()) return false;
20005
20195
  }
20006
- };
20007
- for (const [passage, tokens] of parsed) withParseCache(() => checkTokens(passage, passage.content, tokens, 0, ""));
20008
- return diagnostics;
20009
- }
20196
+ return false;
20197
+ }
20198
+ /** Skip one character, or one string, template, comment or group. */
20199
+ skipOne() {
20200
+ const { src } = this;
20201
+ const c = src.charAt(this.i);
20202
+ if (c === "\"" || c === "'") return this.string().closed;
20203
+ if (c === "`") return this.skipTemplate();
20204
+ if (src.startsWith("//", this.i) || src.startsWith("/*", this.i)) {
20205
+ this.space();
20206
+ return true;
20207
+ }
20208
+ if (c === "[" || c === "{" || c === "(") return this.skipBalanced();
20209
+ if (c === "]" || c === "}" || c === ")") return false;
20210
+ this.i++;
20211
+ return true;
20212
+ }
20213
+ /** Skip a template literal, with the expressions in it. */
20214
+ skipTemplate() {
20215
+ const { src } = this;
20216
+ this.i++;
20217
+ while (this.i < src.length) {
20218
+ const c = src.charAt(this.i);
20219
+ if (c === "\\") this.i += 2;
20220
+ else if (c === "`") {
20221
+ this.i++;
20222
+ return true;
20223
+ } else if (c === "$" && src.charAt(this.i + 1) === "{") {
20224
+ this.i++;
20225
+ if (!this.skipBalanced()) return false;
20226
+ } else this.i++;
20227
+ }
20228
+ return false;
20229
+ }
20230
+ };
20010
20231
  //#endregion
20011
20232
  //#region src/story-variables.ts
20012
20233
  /**
@@ -20064,22 +20285,101 @@ function inferSchema(value, seen = /* @__PURE__ */ new Map()) {
20064
20285
  if (!VALID_VAR_TYPES.has(jsType)) throw new Error(`Unsupported type "${jsType}" for value ${String(value)}. Expected number, string, boolean, array, or object.`);
20065
20286
  return { type: jsType };
20066
20287
  }
20288
+ var UNSUPPORTED_TYPE = "Expected number, string, boolean, array, or object.";
20289
+ /** The schema of a literal shape (see staticLiteral). */
20290
+ function shapeSchema(shape) {
20291
+ if (!shape.fields) return { type: shape.type };
20292
+ const fields = /* @__PURE__ */ new Map();
20293
+ for (const [key, member] of shape.fields) fields.set(key, shapeSchema(member));
20294
+ return {
20295
+ type: shape.type,
20296
+ fields
20297
+ };
20298
+ }
20067
20299
  /**
20068
- * Parse a StoryVariables or StoryTransients passage content into a schema map.
20069
- * Each line: `$varName = expression` (or `%varName = expression` for transients)
20070
- */
20071
- function parseStoryVariables(content, sigil = "$") {
20072
- const schema = /* @__PURE__ */ new Map();
20300
+ * Read the declarations of a StoryVariables (`$name = value`) or
20301
+ * StoryTransients (`%name = value`) passage, without evaluating them and
20302
+ * without throwing: every valid declaration, and every invalid line as an
20303
+ * error. It is the grammar parseStoryVariables reads with.
20304
+ *
20305
+ * A declaration is a line of the form `$name = expression`; blank lines are
20306
+ * skipped. A line that is not, and a name that cannot be a variable, are
20307
+ * errors. So is an initializer that no variable can hold (a function,
20308
+ * `undefined`), when it is a literal; whether any other initializer can only
20309
+ * be known by running it. A name declared again is an error too, but both
20310
+ * declarations are returned (the later wins when evaluated).
20311
+ */
20312
+ function parseDeclarations(content, sigil = "$") {
20313
+ const declarations = [];
20314
+ const errors = [];
20073
20315
  const DECLARATION_RE = declarationRegex(sigil);
20074
- const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
20316
+ const seen = /* @__PURE__ */ new Set();
20317
+ let lineStart = 0;
20075
20318
  for (const rawLine of content.split("\n")) {
20319
+ const at = lineStart + rawLine.length - rawLine.trimStart().length;
20320
+ lineStart += rawLine.length + 1;
20076
20321
  const line = rawLine.trim();
20077
20322
  if (!line) continue;
20078
20323
  const match = line.match(DECLARATION_RE);
20079
- if (!match) throw new Error(`${passageName}: Invalid declaration: "${line}". Expected: ${sigil}name = value`);
20324
+ const error = (code, start, end, message) => errors.push({
20325
+ code,
20326
+ offset: start,
20327
+ end,
20328
+ message
20329
+ });
20330
+ if (!match) {
20331
+ error("invalid-declaration", at, at + line.length, `Invalid declaration: "${line}". Expected: ${sigil}name = value`);
20332
+ continue;
20333
+ }
20080
20334
  const [, name, expr] = match;
20335
+ const nameStart = at + sigil.length;
20336
+ const nameEnd = nameStart + name.length;
20081
20337
  const nameError = variableNameError(name, sigil + name);
20082
- if (nameError) throw new Error(`${passageName}: ${nameError}`);
20338
+ if (nameError) {
20339
+ error("invalid-name", nameStart, nameEnd, nameError);
20340
+ continue;
20341
+ }
20342
+ const valueEnd = at + line.length;
20343
+ const declaration = {
20344
+ name,
20345
+ nameStart,
20346
+ nameEnd,
20347
+ valueStart: valueEnd - expr.length,
20348
+ valueEnd
20349
+ };
20350
+ if (seen.has(name)) error("duplicate-declaration", nameStart, nameEnd, `Duplicate declaration of ${sigil}${name}`);
20351
+ seen.add(name);
20352
+ const literal = staticLiteral(expr);
20353
+ if (literal && "shape" in literal) declaration.schema = shapeSchema(literal.shape);
20354
+ else if (literal) error("unsupported-value", declaration.valueStart, valueEnd, `Unsupported type "${literal.unsupported}" for value ${expr}. ${UNSUPPORTED_TYPE}`);
20355
+ declarations.push(declaration);
20356
+ }
20357
+ return {
20358
+ declarations,
20359
+ errors
20360
+ };
20361
+ }
20362
+ /**
20363
+ * Parse a StoryVariables or StoryTransients passage content into a schema map.
20364
+ * Each line: `$varName = expression` (or `%varName = expression` for transients)
20365
+ * The expressions are evaluated; parseDeclarations reads the same lines
20366
+ * without.
20367
+ */
20368
+ function parseStoryVariables(content, sigil = "$") {
20369
+ const schema = /* @__PURE__ */ new Map();
20370
+ const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
20371
+ const { declarations, errors } = parseDeclarations(content, sigil);
20372
+ const lines = [...errors.filter((e) => e.code === "invalid-declaration" || e.code === "invalid-name").map((e) => ({
20373
+ at: e.offset,
20374
+ error: e
20375
+ })), ...declarations.map((d) => ({
20376
+ at: d.nameStart,
20377
+ declaration: d
20378
+ }))].sort((a, b) => a.at - b.at);
20379
+ for (const line of lines) {
20380
+ if ("error" in line) throw new Error(`${passageName}: ${line.error.message}`);
20381
+ const { name, valueStart, valueEnd } = line.declaration;
20382
+ const expr = content.slice(valueStart, valueEnd);
20083
20383
  let value;
20084
20384
  try {
20085
20385
  value = new Function("return (" + expr + ")")();