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