@rohal12/spindle 0.59.22 → 0.59.25
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 +1873 -1340
- package/dist/pkg/macro-registry.js +575 -0
- package/dist/pkg/story-variables.js +1882 -1223
- package/dist/pkg/tooling.js +26 -16
- package/package.json +2 -1
- package/src/code-check.ts +315 -64
- package/src/components/PassageDialog.tsx +28 -1
- package/src/components/macros/MenubarButtons.tsx +3 -0
- package/src/components/macros/SettingsControls.tsx +10 -6
- package/src/components/macros/Type.tsx +1 -1
- package/src/components/macros/detached-body.tsx +62 -3
- package/src/hooks/use-modal-focus.ts +62 -19
- 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/render.tsx +15 -4
- 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/settings.ts +9 -0
- package/src/static-literal.ts +292 -0
- package/src/story-variables.ts +438 -125
- package/src/tooling.ts +178 -9
- package/src/types-drift-check.ts +52 -0
- package/src/widgets/ast-scanner.ts +16 -4
- package/src/widgets/widget-def.ts +93 -22
- package/types/tooling.d.ts +571 -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
|
+
};
|
|
920
833
|
}
|
|
921
|
-
function peg$
|
|
922
|
-
fail("Unclosed attribute value: the " + q + " here has no closing " + q, location());
|
|
834
|
+
function peg$f54(q) {
|
|
835
|
+
fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
|
|
836
|
+
}
|
|
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;
|
|
@@ -1055,73 +975,22 @@ function peg$parse(input, options) {
|
|
|
1055
975
|
function peg$buildStructuredError(expected, found, location) {
|
|
1056
976
|
return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
|
|
1057
977
|
}
|
|
1058
|
-
function peg$
|
|
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() {
|
|
978
|
+
function peg$parseTokens() {
|
|
1110
979
|
let s0, s1, s2;
|
|
1111
980
|
s0 = peg$currPos;
|
|
1112
981
|
s1 = [];
|
|
1113
|
-
s2 = peg$
|
|
982
|
+
s2 = peg$parseTokenItem();
|
|
1114
983
|
while (s2 !== peg$FAILED) {
|
|
1115
984
|
s1.push(s2);
|
|
1116
|
-
s2 = peg$
|
|
985
|
+
s2 = peg$parseTokenItem();
|
|
1117
986
|
}
|
|
1118
987
|
peg$savedPos = s0;
|
|
1119
|
-
s1 = peg$
|
|
988
|
+
s1 = peg$f0(s1);
|
|
1120
989
|
s0 = s1;
|
|
1121
990
|
return s0;
|
|
1122
991
|
}
|
|
1123
|
-
function peg$
|
|
1124
|
-
let s0;
|
|
992
|
+
function peg$parseTokenItem() {
|
|
993
|
+
let s0, s1, s2, s3, s4;
|
|
1125
994
|
s0 = peg$parseTextRun();
|
|
1126
995
|
if (s0 === peg$FAILED) {
|
|
1127
996
|
s0 = peg$parseEscape();
|
|
@@ -1132,13 +1001,74 @@ function peg$parse(input, options) {
|
|
|
1132
1001
|
if (s0 === peg$FAILED) {
|
|
1133
1002
|
s0 = peg$parseEmailAutolink();
|
|
1134
1003
|
if (s0 === peg$FAILED) {
|
|
1135
|
-
s0 = peg$
|
|
1004
|
+
s0 = peg$currPos;
|
|
1005
|
+
peg$savedPos = peg$currPos;
|
|
1006
|
+
s1 = peg$f1();
|
|
1007
|
+
if (s1) s1 = void 0;
|
|
1008
|
+
else s1 = peg$FAILED;
|
|
1009
|
+
if (s1 !== peg$FAILED) {
|
|
1010
|
+
s2 = peg$parseHtmlOpen();
|
|
1011
|
+
if (s2 !== peg$FAILED) {
|
|
1012
|
+
peg$savedPos = s0;
|
|
1013
|
+
s0 = peg$f2(s2);
|
|
1014
|
+
} else {
|
|
1015
|
+
peg$currPos = s0;
|
|
1016
|
+
s0 = peg$FAILED;
|
|
1017
|
+
}
|
|
1018
|
+
} else {
|
|
1019
|
+
peg$currPos = s0;
|
|
1020
|
+
s0 = peg$FAILED;
|
|
1021
|
+
}
|
|
1136
1022
|
if (s0 === peg$FAILED) {
|
|
1137
|
-
s0 = peg$
|
|
1023
|
+
s0 = peg$currPos;
|
|
1024
|
+
peg$savedPos = peg$currPos;
|
|
1025
|
+
s1 = peg$f3();
|
|
1026
|
+
if (s1) s1 = void 0;
|
|
1027
|
+
else s1 = peg$FAILED;
|
|
1028
|
+
if (s1 !== peg$FAILED) {
|
|
1029
|
+
s2 = peg$parseHtmlClose();
|
|
1030
|
+
if (s2 !== peg$FAILED) {
|
|
1031
|
+
peg$savedPos = s0;
|
|
1032
|
+
s0 = peg$f4(s2);
|
|
1033
|
+
} else {
|
|
1034
|
+
peg$currPos = s0;
|
|
1035
|
+
s0 = peg$FAILED;
|
|
1036
|
+
}
|
|
1037
|
+
} else {
|
|
1038
|
+
peg$currPos = s0;
|
|
1039
|
+
s0 = peg$FAILED;
|
|
1040
|
+
}
|
|
1138
1041
|
if (s0 === peg$FAILED) {
|
|
1139
1042
|
s0 = peg$parseValue();
|
|
1140
1043
|
if (s0 === peg$FAILED) {
|
|
1141
|
-
s0 = peg$
|
|
1044
|
+
s0 = peg$currPos;
|
|
1045
|
+
s1 = peg$parseMacroTag();
|
|
1046
|
+
if (s1 !== peg$FAILED) {
|
|
1047
|
+
s2 = peg$currPos;
|
|
1048
|
+
peg$savedPos = peg$currPos;
|
|
1049
|
+
s3 = peg$f5(s1);
|
|
1050
|
+
if (s3) s3 = void 0;
|
|
1051
|
+
else s3 = peg$FAILED;
|
|
1052
|
+
if (s3 !== peg$FAILED) {
|
|
1053
|
+
s4 = peg$parseRawTokens();
|
|
1054
|
+
if (s4 !== peg$FAILED) {
|
|
1055
|
+
peg$savedPos = s2;
|
|
1056
|
+
s2 = peg$f6(s1, s4);
|
|
1057
|
+
} else {
|
|
1058
|
+
peg$currPos = s2;
|
|
1059
|
+
s2 = peg$FAILED;
|
|
1060
|
+
}
|
|
1061
|
+
} else {
|
|
1062
|
+
peg$currPos = s2;
|
|
1063
|
+
s2 = peg$FAILED;
|
|
1064
|
+
}
|
|
1065
|
+
if (s2 === peg$FAILED) s2 = null;
|
|
1066
|
+
peg$savedPos = s0;
|
|
1067
|
+
s0 = peg$f7(s1, s2);
|
|
1068
|
+
} else {
|
|
1069
|
+
peg$currPos = s0;
|
|
1070
|
+
s0 = peg$FAILED;
|
|
1071
|
+
}
|
|
1142
1072
|
if (s0 === peg$FAILED) s0 = peg$parseLiteral();
|
|
1143
1073
|
}
|
|
1144
1074
|
}
|
|
@@ -1150,134 +1080,18 @@ function peg$parse(input, options) {
|
|
|
1150
1080
|
}
|
|
1151
1081
|
return s0;
|
|
1152
1082
|
}
|
|
1153
|
-
function peg$
|
|
1154
|
-
let s0, s1, s2
|
|
1083
|
+
function peg$parseCloseTag() {
|
|
1084
|
+
let s0, s1, s2;
|
|
1155
1085
|
s0 = peg$currPos;
|
|
1156
1086
|
s1 = peg$parseMacroTag();
|
|
1157
1087
|
if (s1 !== peg$FAILED) {
|
|
1158
1088
|
peg$savedPos = peg$currPos;
|
|
1159
|
-
s2 = peg$
|
|
1089
|
+
s2 = peg$f8(s1);
|
|
1160
1090
|
if (s2) s2 = void 0;
|
|
1161
1091
|
else s2 = peg$FAILED;
|
|
1162
1092
|
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
1093
|
peg$savedPos = s0;
|
|
1280
|
-
s0 = peg$
|
|
1094
|
+
s0 = peg$f9(s1);
|
|
1281
1095
|
} else {
|
|
1282
1096
|
peg$currPos = s0;
|
|
1283
1097
|
s0 = peg$FAILED;
|
|
@@ -1286,108 +1100,17 @@ function peg$parse(input, options) {
|
|
|
1286
1100
|
peg$currPos = s0;
|
|
1287
1101
|
s0 = peg$FAILED;
|
|
1288
1102
|
}
|
|
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
1103
|
if (s0 === peg$FAILED) {
|
|
1314
1104
|
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
1105
|
peg$savedPos = peg$currPos;
|
|
1344
|
-
|
|
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;
|
|
1375
|
-
}
|
|
1376
|
-
} else {
|
|
1377
|
-
peg$currPos = s0;
|
|
1378
|
-
s0 = peg$FAILED;
|
|
1379
|
-
}
|
|
1380
|
-
if (s0 === peg$FAILED) {
|
|
1381
|
-
s0 = peg$currPos;
|
|
1382
|
-
peg$savedPos = peg$currPos;
|
|
1383
|
-
s1 = peg$f22();
|
|
1106
|
+
s1 = peg$f10();
|
|
1384
1107
|
if (s1) s1 = void 0;
|
|
1385
1108
|
else s1 = peg$FAILED;
|
|
1386
1109
|
if (s1 !== peg$FAILED) {
|
|
1387
1110
|
s2 = peg$parseHtmlClose();
|
|
1388
1111
|
if (s2 !== peg$FAILED) {
|
|
1389
1112
|
peg$savedPos = s0;
|
|
1390
|
-
s0 = peg$
|
|
1113
|
+
s0 = peg$f11(s2);
|
|
1391
1114
|
} else {
|
|
1392
1115
|
peg$currPos = s0;
|
|
1393
1116
|
s0 = peg$FAILED;
|
|
@@ -1399,187 +1122,17 @@ function peg$parse(input, options) {
|
|
|
1399
1122
|
}
|
|
1400
1123
|
return s0;
|
|
1401
1124
|
}
|
|
1402
|
-
function peg$parseRawBody() {
|
|
1403
|
-
let s0, s1, s2, s3, s4, s5, s6, s7;
|
|
1404
|
-
s0 = peg$currPos;
|
|
1405
|
-
s1 = peg$parseHere();
|
|
1406
|
-
peg$savedPos = peg$currPos;
|
|
1407
|
-
s2 = peg$f24(s1);
|
|
1408
|
-
if (s2) s2 = void 0;
|
|
1409
|
-
else s2 = peg$FAILED;
|
|
1410
|
-
if (s2 !== peg$FAILED) {
|
|
1411
|
-
s3 = peg$currPos;
|
|
1412
|
-
s4 = peg$f25(s1);
|
|
1413
|
-
s5 = peg$currPos;
|
|
1414
|
-
s6 = [];
|
|
1415
|
-
if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
|
|
1416
|
-
else if (input.length > peg$currPos) {
|
|
1417
|
-
s7 = input.charAt(peg$currPos);
|
|
1418
|
-
peg$currPos++;
|
|
1419
|
-
} else {
|
|
1420
|
-
s7 = peg$FAILED;
|
|
1421
|
-
if (peg$silentFails === 0) peg$fail(peg$e0);
|
|
1422
|
-
}
|
|
1423
|
-
while (s7 !== peg$FAILED) {
|
|
1424
|
-
s6.push(s7);
|
|
1425
|
-
if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
|
|
1426
|
-
else if (input.length > peg$currPos) {
|
|
1427
|
-
s7 = input.charAt(peg$currPos);
|
|
1428
|
-
peg$currPos++;
|
|
1429
|
-
} else {
|
|
1430
|
-
s7 = peg$FAILED;
|
|
1431
|
-
if (peg$silentFails === 0) peg$fail(peg$e0);
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
if (s6.length < (s4 | 0)) {
|
|
1435
|
-
peg$currPos = s5;
|
|
1436
|
-
s5 = peg$FAILED;
|
|
1437
|
-
} else s5 = s6;
|
|
1438
|
-
s4 = s5;
|
|
1439
|
-
if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
|
|
1440
|
-
else s3 = s4;
|
|
1441
|
-
if (s3 !== peg$FAILED) {
|
|
1442
|
-
s4 = peg$parseCloseTag();
|
|
1443
|
-
if (s4 !== peg$FAILED) {
|
|
1444
|
-
peg$savedPos = s0;
|
|
1445
|
-
s0 = peg$f26(s1, s3, s4);
|
|
1446
|
-
} else {
|
|
1447
|
-
peg$currPos = s0;
|
|
1448
|
-
s0 = peg$FAILED;
|
|
1449
|
-
}
|
|
1450
|
-
} else {
|
|
1451
|
-
peg$currPos = s0;
|
|
1452
|
-
s0 = peg$FAILED;
|
|
1453
|
-
}
|
|
1454
|
-
} else {
|
|
1455
|
-
peg$currPos = s0;
|
|
1456
|
-
s0 = peg$FAILED;
|
|
1457
|
-
}
|
|
1458
|
-
if (s0 === peg$FAILED) {
|
|
1459
|
-
s0 = peg$currPos;
|
|
1460
|
-
s1 = "";
|
|
1461
|
-
peg$savedPos = s0;
|
|
1462
|
-
s1 = peg$f27();
|
|
1463
|
-
s0 = s1;
|
|
1464
|
-
}
|
|
1465
|
-
return s0;
|
|
1466
|
-
}
|
|
1467
|
-
function peg$parseTokens() {
|
|
1468
|
-
let s0, s1, s2;
|
|
1469
|
-
s0 = peg$currPos;
|
|
1470
|
-
s1 = [];
|
|
1471
|
-
s2 = peg$parseTokenItem();
|
|
1472
|
-
while (s2 !== peg$FAILED) {
|
|
1473
|
-
s1.push(s2);
|
|
1474
|
-
s2 = peg$parseTokenItem();
|
|
1475
|
-
}
|
|
1476
|
-
peg$savedPos = s0;
|
|
1477
|
-
s1 = peg$f28(s1);
|
|
1478
|
-
s0 = s1;
|
|
1479
|
-
return s0;
|
|
1480
|
-
}
|
|
1481
|
-
function peg$parseTokenItem() {
|
|
1482
|
-
let s0, s1, s2, s3, s4;
|
|
1483
|
-
s0 = peg$parseTextRun();
|
|
1484
|
-
if (s0 === peg$FAILED) {
|
|
1485
|
-
s0 = peg$parseEscape();
|
|
1486
|
-
if (s0 === peg$FAILED) {
|
|
1487
|
-
s0 = peg$parseComment();
|
|
1488
|
-
if (s0 === peg$FAILED) {
|
|
1489
|
-
s0 = peg$parseLinkLexeme();
|
|
1490
|
-
if (s0 === peg$FAILED) {
|
|
1491
|
-
s0 = peg$parseEmailAutolink();
|
|
1492
|
-
if (s0 === peg$FAILED) {
|
|
1493
|
-
s0 = peg$currPos;
|
|
1494
|
-
peg$savedPos = peg$currPos;
|
|
1495
|
-
s1 = peg$f29();
|
|
1496
|
-
if (s1) s1 = void 0;
|
|
1497
|
-
else s1 = peg$FAILED;
|
|
1498
|
-
if (s1 !== peg$FAILED) {
|
|
1499
|
-
s2 = peg$parseHtmlOpen();
|
|
1500
|
-
if (s2 !== peg$FAILED) {
|
|
1501
|
-
peg$savedPos = s0;
|
|
1502
|
-
s0 = peg$f30(s2);
|
|
1503
|
-
} else {
|
|
1504
|
-
peg$currPos = s0;
|
|
1505
|
-
s0 = peg$FAILED;
|
|
1506
|
-
}
|
|
1507
|
-
} else {
|
|
1508
|
-
peg$currPos = s0;
|
|
1509
|
-
s0 = peg$FAILED;
|
|
1510
|
-
}
|
|
1511
|
-
if (s0 === peg$FAILED) {
|
|
1512
|
-
s0 = peg$currPos;
|
|
1513
|
-
peg$savedPos = peg$currPos;
|
|
1514
|
-
s1 = peg$f31();
|
|
1515
|
-
if (s1) s1 = void 0;
|
|
1516
|
-
else s1 = peg$FAILED;
|
|
1517
|
-
if (s1 !== peg$FAILED) {
|
|
1518
|
-
s2 = peg$parseHtmlClose();
|
|
1519
|
-
if (s2 !== peg$FAILED) {
|
|
1520
|
-
peg$savedPos = s0;
|
|
1521
|
-
s0 = peg$f32(s2);
|
|
1522
|
-
} else {
|
|
1523
|
-
peg$currPos = s0;
|
|
1524
|
-
s0 = peg$FAILED;
|
|
1525
|
-
}
|
|
1526
|
-
} else {
|
|
1527
|
-
peg$currPos = s0;
|
|
1528
|
-
s0 = peg$FAILED;
|
|
1529
|
-
}
|
|
1530
|
-
if (s0 === peg$FAILED) {
|
|
1531
|
-
s0 = peg$parseValue();
|
|
1532
|
-
if (s0 === peg$FAILED) {
|
|
1533
|
-
s0 = peg$currPos;
|
|
1534
|
-
s1 = peg$parseMacroTag();
|
|
1535
|
-
if (s1 !== peg$FAILED) {
|
|
1536
|
-
s2 = peg$currPos;
|
|
1537
|
-
peg$savedPos = peg$currPos;
|
|
1538
|
-
s3 = peg$f33(s1);
|
|
1539
|
-
if (s3) s3 = void 0;
|
|
1540
|
-
else s3 = peg$FAILED;
|
|
1541
|
-
if (s3 !== peg$FAILED) {
|
|
1542
|
-
s4 = peg$parseRawTokens();
|
|
1543
|
-
if (s4 !== peg$FAILED) {
|
|
1544
|
-
peg$savedPos = s2;
|
|
1545
|
-
s2 = peg$f34(s1, s4);
|
|
1546
|
-
} else {
|
|
1547
|
-
peg$currPos = s2;
|
|
1548
|
-
s2 = peg$FAILED;
|
|
1549
|
-
}
|
|
1550
|
-
} else {
|
|
1551
|
-
peg$currPos = s2;
|
|
1552
|
-
s2 = peg$FAILED;
|
|
1553
|
-
}
|
|
1554
|
-
if (s2 === peg$FAILED) s2 = null;
|
|
1555
|
-
peg$savedPos = s0;
|
|
1556
|
-
s0 = peg$f35(s1, s2);
|
|
1557
|
-
} else {
|
|
1558
|
-
peg$currPos = s0;
|
|
1559
|
-
s0 = peg$FAILED;
|
|
1560
|
-
}
|
|
1561
|
-
if (s0 === peg$FAILED) s0 = peg$parseLiteral();
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
return s0;
|
|
1571
|
-
}
|
|
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
2170
|
} else {
|
|
2612
|
-
peg$currPos =
|
|
2613
|
-
|
|
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 (
|
|
3094
|
-
else {
|
|
3095
|
-
peg$currPos =
|
|
3096
|
-
|
|
2624
|
+
if (s7 === peg$FAILED) s6 = void 0;
|
|
2625
|
+
else {
|
|
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() {
|
|
@@ -3806,6 +3332,10 @@ var NameSet = class {
|
|
|
3806
3332
|
};
|
|
3807
3333
|
//#endregion
|
|
3808
3334
|
//#region src/markup/ast.ts
|
|
3335
|
+
/**
|
|
3336
|
+
* The passage AST (built by parse.ts), and the registry of block macros:
|
|
3337
|
+
* those whose body the parser nests up to their `{/name}`.
|
|
3338
|
+
*/
|
|
3809
3339
|
/** Macros that require a closing tag and can contain children */
|
|
3810
3340
|
var BLOCK_MACROS = new NameSet([
|
|
3811
3341
|
"if",
|
|
@@ -3823,10 +3353,271 @@ var BLOCK_MACROS = new NameSet([
|
|
|
3823
3353
|
"span",
|
|
3824
3354
|
"nobr"
|
|
3825
3355
|
]);
|
|
3356
|
+
/** Macros whose body is JavaScript source, kept verbatim. */
|
|
3357
|
+
var RAW_BODY_MACROS = new Set(["do"]);
|
|
3358
|
+
/** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
|
|
3359
|
+
function isRawMacro(name) {
|
|
3360
|
+
return RAW_BODY_MACROS.has(name);
|
|
3361
|
+
}
|
|
3826
3362
|
/** Whether a macro takes a body closed by `{/name}`. */
|
|
3827
3363
|
function isBlockMacro(name) {
|
|
3828
3364
|
return BLOCK_MACROS.has(name);
|
|
3829
3365
|
}
|
|
3366
|
+
/** Macros whose branches render as one: the node holds one per branch. */
|
|
3367
|
+
var BRANCHING = new Set([
|
|
3368
|
+
"if",
|
|
3369
|
+
"switch",
|
|
3370
|
+
"timed"
|
|
3371
|
+
]);
|
|
3372
|
+
/** `value` as a quoted macro argument. */
|
|
3373
|
+
var quoteArg = (value) => `"${value.replace(/[\\"]/g, "\\$&")}"`;
|
|
3374
|
+
/** The AST of paired markup (see pair.ts): what the renderer runs. */
|
|
3375
|
+
function buildAst(nodes) {
|
|
3376
|
+
return nodes.map(astNode);
|
|
3377
|
+
}
|
|
3378
|
+
function astNode({ token, body }) {
|
|
3379
|
+
switch (token.type) {
|
|
3380
|
+
case "text": return token.comment ? {
|
|
3381
|
+
type: "text",
|
|
3382
|
+
value: token.value,
|
|
3383
|
+
comment: true
|
|
3384
|
+
} : {
|
|
3385
|
+
type: "text",
|
|
3386
|
+
value: token.value
|
|
3387
|
+
};
|
|
3388
|
+
case "link": return withSelectors$1({
|
|
3389
|
+
type: "macro",
|
|
3390
|
+
name: "link",
|
|
3391
|
+
rawArgs: `${quoteArg(token.display)} ${quoteArg(token.target)}`,
|
|
3392
|
+
children: []
|
|
3393
|
+
}, token);
|
|
3394
|
+
case "variable": return withSelectors$1({
|
|
3395
|
+
type: "variable",
|
|
3396
|
+
name: token.name,
|
|
3397
|
+
scope: token.scope
|
|
3398
|
+
}, token);
|
|
3399
|
+
case "expression": return withSelectors$1({
|
|
3400
|
+
type: "expression",
|
|
3401
|
+
expression: token.expression
|
|
3402
|
+
}, token);
|
|
3403
|
+
case "html": return {
|
|
3404
|
+
type: "html",
|
|
3405
|
+
tag: token.tag,
|
|
3406
|
+
attributes: token.attributes,
|
|
3407
|
+
children: body ? buildAst(body.children) : []
|
|
3408
|
+
};
|
|
3409
|
+
case "macro": {
|
|
3410
|
+
const name = token.name.toLowerCase();
|
|
3411
|
+
const node = {
|
|
3412
|
+
type: "macro",
|
|
3413
|
+
name,
|
|
3414
|
+
rawArgs: token.rawArgs,
|
|
3415
|
+
children: []
|
|
3416
|
+
};
|
|
3417
|
+
if (!body) return withSelectors$1(node, token);
|
|
3418
|
+
const children = buildAst(body.children);
|
|
3419
|
+
if (!BRANCHING.has(name)) {
|
|
3420
|
+
node.children = children;
|
|
3421
|
+
return withSelectors$1(node, token);
|
|
3422
|
+
}
|
|
3423
|
+
const branch = (tag, branchChildren) => withSelectors$1({
|
|
3424
|
+
rawArgs: tag.rawArgs,
|
|
3425
|
+
children: branchChildren
|
|
3426
|
+
}, tag);
|
|
3427
|
+
node.branches = [branch(token, children), ...body.branches.map(({ tag, children: c }) => branch(tag, buildAst(c)))];
|
|
3428
|
+
return node;
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
//#endregion
|
|
3433
|
+
//#region src/markup/line-column.ts
|
|
3434
|
+
/** 1-based line and column of `offset` in `text`. */
|
|
3435
|
+
function lineColumn(text, offset) {
|
|
3436
|
+
let line = 1;
|
|
3437
|
+
let lineStart = 0;
|
|
3438
|
+
for (let i = text.indexOf("\n"); i !== -1 && i < offset;) {
|
|
3439
|
+
line++;
|
|
3440
|
+
lineStart = i + 1;
|
|
3441
|
+
i = text.indexOf("\n", lineStart);
|
|
3442
|
+
}
|
|
3443
|
+
return {
|
|
3444
|
+
line,
|
|
3445
|
+
column: offset - lineStart + 1
|
|
3446
|
+
};
|
|
3447
|
+
}
|
|
3448
|
+
//#endregion
|
|
3449
|
+
//#region src/markup/pair.ts
|
|
3450
|
+
/**
|
|
3451
|
+
* Pairing: which closer closes which opener among the flat tokens of markup
|
|
3452
|
+
* (parse.ts tokenizeMarkup), and which branch (`{else}`, `{case}`) belongs to
|
|
3453
|
+
* which macro. The runtime AST (ast.ts) is built from this, and editor tooling
|
|
3454
|
+
* reads the same tree (`pairMarkup` in tooling.ts), so both agree on where a
|
|
3455
|
+
* block starts and ends.
|
|
3456
|
+
*
|
|
3457
|
+
* It never throws: a problem is an entry of `errors`, and the tree is
|
|
3458
|
+
* recovered around it. A closer closes the innermost open element, as the
|
|
3459
|
+
* runtime reads it, or, when it matches one further out, closes that one and
|
|
3460
|
+
* what was open inside it stays unclosed.
|
|
3461
|
+
*/
|
|
3462
|
+
/** The last of `items`. */
|
|
3463
|
+
var last$1 = (items) => items[items.length - 1];
|
|
3464
|
+
/** The macro each branch macro belongs to. */
|
|
3465
|
+
var BRANCH_PARENT = {
|
|
3466
|
+
elseif: "if",
|
|
3467
|
+
else: "if",
|
|
3468
|
+
case: "switch",
|
|
3469
|
+
default: "switch",
|
|
3470
|
+
next: "timed"
|
|
3471
|
+
};
|
|
3472
|
+
var isBranchTag = (token) => token.type === "macro" && !token.isClose && Object.prototype.hasOwnProperty.call(BRANCH_PARENT, token.name.toLowerCase());
|
|
3473
|
+
var lowerName = (token) => nameOf(token).toLowerCase();
|
|
3474
|
+
/** The macro name or HTML tag of `tag`, as written. */
|
|
3475
|
+
var nameOf = (tag) => tag.type === "macro" ? tag.name : tag.tag;
|
|
3476
|
+
/** How a tag reads in an error message. */
|
|
3477
|
+
function tagLabel(tag) {
|
|
3478
|
+
return tag.type === "html" ? `${tag.isClose ? "</" : "<"}${tag.tag}>` : `{${tag.isClose ? "/" : ""}${tag.name}}`;
|
|
3479
|
+
}
|
|
3480
|
+
/** The tag that closes the element opened by `tag`. */
|
|
3481
|
+
var closerOf = (tag) => tag.type === "html" ? `</${tag.tag}>` : `{/${tag.name}}`;
|
|
3482
|
+
/** Whether `close` is the closing tag of the element opened by `open`. */
|
|
3483
|
+
var closes = (open, close) => open.type === close.type && lowerName(open) === lowerName(close);
|
|
3484
|
+
/**
|
|
3485
|
+
* Pair `tokens`, the tokens of `source`, into a tree: elements with their
|
|
3486
|
+
* bodies and branches, and the problems found (unclosed, mismatched and
|
|
3487
|
+
* stray closers, branches outside their macro) in the order a parser reading
|
|
3488
|
+
* from left to right notices them.
|
|
3489
|
+
*/
|
|
3490
|
+
function pairMarkup(tokens, options = {}) {
|
|
3491
|
+
const isBlock = options.isBlock ?? isBlockMacro;
|
|
3492
|
+
const isRaw = options.isRaw ?? isRawMacro;
|
|
3493
|
+
const errors = [];
|
|
3494
|
+
const noticedAtEnd = (tokens[tokens.length - 1]?.end ?? 0) + 1;
|
|
3495
|
+
const where = (offset) => {
|
|
3496
|
+
if (options.source === void 0) return `offset ${offset}`;
|
|
3497
|
+
const { line, column } = lineColumn(options.source, offset);
|
|
3498
|
+
return `line ${line}, column ${column}`;
|
|
3499
|
+
};
|
|
3500
|
+
const report = (code, token, message, noticedAt, data) => {
|
|
3501
|
+
errors.push({
|
|
3502
|
+
code,
|
|
3503
|
+
message,
|
|
3504
|
+
start: token.start,
|
|
3505
|
+
end: token.end,
|
|
3506
|
+
noticedAt,
|
|
3507
|
+
data
|
|
3508
|
+
});
|
|
3509
|
+
};
|
|
3510
|
+
/** A branch outside its macro, or inside another element `inside`. */
|
|
3511
|
+
const misplaced = (tag, inside, noticedAt) => {
|
|
3512
|
+
const parent = BRANCH_PARENT[tag.name.toLowerCase()];
|
|
3513
|
+
const where = inside ? `, not inside ${tagLabel(inside)}` : "";
|
|
3514
|
+
report("misplaced-branch", tag, `${tagLabel(tag)} must be directly inside {${parent}}${where}`, noticedAt, {
|
|
3515
|
+
name: tag.name,
|
|
3516
|
+
parent,
|
|
3517
|
+
...inside && { inside: nameOf(inside) }
|
|
3518
|
+
});
|
|
3519
|
+
};
|
|
3520
|
+
const root = [];
|
|
3521
|
+
const stack = [];
|
|
3522
|
+
const add = (node) => (last$1(stack)?.into ?? root).push(node);
|
|
3523
|
+
/**
|
|
3524
|
+
* End the element on top of the stack, with `close` if it has one: its
|
|
3525
|
+
* misplaced branches are reported first, then how it ends.
|
|
3526
|
+
*/
|
|
3527
|
+
const end = (ending, close, owns = ending === "closed") => {
|
|
3528
|
+
const { node, body } = stack.pop();
|
|
3529
|
+
const open = node.token;
|
|
3530
|
+
const noticedAt = close ? close.end : noticedAtEnd;
|
|
3531
|
+
for (const { tag } of body.branches) {
|
|
3532
|
+
const parent = BRANCH_PARENT[tag.name.toLowerCase()];
|
|
3533
|
+
if (open.type !== "macro" || lowerName(open) !== parent) misplaced(tag, open, noticedAt);
|
|
3534
|
+
}
|
|
3535
|
+
if (ending === "unclosed") report("unclosed-block", open, `Unclosed ${tagLabel(open)}: no ${closerOf(open)} closes it`, noticedAt, { name: nameOf(open) });
|
|
3536
|
+
else if (ending === "mismatch") report("mismatched-closer", close, `${tagLabel(close)} found where ${closerOf(open)} should close the ${tagLabel(open)} opened at ${where(open.start)}`, noticedAt, {
|
|
3537
|
+
name: nameOf(open),
|
|
3538
|
+
closer: nameOf(close)
|
|
3539
|
+
});
|
|
3540
|
+
if (owns) body.close = close;
|
|
3541
|
+
node.end = body.close?.end ?? lastEnd(body) ?? open.end;
|
|
3542
|
+
add(node);
|
|
3543
|
+
};
|
|
3544
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
3545
|
+
const token = tokens[i];
|
|
3546
|
+
if ((token.type === "macro" || token.type === "html") && token.isClose) {
|
|
3547
|
+
const top = last$1(stack);
|
|
3548
|
+
if (!top) report("stray-closer", token, `${tagLabel(token)} closes nothing: no ${token.type === "html" ? `<${token.tag}>` : `{${token.name}}`} is open here`, token.start, { name: nameOf(token) });
|
|
3549
|
+
else if (closes(top.node.token, token)) end("closed", token);
|
|
3550
|
+
else {
|
|
3551
|
+
let outer = stack.length - 1;
|
|
3552
|
+
while (outer >= 0 && !closes(stack[outer].node.token, token)) outer--;
|
|
3553
|
+
end("mismatch", token, outer === -1);
|
|
3554
|
+
if (outer !== -1) {
|
|
3555
|
+
while (stack.length > outer + 1) end("cut", token);
|
|
3556
|
+
end("closed", token);
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
continue;
|
|
3560
|
+
}
|
|
3561
|
+
if (isBranchTag(token)) {
|
|
3562
|
+
const tag = token;
|
|
3563
|
+
const frame = last$1(stack);
|
|
3564
|
+
if (!frame) {
|
|
3565
|
+
misplaced(tag, void 0, tag.start);
|
|
3566
|
+
continue;
|
|
3567
|
+
}
|
|
3568
|
+
const branch = {
|
|
3569
|
+
tag,
|
|
3570
|
+
children: []
|
|
3571
|
+
};
|
|
3572
|
+
frame.body.branches.push(branch);
|
|
3573
|
+
frame.into = branch.children;
|
|
3574
|
+
continue;
|
|
3575
|
+
}
|
|
3576
|
+
const node = {
|
|
3577
|
+
token,
|
|
3578
|
+
start: token.start,
|
|
3579
|
+
end: token.end
|
|
3580
|
+
};
|
|
3581
|
+
const opens = token.type === "html" ? !token.isSelfClose : token.type === "macro" && isBlock(token.name.toLowerCase());
|
|
3582
|
+
if (opens && token.type === "macro" && isRaw(token.name.toLowerCase()) && !closesRawBody(token, tokens[i + 1], tokens[i + 2])) {
|
|
3583
|
+
report("unclosed-block", token, `Unclosed ${tagLabel(token)}: no ${closerOf(token)} closes it`, token.end, { name: nameOf(token) });
|
|
3584
|
+
add(node);
|
|
3585
|
+
continue;
|
|
3586
|
+
}
|
|
3587
|
+
if (!opens) {
|
|
3588
|
+
add(node);
|
|
3589
|
+
continue;
|
|
3590
|
+
}
|
|
3591
|
+
const body = {
|
|
3592
|
+
children: [],
|
|
3593
|
+
branches: []
|
|
3594
|
+
};
|
|
3595
|
+
node.body = body;
|
|
3596
|
+
stack.push({
|
|
3597
|
+
node,
|
|
3598
|
+
body,
|
|
3599
|
+
into: body.children
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3602
|
+
while (stack.length > 0) end("unclosed");
|
|
3603
|
+
return {
|
|
3604
|
+
nodes: root,
|
|
3605
|
+
errors
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3608
|
+
/**
|
|
3609
|
+
* Whether the tokens after the opening tag `open` of a raw macro are its
|
|
3610
|
+
* body (one text token, if it is not empty) and its closer.
|
|
3611
|
+
*/
|
|
3612
|
+
function closesRawBody(open, next, after) {
|
|
3613
|
+
const closer = (t) => t?.type === "macro" && t.isClose && closes(open, t);
|
|
3614
|
+
return closer(next) || next?.type === "text" && closer(after);
|
|
3615
|
+
}
|
|
3616
|
+
/** The end of the last thing in `body`. */
|
|
3617
|
+
function lastEnd(body) {
|
|
3618
|
+
const branch = last$1(body.branches);
|
|
3619
|
+
return last$1(branch?.children ?? body.children)?.end ?? branch?.tag.end;
|
|
3620
|
+
}
|
|
3830
3621
|
//#endregion
|
|
3831
3622
|
//#region node_modules/acorn/dist/acorn.mjs
|
|
3832
3623
|
var astralIdentifierCodes = [
|
|
@@ -9962,39 +9753,26 @@ function splitSigilTemplate(template) {
|
|
|
9962
9753
|
* hooks plugged in. It builds the AST directly and reports malformed markup
|
|
9963
9754
|
* as a MarkupError carrying its line and column.
|
|
9964
9755
|
*/
|
|
9965
|
-
/** Macros whose body is JavaScript source, kept verbatim. */
|
|
9966
|
-
var RAW_BODY_MACROS = new Set(["do"]);
|
|
9967
9756
|
var defaultHooks = {
|
|
9968
9757
|
...defaultCodeEnd,
|
|
9969
9758
|
isBlock: isBlockMacro,
|
|
9970
|
-
isRaw:
|
|
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,28 @@ 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
|
-
cursor = at + value.length;
|
|
10750
|
-
if (!isCodeAttribute(name)) {
|
|
10751
|
-
yield {
|
|
10752
|
-
kind: "text",
|
|
10753
|
-
text: value,
|
|
10754
|
-
offset: at,
|
|
10755
|
-
where: `In the ${name} attribute of <${token.tag}>: `
|
|
10756
|
-
};
|
|
10757
|
-
continue;
|
|
10758
|
-
}
|
|
10759
|
-
let from = 0;
|
|
10760
|
-
for (const part of splitSigilTemplate(value)) {
|
|
10761
|
-
if (!("expr" in part)) continue;
|
|
10762
|
-
const k = locate(value, part.expr, from);
|
|
10763
|
-
from = k + part.expr.length;
|
|
10764
|
-
yield {
|
|
10765
|
-
kind: "code",
|
|
10766
|
-
code: part.expr,
|
|
10767
|
-
offset: at + k,
|
|
10768
|
-
goal: "expression",
|
|
10769
|
-
label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
|
|
10770
|
-
};
|
|
10771
|
-
}
|
|
10580
|
+
else if (token.type === "html") for (const { name, value, at } of attributeValues(src, token)) {
|
|
10581
|
+
if (!isCodeAttribute(name)) {
|
|
10582
|
+
yield textPiece(value, at, `In the ${name} attribute of <${token.tag}>: `);
|
|
10583
|
+
continue;
|
|
10772
10584
|
}
|
|
10773
|
-
|
|
10585
|
+
for (const { expr, at: k } of sigilExpressions(value)) yield {
|
|
10586
|
+
kind: "code",
|
|
10587
|
+
code: expr,
|
|
10588
|
+
offset: at + k,
|
|
10589
|
+
goal: "expression",
|
|
10590
|
+
label: `{${expr}} in the ${name} attribute of <${token.tag}>`
|
|
10591
|
+
};
|
|
10592
|
+
}
|
|
10593
|
+
else if (token.type === "macro" && !token.isClose) {
|
|
10774
10594
|
const name = token.name.toLowerCase();
|
|
10775
10595
|
if (name === "do") {
|
|
10776
10596
|
const close = closeOf(t, name);
|
|
@@ -10804,8 +10624,7 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
10804
10624
|
}
|
|
10805
10625
|
if (!args) continue;
|
|
10806
10626
|
const label = `{${token.name} ${args}}`;
|
|
10807
|
-
const
|
|
10808
|
-
const argsAt = token.start + tag.trimEnd().length - args.length;
|
|
10627
|
+
const argsAt = token.argsStart;
|
|
10809
10628
|
if (CONDITION_MACROS.has(name)) {
|
|
10810
10629
|
yield {
|
|
10811
10630
|
kind: "code",
|
|
@@ -10821,8 +10640,95 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
10821
10640
|
}
|
|
10822
10641
|
}
|
|
10823
10642
|
}
|
|
10643
|
+
/**
|
|
10644
|
+
* `codeAndText`, with the markup in the texts read too: a text piece (a label,
|
|
10645
|
+
* an attribute value) with a `{` in it carries its tokens and errors, and is
|
|
10646
|
+
* followed by the pieces of that markup, `nested`, in the offsets of the whole
|
|
10647
|
+
* `src`. In source order, a nested piece after the text it is in.
|
|
10648
|
+
*/
|
|
10649
|
+
function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
|
|
10650
|
+
yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0);
|
|
10651
|
+
}
|
|
10652
|
+
/**
|
|
10653
|
+
* The pieces of `tokens`, the tokens of `src`, which is the text described by
|
|
10654
|
+
* `where` (none for `root`, the markup of the whole passage), and whose
|
|
10655
|
+
* offsets `toRoot` turns into offsets in `root`.
|
|
10656
|
+
*/
|
|
10657
|
+
function* expand(root, src, tokens, parametersOf, options, toRoot, where) {
|
|
10658
|
+
for (const flat of codeAndText(src, tokens, parametersOf)) {
|
|
10659
|
+
const piece = where ? nestedPiece(flat, toRoot, where) : flat;
|
|
10660
|
+
if (flat.kind !== "text" || !flat.text.includes("{")) {
|
|
10661
|
+
yield piece;
|
|
10662
|
+
continue;
|
|
10663
|
+
}
|
|
10664
|
+
const toText = (i) => toRoot(pieceOffset(flat, i));
|
|
10665
|
+
const inner = analyzeMarkup(flat.text, {
|
|
10666
|
+
text: true,
|
|
10667
|
+
hooks: options.isBlock && { isBlock: options.isBlock }
|
|
10668
|
+
});
|
|
10669
|
+
yield {
|
|
10670
|
+
...piece,
|
|
10671
|
+
tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
|
|
10672
|
+
errors: inner.errors.map((e) => {
|
|
10673
|
+
const { line, column } = lineColumn(root, toText(e.offset));
|
|
10674
|
+
return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
|
|
10675
|
+
})
|
|
10676
|
+
};
|
|
10677
|
+
yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where);
|
|
10678
|
+
}
|
|
10679
|
+
}
|
|
10680
|
+
/** `piece`, of a text in another, with its offsets turned by `toRoot`. */
|
|
10681
|
+
function nestedPiece(piece, toRoot, where) {
|
|
10682
|
+
const offset = toRoot(piece.offset);
|
|
10683
|
+
const nested = {
|
|
10684
|
+
offset,
|
|
10685
|
+
nested: true,
|
|
10686
|
+
where
|
|
10687
|
+
};
|
|
10688
|
+
if (piece.kind === "passage" || piece.kind === "argument-error") {
|
|
10689
|
+
const length = toRoot(piece.offset + piece.length) - offset;
|
|
10690
|
+
return {
|
|
10691
|
+
...piece,
|
|
10692
|
+
...nested,
|
|
10693
|
+
length
|
|
10694
|
+
};
|
|
10695
|
+
}
|
|
10696
|
+
const extent = extentOf(piece);
|
|
10697
|
+
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;
|
|
10698
|
+
return sourceOffsets ? {
|
|
10699
|
+
...piece,
|
|
10700
|
+
...nested,
|
|
10701
|
+
sourceOffsets
|
|
10702
|
+
} : {
|
|
10703
|
+
...piece,
|
|
10704
|
+
...nested
|
|
10705
|
+
};
|
|
10706
|
+
}
|
|
10707
|
+
/**
|
|
10708
|
+
* Where each character of `value`, the unescaped text of a quoted string
|
|
10709
|
+
* written as `raw` from `at` on (a backslash before a quote or a backslash
|
|
10710
|
+
* is dropped), is
|
|
10711
|
+
* in the source, and where the text ends. None when the text is where its
|
|
10712
|
+
* length says, or is not that string.
|
|
10713
|
+
*/
|
|
10714
|
+
function escapeOffsets(raw, at, value) {
|
|
10715
|
+
const offsets = [];
|
|
10716
|
+
let escaped = false;
|
|
10717
|
+
let i = 0;
|
|
10718
|
+
while (offsets.length < value.length) {
|
|
10719
|
+
if (i >= raw.length) return void 0;
|
|
10720
|
+
offsets.push(at + i);
|
|
10721
|
+
if (raw[i] === "\\" && /["'\\]/.test(raw.charAt(i + 1))) {
|
|
10722
|
+
escaped = true;
|
|
10723
|
+
i += 2;
|
|
10724
|
+
} else i++;
|
|
10725
|
+
}
|
|
10726
|
+
offsets.push(at + i);
|
|
10727
|
+
return escaped ? offsets : void 0;
|
|
10728
|
+
}
|
|
10824
10729
|
/** The code and text in the arguments `args` (at `offset`) of `macro`. */
|
|
10825
10730
|
function* argPieces(args, offset, params, macro, label) {
|
|
10731
|
+
const name = macro.toLowerCase();
|
|
10826
10732
|
let values;
|
|
10827
10733
|
const spans = /* @__PURE__ */ new Map();
|
|
10828
10734
|
try {
|
|
@@ -10833,11 +10739,12 @@ function* argPieces(args, offset, params, macro, label) {
|
|
|
10833
10739
|
kind: "argument-error",
|
|
10834
10740
|
message: error.message,
|
|
10835
10741
|
offset,
|
|
10836
|
-
|
|
10742
|
+
length: args.length,
|
|
10743
|
+
label,
|
|
10744
|
+
macro: name
|
|
10837
10745
|
};
|
|
10838
10746
|
return;
|
|
10839
10747
|
}
|
|
10840
|
-
const name = macro.toLowerCase();
|
|
10841
10748
|
/** The pieces of the parameters `list`, with their values in `from`. */
|
|
10842
10749
|
function* visit(list, from) {
|
|
10843
10750
|
for (const param of list) {
|
|
@@ -10884,25 +10791,88 @@ function* argPieces(args, offset, params, macro, label) {
|
|
|
10884
10791
|
}
|
|
10885
10792
|
const at = offset + start + (value !== written && /^["']/.test(written) ? 1 : 0);
|
|
10886
10793
|
const holds = stringHolds(param);
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10794
|
+
const sourceOffsets = escapeOffsets(args.slice(at - offset), at, value);
|
|
10795
|
+
if (holds === "expression" || holds === "statements") {
|
|
10796
|
+
const piece = {
|
|
10797
|
+
kind: "code",
|
|
10798
|
+
code: value,
|
|
10799
|
+
offset: at,
|
|
10800
|
+
goal: holds,
|
|
10801
|
+
label,
|
|
10802
|
+
inString: true
|
|
10803
|
+
};
|
|
10804
|
+
if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
|
|
10805
|
+
yield piece;
|
|
10806
|
+
} else if (holds === "passage") yield passage(value);
|
|
10807
|
+
else if (holds === "markup") {
|
|
10808
|
+
const piece = textPiece(value, at, `In the ${param.name} of {${macro}}: `);
|
|
10809
|
+
if (sourceOffsets) piece.sourceOffsets = sourceOffsets;
|
|
10810
|
+
yield piece;
|
|
10811
|
+
}
|
|
10902
10812
|
}
|
|
10903
10813
|
}
|
|
10904
10814
|
yield* [...visit(params, values)].sort((a, b) => a.offset - b.offset);
|
|
10905
10815
|
}
|
|
10816
|
+
/** A text that may hold markup, at `offset`; read when it is expanded. */
|
|
10817
|
+
var textPiece = (text, offset, where) => ({
|
|
10818
|
+
kind: "text",
|
|
10819
|
+
text,
|
|
10820
|
+
offset,
|
|
10821
|
+
where,
|
|
10822
|
+
tokens: [],
|
|
10823
|
+
errors: []
|
|
10824
|
+
});
|
|
10825
|
+
/**
|
|
10826
|
+
* The attributes of an HTML tag by the values as written, with where each
|
|
10827
|
+
* value is: the first of equal names, which is the one in effect. A token
|
|
10828
|
+
* with no spans (made from an AST) has them found in `src`, in order.
|
|
10829
|
+
*/
|
|
10830
|
+
function attributeValues(src, token) {
|
|
10831
|
+
if (token.attributeSpans.length === 0) {
|
|
10832
|
+
let cursor = token.start;
|
|
10833
|
+
return Object.entries(token.attributes).map(([name, value]) => {
|
|
10834
|
+
const at = locate(src, value, cursor);
|
|
10835
|
+
cursor = at + value.length;
|
|
10836
|
+
return {
|
|
10837
|
+
name,
|
|
10838
|
+
value,
|
|
10839
|
+
at
|
|
10840
|
+
};
|
|
10841
|
+
});
|
|
10842
|
+
}
|
|
10843
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10844
|
+
const values = [];
|
|
10845
|
+
for (const span of token.attributeSpans) {
|
|
10846
|
+
const lower = span.name.toLowerCase();
|
|
10847
|
+
if (seen.has(lower)) continue;
|
|
10848
|
+
seen.add(lower);
|
|
10849
|
+
if (span.valueStart === void 0) continue;
|
|
10850
|
+
values.push({
|
|
10851
|
+
name: span.name,
|
|
10852
|
+
value: src.slice(span.valueStart, span.valueEnd),
|
|
10853
|
+
at: span.valueStart
|
|
10854
|
+
});
|
|
10855
|
+
}
|
|
10856
|
+
return values;
|
|
10857
|
+
}
|
|
10858
|
+
/**
|
|
10859
|
+
* The `{$…}` expressions in the value of a code attribute (`onclick`, see
|
|
10860
|
+
* isCodeAttribute), with where each is in the value.
|
|
10861
|
+
*/
|
|
10862
|
+
function sigilExpressions(value) {
|
|
10863
|
+
const found = [];
|
|
10864
|
+
let from = 0;
|
|
10865
|
+
for (const part of splitSigilTemplate(value)) {
|
|
10866
|
+
if (!("expr" in part)) continue;
|
|
10867
|
+
const at = locate(value, part.expr, from);
|
|
10868
|
+
from = at + part.expr.length;
|
|
10869
|
+
found.push({
|
|
10870
|
+
expr: part.expr,
|
|
10871
|
+
at
|
|
10872
|
+
});
|
|
10873
|
+
}
|
|
10874
|
+
return found;
|
|
10875
|
+
}
|
|
10906
10876
|
/**
|
|
10907
10877
|
* Index of `part` in `text` from `from` on, else anywhere, else `from`: the
|
|
10908
10878
|
* place to report an error in `part` at.
|
|
@@ -10913,18 +10883,10 @@ function locate(text, part, from) {
|
|
|
10913
10883
|
const anywhere = text.indexOf(part);
|
|
10914
10884
|
return anywhere >= 0 ? anywhere : from;
|
|
10915
10885
|
}
|
|
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) {
|
|
10886
|
+
/** The passage references among `pieces` (see collectPassageReferences). */
|
|
10887
|
+
function referencesOf(pieces) {
|
|
10926
10888
|
const refs = [];
|
|
10927
|
-
for (const piece of
|
|
10889
|
+
for (const piece of pieces) if (piece.kind === "passage") refs.push({
|
|
10928
10890
|
macro: piece.macro,
|
|
10929
10891
|
target: {
|
|
10930
10892
|
kind: "name",
|
|
@@ -11060,26 +11022,27 @@ function astContainsChildren(nodes, parametersOf = registeredParameters) {
|
|
|
11060
11022
|
for (const node of nodes) {
|
|
11061
11023
|
if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
|
|
11062
11024
|
if (node.type === "html") {
|
|
11063
|
-
const span = {
|
|
11064
|
-
start: 0,
|
|
11065
|
-
end: 0
|
|
11066
|
-
};
|
|
11067
11025
|
if (tokenTextContainsChildren({
|
|
11068
11026
|
isClose: false,
|
|
11069
11027
|
isSelfClose: false,
|
|
11028
|
+
tagNameStart: 0,
|
|
11029
|
+
tagNameEnd: 0,
|
|
11030
|
+
attributeSpans: [],
|
|
11070
11031
|
...node,
|
|
11071
|
-
|
|
11032
|
+
start: 0,
|
|
11033
|
+
end: 0
|
|
11072
11034
|
}, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
|
|
11073
11035
|
}
|
|
11074
11036
|
if (node.type === "macro") {
|
|
11075
|
-
const span = {
|
|
11076
|
-
start: 0,
|
|
11077
|
-
end: 0
|
|
11078
|
-
};
|
|
11079
11037
|
if (tokenTextContainsChildren({
|
|
11080
11038
|
isClose: false,
|
|
11039
|
+
nameStart: 0,
|
|
11040
|
+
nameEnd: 0,
|
|
11041
|
+
argsStart: 0,
|
|
11042
|
+
argsEnd: 0,
|
|
11081
11043
|
...node,
|
|
11082
|
-
|
|
11044
|
+
start: 0,
|
|
11045
|
+
end: 0
|
|
11083
11046
|
}, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
|
|
11084
11047
|
if (node.branches) {
|
|
11085
11048
|
for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf)) return true;
|
|
@@ -11120,37 +11083,70 @@ function widgetDef({ name = "", parameters = "" }) {
|
|
|
11120
11083
|
function parseWidgetDef(rawArgs) {
|
|
11121
11084
|
return widgetDef(parseMacroArgs(rawArgs, WIDGET_PARAMETERS));
|
|
11122
11085
|
}
|
|
11086
|
+
/** Where the name is written in the arguments, without its quotes. */
|
|
11087
|
+
function nameSpan(rawArgs) {
|
|
11088
|
+
const spans = /* @__PURE__ */ new Map();
|
|
11089
|
+
parseMacroArgs(rawArgs, WIDGET_PARAMETERS, spans);
|
|
11090
|
+
const [start, end] = spans.get(WIDGET_PARAMETERS[0]) ?? [0, 0];
|
|
11091
|
+
const quote = rawArgs[start];
|
|
11092
|
+
return (quote === "\"" || quote === "'") && end - start >= 2 ? [start + 1, rawArgs[end - 1] === quote ? end - 1 : end] : [start, end];
|
|
11093
|
+
}
|
|
11123
11094
|
/**
|
|
11124
|
-
* The
|
|
11125
|
-
*
|
|
11126
|
-
*
|
|
11127
|
-
*
|
|
11095
|
+
* The widgets that StoryInit and the passages tagged `widget` define, in
|
|
11096
|
+
* source order: the ones the runtime registers, read tolerantly (a half-typed
|
|
11097
|
+
* definition is still reported, without a `closeStart`). Definitions whose
|
|
11098
|
+
* arguments cannot be read are left out.
|
|
11128
11099
|
*
|
|
11129
11100
|
* The passages are read as flat tokens, which need no block macros to be
|
|
11130
11101
|
* known, so a `{@children}` in an HTML comment or in a `{do}` body is text
|
|
11131
|
-
* here as it is to the parser, and does not make a block widget (#387).
|
|
11102
|
+
* here as it is to the parser, and does not make a block widget (#387). In
|
|
11103
|
+
* nested definitions, it belongs to the innermost.
|
|
11132
11104
|
*/
|
|
11133
|
-
function
|
|
11134
|
-
const
|
|
11105
|
+
function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
|
|
11106
|
+
const found = [];
|
|
11135
11107
|
for (const passage of passages) {
|
|
11136
11108
|
if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
|
|
11137
11109
|
const open = [];
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
continue;
|
|
11145
|
-
}
|
|
11110
|
+
const done = [];
|
|
11111
|
+
for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") if (!token.isClose) open.push({
|
|
11112
|
+
token,
|
|
11113
|
+
isBlock: false
|
|
11114
|
+
});
|
|
11115
|
+
else {
|
|
11146
11116
|
const def = open.pop();
|
|
11147
|
-
if (
|
|
11148
|
-
|
|
11149
|
-
|
|
11150
|
-
}
|
|
11151
|
-
}
|
|
11117
|
+
if (def) done.push({
|
|
11118
|
+
...def,
|
|
11119
|
+
closeStart: token.start
|
|
11120
|
+
});
|
|
11121
|
+
}
|
|
11122
|
+
else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
|
|
11123
|
+
done.push(...open);
|
|
11124
|
+
const defs = [];
|
|
11125
|
+
for (const { token, isBlock, closeStart } of done) try {
|
|
11126
|
+
const [from, to] = nameSpan(token.rawArgs);
|
|
11127
|
+
defs.push({
|
|
11128
|
+
...parseWidgetDef(token.rawArgs),
|
|
11129
|
+
block: isBlock,
|
|
11130
|
+
passage: passage.name,
|
|
11131
|
+
start: token.start,
|
|
11132
|
+
end: token.end,
|
|
11133
|
+
nameStart: token.argsStart + from,
|
|
11134
|
+
nameEnd: token.argsStart + to,
|
|
11135
|
+
...closeStart === void 0 ? {} : { closeStart }
|
|
11136
|
+
});
|
|
11137
|
+
} catch {}
|
|
11138
|
+
found.push(...defs.sort((a, b) => a.start - b.start));
|
|
11152
11139
|
}
|
|
11153
|
-
return
|
|
11140
|
+
return found;
|
|
11141
|
+
}
|
|
11142
|
+
/**
|
|
11143
|
+
* The names of the block widgets (those whose body renders `{@children}`)
|
|
11144
|
+
* that StoryInit and the passages tagged `widget` define, closed. They must
|
|
11145
|
+
* be known as block macros before any passage is parsed, so that passages
|
|
11146
|
+
* invoking them nest their content whatever the passage order.
|
|
11147
|
+
*/
|
|
11148
|
+
function blockWidgetNames(passages, parametersOf = registeredParameters) {
|
|
11149
|
+
return widgetDefinitions$1(passages, parametersOf).filter((def) => def.block && def.closeStart !== void 0).map((def) => def.name);
|
|
11154
11150
|
}
|
|
11155
11151
|
//#endregion
|
|
11156
11152
|
//#region src/markup/validate.ts
|
|
@@ -11170,7 +11166,7 @@ var NOT_MARKUP = new Set([
|
|
|
11170
11166
|
"StoryTransients",
|
|
11171
11167
|
"SaveTitle"
|
|
11172
11168
|
]);
|
|
11173
|
-
var NOT_MARKUP_TAGS = ["script", "stylesheet"];
|
|
11169
|
+
var NOT_MARKUP_TAGS$1 = ["script", "stylesheet"];
|
|
11174
11170
|
/** Branch macros, which their parent macro renders. */
|
|
11175
11171
|
var BRANCH_MACROS = new Set([
|
|
11176
11172
|
"elseif",
|
|
@@ -11194,13 +11190,10 @@ function distance(a, b) {
|
|
|
11194
11190
|
}
|
|
11195
11191
|
return prev[b.length];
|
|
11196
11192
|
}
|
|
11197
|
-
/**
|
|
11198
|
-
|
|
11199
|
-
* `quote`, if one is close.
|
|
11200
|
-
*/
|
|
11201
|
-
function didYouMean(name, names, quote) {
|
|
11193
|
+
/** The known name closest to `name`, if one is close. */
|
|
11194
|
+
function closestName(name, names) {
|
|
11202
11195
|
const lower = name.toLowerCase();
|
|
11203
|
-
let best
|
|
11196
|
+
let best;
|
|
11204
11197
|
let bestDistance = Math.max(2, Math.floor(lower.length / 3)) + 1;
|
|
11205
11198
|
for (const candidate of names) {
|
|
11206
11199
|
const d = distance(lower, candidate.toLowerCase());
|
|
@@ -11209,8 +11202,10 @@ function didYouMean(name, names, quote) {
|
|
|
11209
11202
|
bestDistance = d;
|
|
11210
11203
|
}
|
|
11211
11204
|
}
|
|
11212
|
-
return best
|
|
11205
|
+
return best;
|
|
11213
11206
|
}
|
|
11207
|
+
/** " Did you mean …?" with `best`, written by `quote`, if there is one. */
|
|
11208
|
+
var didYouMean = (best, quote) => best ? ` Did you mean ${quote(best)}?` : "";
|
|
11214
11209
|
/** What a passage argument may be, after an error in one. */
|
|
11215
11210
|
var PASSAGE_ARGUMENT_HINT = " (a passage name is a quoted string or an expression)";
|
|
11216
11211
|
/** A passage argument that is one bare word (`{goto Kitchen}`). */
|
|
@@ -11230,14 +11225,18 @@ function widgetName(rawArgs) {
|
|
|
11230
11225
|
function validateMarkup(passages, options) {
|
|
11231
11226
|
const diagnostics = [];
|
|
11232
11227
|
const hooks = options.isBlockMacro ? { isBlock: options.isBlockMacro } : void 0;
|
|
11233
|
-
const report = (passage,
|
|
11234
|
-
const { line, column } = lineColumn(passage.content,
|
|
11228
|
+
const report = (passage, start, end, code, message, data) => {
|
|
11229
|
+
const { line, column } = lineColumn(passage.content, start);
|
|
11235
11230
|
const d = {
|
|
11236
11231
|
passage: passage.name,
|
|
11237
11232
|
line,
|
|
11238
11233
|
column,
|
|
11239
|
-
message
|
|
11234
|
+
message,
|
|
11235
|
+
code,
|
|
11236
|
+
start,
|
|
11237
|
+
end
|
|
11240
11238
|
};
|
|
11239
|
+
if (data) d.data = data;
|
|
11241
11240
|
const file = passage.metadata?.["data-source-file"];
|
|
11242
11241
|
if (file) {
|
|
11243
11242
|
d.file = file;
|
|
@@ -11246,13 +11245,15 @@ function validateMarkup(passages, options) {
|
|
|
11246
11245
|
}
|
|
11247
11246
|
diagnostics.push(d);
|
|
11248
11247
|
};
|
|
11248
|
+
/** Report malformed markup. */
|
|
11249
|
+
const reportError = (passage, err, where) => report(passage, err.offset, err.end, err.code, where + err.reason, err.data);
|
|
11249
11250
|
const parsed = [];
|
|
11250
11251
|
const widgets = /* @__PURE__ */ new Set();
|
|
11251
11252
|
const passageNames = /* @__PURE__ */ new Set();
|
|
11252
11253
|
for (const passage of passages) {
|
|
11253
11254
|
passageNames.add(passage.name);
|
|
11254
11255
|
if (NOT_MARKUP.has(passage.name)) continue;
|
|
11255
|
-
if (passage.tags?.some((tag) => NOT_MARKUP_TAGS.includes(tag))) continue;
|
|
11256
|
+
if (passage.tags?.some((tag) => NOT_MARKUP_TAGS$1.includes(tag))) continue;
|
|
11256
11257
|
const reported = !options.only || options.only(passage);
|
|
11257
11258
|
try {
|
|
11258
11259
|
const tokens = tokenizeMarkup(passage.content);
|
|
@@ -11267,63 +11268,75 @@ function validateMarkup(passages, options) {
|
|
|
11267
11268
|
parsed.push([passage, tokens]);
|
|
11268
11269
|
} catch (err) {
|
|
11269
11270
|
if (!(err instanceof MarkupError)) throw err;
|
|
11270
|
-
if (reported)
|
|
11271
|
+
if (reported) reportError(passage, err, "");
|
|
11271
11272
|
}
|
|
11272
11273
|
}
|
|
11273
11274
|
const names = [...options.macroNames ?? [], ...widgets];
|
|
11274
|
-
/** Report the unknown macros among `tokens`,
|
|
11275
|
-
const checkMacros = (passage, tokens,
|
|
11275
|
+
/** Report the unknown macros among `tokens`, with `where` in front. */
|
|
11276
|
+
const checkMacros = (passage, tokens, where) => {
|
|
11276
11277
|
for (const token of tokens) {
|
|
11277
11278
|
if (token.type !== "macro" || token.isClose) continue;
|
|
11278
11279
|
const lower = token.name.toLowerCase();
|
|
11279
11280
|
if (BRANCH_MACROS.has(lower) || widgets.has(lower) || options.isKnownMacro(lower)) continue;
|
|
11280
|
-
|
|
11281
|
+
const best = closestName(token.name, names);
|
|
11282
|
+
report(passage, token.start, token.end, "unknown-macro", `${where}Unknown macro {${token.name}}.${didYouMean(best, (n) => `{${n}}`)}`, {
|
|
11283
|
+
name: token.name,
|
|
11284
|
+
suggestions: best ? [best] : []
|
|
11285
|
+
});
|
|
11281
11286
|
}
|
|
11282
11287
|
};
|
|
11283
11288
|
const parametersOf = options.parametersOf ?? (() => void 0);
|
|
11284
11289
|
/**
|
|
11285
|
-
* Check
|
|
11286
|
-
*
|
|
11290
|
+
* Check the pieces of a passage: its macros, the code in them, the passage
|
|
11291
|
+
* names they write out and the markup in their text.
|
|
11287
11292
|
*/
|
|
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);
|
|
11293
|
+
const checkPassage = (passage, tokens) => {
|
|
11294
|
+
checkMacros(passage, tokens, "");
|
|
11295
|
+
let skipTo = 0;
|
|
11296
|
+
for (const piece of passagePiecesOf(passage.content, tokens, parametersOf, { isBlock: options.isBlockMacro })) {
|
|
11297
|
+
if (piece.nested && piece.offset < skipTo) continue;
|
|
11298
|
+
const at = piece.offset;
|
|
11299
|
+
const where = piece.where && piece.nested ? piece.where : "";
|
|
11300
|
+
switch (piece.kind) {
|
|
11301
|
+
case "argument-error":
|
|
11302
|
+
report(passage, at, at + piece.length, "argument-error", `${where}${piece.message} in ${piece.label}`, { macro: piece.macro });
|
|
11303
|
+
break;
|
|
11304
|
+
case "passage":
|
|
11305
|
+
if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
|
|
11306
|
+
const best = closestName(piece.name, passageNames);
|
|
11307
|
+
report(passage, at, at + piece.length, "unknown-passage", `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${didYouMean(best, JSON.stringify)}`, {
|
|
11308
|
+
name: piece.name,
|
|
11309
|
+
macro: piece.macro,
|
|
11310
|
+
suggestions: best ? [best] : []
|
|
11311
|
+
});
|
|
11312
|
+
}
|
|
11313
|
+
break;
|
|
11314
|
+
case "code":
|
|
11315
|
+
checkCode(passage, piece, where);
|
|
11316
|
+
break;
|
|
11317
|
+
case "text": if (piece.errors.length > 0) {
|
|
11318
|
+
reportError(passage, piece.errors[0], piece.where);
|
|
11319
|
+
skipTo = pieceOffset(piece, piece.text.length);
|
|
11320
|
+
} else checkMacros(passage, piece.tokens, piece.where);
|
|
11323
11321
|
}
|
|
11324
11322
|
}
|
|
11325
11323
|
};
|
|
11326
|
-
|
|
11324
|
+
const checkCode = (passage, piece, where) => {
|
|
11325
|
+
const at = piece.offset;
|
|
11326
|
+
const result = parseOrError(piece.code, piece.goal);
|
|
11327
|
+
const code = piece.code.trim();
|
|
11328
|
+
if (result instanceof CodeSyntaxError) {
|
|
11329
|
+
const offending = /^(?:[\w$]+|\S)/.exec(piece.code.slice(result.pos));
|
|
11330
|
+
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);
|
|
11331
|
+
} else if (piece.passage && BARE_WORD_RE.test(code)) {
|
|
11332
|
+
const lead = piece.code.length - piece.code.trimStart().length;
|
|
11333
|
+
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}`, {
|
|
11334
|
+
name: code,
|
|
11335
|
+
macro: piece.macro ?? ""
|
|
11336
|
+
});
|
|
11337
|
+
}
|
|
11338
|
+
};
|
|
11339
|
+
for (const [passage, tokens] of parsed) withParseCache(() => checkPassage(passage, tokens));
|
|
11327
11340
|
return diagnostics;
|
|
11328
11341
|
}
|
|
11329
11342
|
//#endregion
|
|
@@ -11356,16 +11369,284 @@ function ownEntries(sources, keep = () => true) {
|
|
|
11356
11369
|
var createNamespace = (...sources) => ownEntries(sources);
|
|
11357
11370
|
Object.freeze(createNamespace());
|
|
11358
11371
|
//#endregion
|
|
11372
|
+
//#region src/static-literal.ts
|
|
11373
|
+
/**
|
|
11374
|
+
* The shape of a JavaScript literal, read from its text without running it:
|
|
11375
|
+
* what a StoryVariables initializer is when it is a literal, or an array or
|
|
11376
|
+
* object literal of literals (see parseDeclarations in story-variables.ts).
|
|
11377
|
+
*
|
|
11378
|
+
* The reader is deliberately small. Anything it does not recognise (a call,
|
|
11379
|
+
* an operator, a reference, a spread) is "not static", which is no error: the
|
|
11380
|
+
* value is simply not known without running the code.
|
|
11381
|
+
*/
|
|
11382
|
+
var NUMBER_RE = /(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(?:[eE][+-]?\d+)?)(n?)/y;
|
|
11383
|
+
var IDENT_RE = /[A-Za-z_$][\w$]*/y;
|
|
11384
|
+
var ARROW_RE = /(?:async\s+)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*=>/y;
|
|
11385
|
+
/** Read `src`, one literal and nothing else. */
|
|
11386
|
+
function staticLiteral(src) {
|
|
11387
|
+
const reader = new Reader(src);
|
|
11388
|
+
const value = reader.value();
|
|
11389
|
+
reader.space();
|
|
11390
|
+
return reader.i === src.length ? value : void 0;
|
|
11391
|
+
}
|
|
11392
|
+
var Reader = class {
|
|
11393
|
+
constructor(src) {
|
|
11394
|
+
this.src = src;
|
|
11395
|
+
this.i = 0;
|
|
11396
|
+
}
|
|
11397
|
+
/** Skip whitespace and comments. */
|
|
11398
|
+
space() {
|
|
11399
|
+
const { src } = this;
|
|
11400
|
+
for (;;) {
|
|
11401
|
+
while (/\s/.test(src.charAt(this.i))) this.i++;
|
|
11402
|
+
if (src.startsWith("//", this.i)) {
|
|
11403
|
+
const end = src.indexOf("\n", this.i);
|
|
11404
|
+
this.i = end < 0 ? src.length : end;
|
|
11405
|
+
} else if (src.startsWith("/*", this.i)) {
|
|
11406
|
+
const end = src.indexOf("*/", this.i + 2);
|
|
11407
|
+
this.i = end < 0 ? src.length : end + 2;
|
|
11408
|
+
} else return;
|
|
11409
|
+
}
|
|
11410
|
+
}
|
|
11411
|
+
/** The value at the cursor, which is left after it (or anywhere, if not static). */
|
|
11412
|
+
value() {
|
|
11413
|
+
const { src } = this;
|
|
11414
|
+
this.space();
|
|
11415
|
+
const c = src.charAt(this.i);
|
|
11416
|
+
if (c === "\"" || c === "'") return this.string().closed ? { shape: { type: "string" } } : void 0;
|
|
11417
|
+
if (c === "`") return this.template();
|
|
11418
|
+
if (c === "[") return this.skipBalanced() ? { shape: { type: "array" } } : void 0;
|
|
11419
|
+
if (c === "{") return this.object();
|
|
11420
|
+
if (/[\d.+-]/.test(c)) return this.number();
|
|
11421
|
+
if (/[A-Za-z_$(]/.test(c)) return this.word();
|
|
11422
|
+
}
|
|
11423
|
+
/** Skip the string literal at the cursor: its body, and whether it is closed. */
|
|
11424
|
+
string() {
|
|
11425
|
+
const { end, closed } = scanStringLiteral(this.src, this.i);
|
|
11426
|
+
const body = this.src.slice(this.i + 1, closed ? end - 1 : end);
|
|
11427
|
+
this.i = end;
|
|
11428
|
+
return {
|
|
11429
|
+
body,
|
|
11430
|
+
closed
|
|
11431
|
+
};
|
|
11432
|
+
}
|
|
11433
|
+
/** A template literal: a string, but for `${}`. */
|
|
11434
|
+
template() {
|
|
11435
|
+
const { src } = this;
|
|
11436
|
+
for (let i = this.i + 1; i < src.length; i++) {
|
|
11437
|
+
const c = src.charAt(i);
|
|
11438
|
+
if (c === "\\") i++;
|
|
11439
|
+
else if (c === "`") {
|
|
11440
|
+
this.i = i + 1;
|
|
11441
|
+
return { shape: { type: "string" } };
|
|
11442
|
+
} else if (c === "$" && src.charAt(i + 1) === "{") return void 0;
|
|
11443
|
+
}
|
|
11444
|
+
}
|
|
11445
|
+
/** A number, or a sign and one. */
|
|
11446
|
+
number() {
|
|
11447
|
+
const { src } = this;
|
|
11448
|
+
let i = this.i;
|
|
11449
|
+
if (src.charAt(i) === "+" || src.charAt(i) === "-") {
|
|
11450
|
+
i++;
|
|
11451
|
+
while (/\s/.test(src.charAt(i))) i++;
|
|
11452
|
+
}
|
|
11453
|
+
NUMBER_RE.lastIndex = i;
|
|
11454
|
+
const match = NUMBER_RE.exec(src);
|
|
11455
|
+
if (match) {
|
|
11456
|
+
this.i = NUMBER_RE.lastIndex;
|
|
11457
|
+
return match[1] ? { unsupported: "bigint" } : { shape: { type: "number" } };
|
|
11458
|
+
}
|
|
11459
|
+
IDENT_RE.lastIndex = i;
|
|
11460
|
+
if (IDENT_RE.exec(src)?.[0] === "Infinity") {
|
|
11461
|
+
this.i = IDENT_RE.lastIndex;
|
|
11462
|
+
return { shape: { type: "number" } };
|
|
11463
|
+
}
|
|
11464
|
+
}
|
|
11465
|
+
/** A keyword, a function, or a name (which is not static). */
|
|
11466
|
+
word() {
|
|
11467
|
+
const { src } = this;
|
|
11468
|
+
ARROW_RE.lastIndex = this.i;
|
|
11469
|
+
if (ARROW_RE.test(src)) return this.function();
|
|
11470
|
+
IDENT_RE.lastIndex = this.i;
|
|
11471
|
+
const word = IDENT_RE.exec(src)?.[0];
|
|
11472
|
+
if (word === void 0) return void 0;
|
|
11473
|
+
const end = IDENT_RE.lastIndex;
|
|
11474
|
+
switch (word) {
|
|
11475
|
+
case "true":
|
|
11476
|
+
case "false":
|
|
11477
|
+
this.i = end;
|
|
11478
|
+
return { shape: { type: "boolean" } };
|
|
11479
|
+
case "null":
|
|
11480
|
+
this.i = end;
|
|
11481
|
+
return { shape: { type: "null" } };
|
|
11482
|
+
case "NaN":
|
|
11483
|
+
this.i = end;
|
|
11484
|
+
return { shape: { type: "number" } };
|
|
11485
|
+
case "undefined":
|
|
11486
|
+
this.i = end;
|
|
11487
|
+
return { unsupported: "undefined" };
|
|
11488
|
+
case "function":
|
|
11489
|
+
case "class":
|
|
11490
|
+
case "async": return this.function();
|
|
11491
|
+
}
|
|
11492
|
+
}
|
|
11493
|
+
/** A function (or class): the rest is its body, which is not read. */
|
|
11494
|
+
function() {
|
|
11495
|
+
return this.unsupported({ unsupported: "function" });
|
|
11496
|
+
}
|
|
11497
|
+
/** `value`, which makes the whole literal unsupported: the rest is not read. */
|
|
11498
|
+
unsupported(value) {
|
|
11499
|
+
this.i = this.src.length;
|
|
11500
|
+
return value;
|
|
11501
|
+
}
|
|
11502
|
+
/** An object literal: the members that are static. */
|
|
11503
|
+
object() {
|
|
11504
|
+
const { src } = this;
|
|
11505
|
+
const fields = /* @__PURE__ */ new Map();
|
|
11506
|
+
this.i++;
|
|
11507
|
+
for (;;) {
|
|
11508
|
+
this.space();
|
|
11509
|
+
const c = src.charAt(this.i);
|
|
11510
|
+
if (c === "}") {
|
|
11511
|
+
this.i++;
|
|
11512
|
+
return { shape: {
|
|
11513
|
+
type: "object",
|
|
11514
|
+
fields
|
|
11515
|
+
} };
|
|
11516
|
+
}
|
|
11517
|
+
if (c === ",") {
|
|
11518
|
+
this.i++;
|
|
11519
|
+
continue;
|
|
11520
|
+
}
|
|
11521
|
+
if (this.i >= src.length) return void 0;
|
|
11522
|
+
const key = this.key();
|
|
11523
|
+
this.space();
|
|
11524
|
+
if (key !== void 0 && src.charAt(this.i) === ":") {
|
|
11525
|
+
this.i++;
|
|
11526
|
+
const at = this.i;
|
|
11527
|
+
const value = this.value();
|
|
11528
|
+
this.space();
|
|
11529
|
+
if (value && "unsupported" in value) return this.unsupported(value);
|
|
11530
|
+
if (value && ",}".includes(src.charAt(this.i))) {
|
|
11531
|
+
fields.set(key, value.shape);
|
|
11532
|
+
continue;
|
|
11533
|
+
}
|
|
11534
|
+
this.i = at;
|
|
11535
|
+
} else if (key !== void 0 && src.charAt(this.i) === "(") return this.unsupported({ unsupported: "function" });
|
|
11536
|
+
if (!this.skipMember()) return void 0;
|
|
11537
|
+
}
|
|
11538
|
+
}
|
|
11539
|
+
/** The key of a member (a name, a string or a number), if it has one. */
|
|
11540
|
+
key() {
|
|
11541
|
+
const { src } = this;
|
|
11542
|
+
const c = src.charAt(this.i);
|
|
11543
|
+
if (c === "\"" || c === "'") {
|
|
11544
|
+
const { body, closed } = this.string();
|
|
11545
|
+
return closed ? body : void 0;
|
|
11546
|
+
}
|
|
11547
|
+
const word = /[\w$]+/y;
|
|
11548
|
+
word.lastIndex = this.i;
|
|
11549
|
+
const found = word.exec(src)?.[0];
|
|
11550
|
+
if (found === void 0) return void 0;
|
|
11551
|
+
this.i = word.lastIndex;
|
|
11552
|
+
return found;
|
|
11553
|
+
}
|
|
11554
|
+
/** Skip to the `,` or `}` that ends a member, balancing what is inside. */
|
|
11555
|
+
skipMember() {
|
|
11556
|
+
const { src } = this;
|
|
11557
|
+
while (this.i < src.length) {
|
|
11558
|
+
const c = src.charAt(this.i);
|
|
11559
|
+
if (c === "," || c === "}") return true;
|
|
11560
|
+
if (!this.skipOne()) return false;
|
|
11561
|
+
}
|
|
11562
|
+
return false;
|
|
11563
|
+
}
|
|
11564
|
+
/** Skip an array literal (or any bracketed group) at the cursor. */
|
|
11565
|
+
skipBalanced() {
|
|
11566
|
+
const { src } = this;
|
|
11567
|
+
const close = {
|
|
11568
|
+
"[": "]",
|
|
11569
|
+
"{": "}",
|
|
11570
|
+
"(": ")"
|
|
11571
|
+
}[src.charAt(this.i)];
|
|
11572
|
+
if (!close) return false;
|
|
11573
|
+
this.i++;
|
|
11574
|
+
while (this.i < src.length) {
|
|
11575
|
+
if (src.charAt(this.i) === close) {
|
|
11576
|
+
this.i++;
|
|
11577
|
+
return true;
|
|
11578
|
+
}
|
|
11579
|
+
if (!this.skipOne()) return false;
|
|
11580
|
+
}
|
|
11581
|
+
return false;
|
|
11582
|
+
}
|
|
11583
|
+
/** Skip one character, or one string, template, comment or group. */
|
|
11584
|
+
skipOne() {
|
|
11585
|
+
const { src } = this;
|
|
11586
|
+
const c = src.charAt(this.i);
|
|
11587
|
+
if (c === "\"" || c === "'") return this.string().closed;
|
|
11588
|
+
if (c === "`") return this.skipTemplate();
|
|
11589
|
+
if (src.startsWith("//", this.i) || src.startsWith("/*", this.i)) {
|
|
11590
|
+
this.space();
|
|
11591
|
+
return true;
|
|
11592
|
+
}
|
|
11593
|
+
if (c === "[" || c === "{" || c === "(") return this.skipBalanced();
|
|
11594
|
+
if (c === "]" || c === "}" || c === ")") return false;
|
|
11595
|
+
this.i++;
|
|
11596
|
+
return true;
|
|
11597
|
+
}
|
|
11598
|
+
/** Skip a template literal, with the expressions in it. */
|
|
11599
|
+
skipTemplate() {
|
|
11600
|
+
const { src } = this;
|
|
11601
|
+
this.i++;
|
|
11602
|
+
while (this.i < src.length) {
|
|
11603
|
+
const c = src.charAt(this.i);
|
|
11604
|
+
if (c === "\\") this.i += 2;
|
|
11605
|
+
else if (c === "`") {
|
|
11606
|
+
this.i++;
|
|
11607
|
+
return true;
|
|
11608
|
+
} else if (c === "$" && src.charAt(this.i + 1) === "{") {
|
|
11609
|
+
this.i++;
|
|
11610
|
+
if (!this.skipBalanced()) return false;
|
|
11611
|
+
} else this.i++;
|
|
11612
|
+
}
|
|
11613
|
+
return false;
|
|
11614
|
+
}
|
|
11615
|
+
};
|
|
11616
|
+
//#endregion
|
|
11359
11617
|
//#region src/story-variables.ts
|
|
11618
|
+
/**
|
|
11619
|
+
* The tokens of markup, or none if it is malformed (validateMarkup reports
|
|
11620
|
+
* that, with its position); in tolerant mode, those of the well-formed parts.
|
|
11621
|
+
*/
|
|
11622
|
+
function tokensOf(text, textMode, { tolerant } = {}) {
|
|
11623
|
+
if (tolerant) return tokenizeMarkupTolerant(text, { text: textMode }).tokens;
|
|
11624
|
+
try {
|
|
11625
|
+
return tokenizeMarkup(text, { text: textMode });
|
|
11626
|
+
} catch (err) {
|
|
11627
|
+
if (err instanceof MarkupError) return [];
|
|
11628
|
+
throw err;
|
|
11629
|
+
}
|
|
11630
|
+
}
|
|
11360
11631
|
function declarationRegex(sigil) {
|
|
11361
11632
|
const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11362
11633
|
return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
|
|
11363
11634
|
}
|
|
11635
|
+
/** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
|
|
11636
|
+
var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
|
|
11637
|
+
/** Quoted first argument of an input macro naming a story variable. */
|
|
11638
|
+
var QUOTED_VAR_ARG_RE = /^["']\$(\w+(?:\.\w+)*)["']?$/;
|
|
11364
11639
|
var VALID_VAR_TYPES = new Set([
|
|
11365
11640
|
"number",
|
|
11366
11641
|
"string",
|
|
11367
11642
|
"boolean"
|
|
11368
11643
|
]);
|
|
11644
|
+
/** Boxed sample values whose members a primitive of each type can access. */
|
|
11645
|
+
var PRIMITIVE_SAMPLES = {
|
|
11646
|
+
string: Object(""),
|
|
11647
|
+
number: Object(0),
|
|
11648
|
+
boolean: Object(false)
|
|
11649
|
+
};
|
|
11369
11650
|
/**
|
|
11370
11651
|
* The schema of a default value. An object met again (a backreference, a
|
|
11371
11652
|
* shared subtree) has the schema made for it the first time, so a cyclic
|
|
@@ -11390,22 +11671,101 @@ function inferSchema(value, seen = /* @__PURE__ */ new Map()) {
|
|
|
11390
11671
|
if (!VALID_VAR_TYPES.has(jsType)) throw new Error(`Unsupported type "${jsType}" for value ${String(value)}. Expected number, string, boolean, array, or object.`);
|
|
11391
11672
|
return { type: jsType };
|
|
11392
11673
|
}
|
|
11674
|
+
var UNSUPPORTED_TYPE = "Expected number, string, boolean, array, or object.";
|
|
11675
|
+
/** The schema of a literal shape (see staticLiteral). */
|
|
11676
|
+
function shapeSchema(shape) {
|
|
11677
|
+
if (!shape.fields) return { type: shape.type };
|
|
11678
|
+
const fields = /* @__PURE__ */ new Map();
|
|
11679
|
+
for (const [key, member] of shape.fields) fields.set(key, shapeSchema(member));
|
|
11680
|
+
return {
|
|
11681
|
+
type: shape.type,
|
|
11682
|
+
fields
|
|
11683
|
+
};
|
|
11684
|
+
}
|
|
11393
11685
|
/**
|
|
11394
|
-
*
|
|
11395
|
-
*
|
|
11686
|
+
* Read the declarations of a StoryVariables (`$name = value`) or
|
|
11687
|
+
* StoryTransients (`%name = value`) passage, without evaluating them and
|
|
11688
|
+
* without throwing: every valid declaration, and every invalid line as an
|
|
11689
|
+
* error. It is the grammar parseStoryVariables reads with.
|
|
11690
|
+
*
|
|
11691
|
+
* A declaration is a line of the form `$name = expression`; blank lines are
|
|
11692
|
+
* skipped. A line that is not, and a name that cannot be a variable, are
|
|
11693
|
+
* errors. So is an initializer that no variable can hold (a function,
|
|
11694
|
+
* `undefined`), when it is a literal; whether any other initializer can only
|
|
11695
|
+
* be known by running it. A name declared again is an error too, but both
|
|
11696
|
+
* declarations are returned (the later wins when evaluated).
|
|
11396
11697
|
*/
|
|
11397
|
-
function
|
|
11398
|
-
const
|
|
11698
|
+
function parseDeclarations(content, sigil = "$") {
|
|
11699
|
+
const declarations = [];
|
|
11700
|
+
const errors = [];
|
|
11399
11701
|
const DECLARATION_RE = declarationRegex(sigil);
|
|
11400
|
-
const
|
|
11702
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11703
|
+
let lineStart = 0;
|
|
11401
11704
|
for (const rawLine of content.split("\n")) {
|
|
11705
|
+
const at = lineStart + rawLine.length - rawLine.trimStart().length;
|
|
11706
|
+
lineStart += rawLine.length + 1;
|
|
11402
11707
|
const line = rawLine.trim();
|
|
11403
11708
|
if (!line) continue;
|
|
11404
11709
|
const match = line.match(DECLARATION_RE);
|
|
11405
|
-
|
|
11710
|
+
const error = (code, start, end, message) => errors.push({
|
|
11711
|
+
code,
|
|
11712
|
+
offset: start,
|
|
11713
|
+
end,
|
|
11714
|
+
message
|
|
11715
|
+
});
|
|
11716
|
+
if (!match) {
|
|
11717
|
+
error("invalid-declaration", at, at + line.length, `Invalid declaration: "${line}". Expected: ${sigil}name = value`);
|
|
11718
|
+
continue;
|
|
11719
|
+
}
|
|
11406
11720
|
const [, name, expr] = match;
|
|
11721
|
+
const nameStart = at + sigil.length;
|
|
11722
|
+
const nameEnd = nameStart + name.length;
|
|
11407
11723
|
const nameError = variableNameError(name, sigil + name);
|
|
11408
|
-
if (nameError)
|
|
11724
|
+
if (nameError) {
|
|
11725
|
+
error("invalid-name", nameStart, nameEnd, nameError);
|
|
11726
|
+
continue;
|
|
11727
|
+
}
|
|
11728
|
+
const valueEnd = at + line.length;
|
|
11729
|
+
const declaration = {
|
|
11730
|
+
name,
|
|
11731
|
+
nameStart,
|
|
11732
|
+
nameEnd,
|
|
11733
|
+
valueStart: valueEnd - expr.length,
|
|
11734
|
+
valueEnd
|
|
11735
|
+
};
|
|
11736
|
+
if (seen.has(name)) error("duplicate-declaration", nameStart, nameEnd, `Duplicate declaration of ${sigil}${name}`);
|
|
11737
|
+
seen.add(name);
|
|
11738
|
+
const literal = staticLiteral(expr);
|
|
11739
|
+
if (literal && "shape" in literal) declaration.schema = shapeSchema(literal.shape);
|
|
11740
|
+
else if (literal) error("unsupported-value", declaration.valueStart, valueEnd, `Unsupported type "${literal.unsupported}" for value ${expr}. ${UNSUPPORTED_TYPE}`);
|
|
11741
|
+
declarations.push(declaration);
|
|
11742
|
+
}
|
|
11743
|
+
return {
|
|
11744
|
+
declarations,
|
|
11745
|
+
errors
|
|
11746
|
+
};
|
|
11747
|
+
}
|
|
11748
|
+
/**
|
|
11749
|
+
* Parse a StoryVariables or StoryTransients passage content into a schema map.
|
|
11750
|
+
* Each line: `$varName = expression` (or `%varName = expression` for transients)
|
|
11751
|
+
* The expressions are evaluated; parseDeclarations reads the same lines
|
|
11752
|
+
* without.
|
|
11753
|
+
*/
|
|
11754
|
+
function parseStoryVariables(content, sigil = "$") {
|
|
11755
|
+
const schema = /* @__PURE__ */ new Map();
|
|
11756
|
+
const passageName = sigil === "%" ? "StoryTransients" : "StoryVariables";
|
|
11757
|
+
const { declarations, errors } = parseDeclarations(content, sigil);
|
|
11758
|
+
const lines = [...errors.filter((e) => e.code === "invalid-declaration" || e.code === "invalid-name").map((e) => ({
|
|
11759
|
+
at: e.offset,
|
|
11760
|
+
error: e
|
|
11761
|
+
})), ...declarations.map((d) => ({
|
|
11762
|
+
at: d.nameStart,
|
|
11763
|
+
declaration: d
|
|
11764
|
+
}))].sort((a, b) => a.at - b.at);
|
|
11765
|
+
for (const line of lines) {
|
|
11766
|
+
if ("error" in line) throw new Error(`${passageName}: ${line.error.message}`);
|
|
11767
|
+
const { name, valueStart, valueEnd } = line.declaration;
|
|
11768
|
+
const expr = content.slice(valueStart, valueEnd);
|
|
11409
11769
|
let value;
|
|
11410
11770
|
try {
|
|
11411
11771
|
value = new Function("return (" + expr + ")")();
|
|
@@ -11426,6 +11786,240 @@ function parseStoryVariables(content, sigil = "$") {
|
|
|
11426
11786
|
}
|
|
11427
11787
|
return schema;
|
|
11428
11788
|
}
|
|
11789
|
+
/**
|
|
11790
|
+
* Check a reference against the declarations: the error code and message, or
|
|
11791
|
+
* null if it is valid. (Unknown fields of objects are valid: classes
|
|
11792
|
+
* registered with Story.registerClass() can add members that are not in the
|
|
11793
|
+
* defaults.)
|
|
11794
|
+
*/
|
|
11795
|
+
function checkReference(ref, declared) {
|
|
11796
|
+
const label = (path) => ref.sigil + [ref.name, ...path].join(".");
|
|
11797
|
+
const nameError = variableNameError(ref.name, ref.sigil + ref.name);
|
|
11798
|
+
if (nameError) return {
|
|
11799
|
+
code: "reserved-name",
|
|
11800
|
+
message: nameError
|
|
11801
|
+
};
|
|
11802
|
+
const schema = ref.sigil === "$" ? declared.variables : declared.transients;
|
|
11803
|
+
if (!schema) return null;
|
|
11804
|
+
if (!schema.has(ref.name)) return ref.sigil === "$" ? {
|
|
11805
|
+
code: "undeclared-variable",
|
|
11806
|
+
message: `Undeclared variable: ${label(ref.path)}`
|
|
11807
|
+
} : {
|
|
11808
|
+
code: "undeclared-transient",
|
|
11809
|
+
message: `Undeclared transient: ${label(ref.path)}`
|
|
11810
|
+
};
|
|
11811
|
+
let current = schema.get(ref.name);
|
|
11812
|
+
for (let i = 0; current && i < ref.path.length; i++) {
|
|
11813
|
+
const part = ref.path[i];
|
|
11814
|
+
if (current.type === "array") return null;
|
|
11815
|
+
if (current.type === "null") return null;
|
|
11816
|
+
const sample = PRIMITIVE_SAMPLES[current.type];
|
|
11817
|
+
if (sample && part in sample) {
|
|
11818
|
+
const memberType = typeof sample[part];
|
|
11819
|
+
if (!VALID_VAR_TYPES.has(memberType)) return null;
|
|
11820
|
+
current = { type: memberType };
|
|
11821
|
+
continue;
|
|
11822
|
+
}
|
|
11823
|
+
if (current.type !== "object" || !current.fields) return {
|
|
11824
|
+
code: "primitive-field",
|
|
11825
|
+
message: `Cannot access field "${part}" on ${label(ref.path.slice(0, i))} (type: ${current.type})`
|
|
11826
|
+
};
|
|
11827
|
+
current = current.fields.get(part);
|
|
11828
|
+
}
|
|
11829
|
+
return null;
|
|
11830
|
+
}
|
|
11831
|
+
var NO_STORE_VAR_MACROS = /* @__PURE__ */ new Set();
|
|
11832
|
+
/** A reference written at `index` of `code`, with its dot path. */
|
|
11833
|
+
function referenceAt(code, index, at) {
|
|
11834
|
+
VAR_PATH_RE.lastIndex = index;
|
|
11835
|
+
const match = VAR_PATH_RE.exec(code);
|
|
11836
|
+
if (!match) return void 0;
|
|
11837
|
+
const [name, ...path] = match[2].split(".");
|
|
11838
|
+
return {
|
|
11839
|
+
sigil: match[1],
|
|
11840
|
+
name,
|
|
11841
|
+
path,
|
|
11842
|
+
start: at(index),
|
|
11843
|
+
end: at(index + match[0].length)
|
|
11844
|
+
};
|
|
11845
|
+
}
|
|
11846
|
+
/**
|
|
11847
|
+
* Scan the value of a code attribute (`onclick`, see isCodeAttribute) for
|
|
11848
|
+
* the `{$…}` references resolved in it; its other braces are code. `at` is
|
|
11849
|
+
* where the value is.
|
|
11850
|
+
*/
|
|
11851
|
+
function scanSigilReferences(value, at, emit) {
|
|
11852
|
+
for (const { expr, at: k } of sigilExpressions(value)) scanCode(expr, (i) => at(k + i), emit);
|
|
11853
|
+
}
|
|
11854
|
+
/**
|
|
11855
|
+
* Scan literal text (string contents, HTML attribute values) for the markup
|
|
11856
|
+
* that labels and HTML attributes evaluate at runtime: `{$…}` displays,
|
|
11857
|
+
* expressions and macros, read as in passage text. A bare `$word` in
|
|
11858
|
+
* literal text is not a reference.
|
|
11859
|
+
*/
|
|
11860
|
+
function scanInterpolations(text, at, emit, options) {
|
|
11861
|
+
if (!text.includes("{")) return;
|
|
11862
|
+
collectTokenRefs(text, tokensOf(text, true, options), at, emit, options);
|
|
11863
|
+
}
|
|
11864
|
+
/**
|
|
11865
|
+
* Report `$var` references in JavaScript code, lexed as the expression
|
|
11866
|
+
* engine lexes it (`lexJs`): references in code, but none inside string or
|
|
11867
|
+
* regex literals or comments, nor property names (`a.$b`, `{ $b: 1 }`).
|
|
11868
|
+
* The text of string and template literals is not scanned: a string in code
|
|
11869
|
+
* is literal text unless a macro argument that holds markup is read as such
|
|
11870
|
+
* (see scanArgs); the `${…}` parts of template literals are code.
|
|
11871
|
+
*/
|
|
11872
|
+
function scanCode(code, at, emit, goal = "expression") {
|
|
11873
|
+
const parsed = parseOrError(code, goal);
|
|
11874
|
+
if (parsed instanceof CodeSyntaxError) {
|
|
11875
|
+
scanCodeLeniently(code, at, emit, goal);
|
|
11876
|
+
return;
|
|
11877
|
+
}
|
|
11878
|
+
for (const ref of parsed.refs) {
|
|
11879
|
+
if (ref.sigil !== "$" && ref.sigil !== "%") continue;
|
|
11880
|
+
const found = referenceAt(code, ref.start, at);
|
|
11881
|
+
if (found) emit(found);
|
|
11882
|
+
}
|
|
11883
|
+
}
|
|
11884
|
+
/** `scanCode` for code acorn can't parse: lexed leniently. */
|
|
11885
|
+
function scanCodeLeniently(code, at, emit, goal) {
|
|
11886
|
+
lexJs(code, {
|
|
11887
|
+
variable(sigil, _name, index) {
|
|
11888
|
+
if (sigil !== "$" && sigil !== "%") return;
|
|
11889
|
+
const found = referenceAt(code, index, at);
|
|
11890
|
+
if (found) emit(found);
|
|
11891
|
+
},
|
|
11892
|
+
literal() {}
|
|
11893
|
+
}, goal);
|
|
11894
|
+
}
|
|
11895
|
+
/**
|
|
11896
|
+
* Report the references in the arguments of a macro by what its parameters
|
|
11897
|
+
* say each holds (see ParameterDef.holds): code is scanned as code and
|
|
11898
|
+
* markup as markup, but literal text (a placeholder, a passage name) holds
|
|
11899
|
+
* none. A macro without declared parameters, or arguments that do not
|
|
11900
|
+
* parse, are scanned as code.
|
|
11901
|
+
*/
|
|
11902
|
+
function scanArgs(token, params, at, emit, options) {
|
|
11903
|
+
if (!token.rawArgs) return;
|
|
11904
|
+
if (params) {
|
|
11905
|
+
const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
|
|
11906
|
+
if (!pieces.some((piece) => piece.kind === "argument-error")) {
|
|
11907
|
+
for (const piece of pieces) {
|
|
11908
|
+
const pieceAt = (i) => at(pieceOffset(piece, i));
|
|
11909
|
+
if (piece.kind === "code") scanCode(piece.code, pieceAt, emit, piece.goal);
|
|
11910
|
+
else if (piece.kind === "text") scanInterpolations(piece.text, pieceAt, emit, {
|
|
11911
|
+
...options,
|
|
11912
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11913
|
+
});
|
|
11914
|
+
}
|
|
11915
|
+
return;
|
|
11916
|
+
}
|
|
11917
|
+
}
|
|
11918
|
+
scanCode(token.rawArgs, (i) => at(token.argsStart + i), emit);
|
|
11919
|
+
}
|
|
11920
|
+
/** Report the `$var` references in the tokens of `content`. */
|
|
11921
|
+
function collectTokenRefs(content, tokens, at, emit, options) {
|
|
11922
|
+
const { storeVarMacros, parametersOf } = options;
|
|
11923
|
+
for (let t = 0; t < tokens.length; t++) {
|
|
11924
|
+
const token = tokens[t];
|
|
11925
|
+
if (token.type === "variable") {
|
|
11926
|
+
if ((token.scope === "variable" || token.scope === "transient") && token.name) {
|
|
11927
|
+
const [name, ...path] = token.name.split(".");
|
|
11928
|
+
emit({
|
|
11929
|
+
sigil: token.scope === "variable" ? "$" : "%",
|
|
11930
|
+
name,
|
|
11931
|
+
path,
|
|
11932
|
+
start: at(token.nameStart - 1),
|
|
11933
|
+
end: at(token.nameEnd)
|
|
11934
|
+
});
|
|
11935
|
+
}
|
|
11936
|
+
} else if (token.type === "link") scanInterpolations(token.display, (i) => at(token.displayStart + i), emit, {
|
|
11937
|
+
...options,
|
|
11938
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11939
|
+
});
|
|
11940
|
+
else if (token.type === "expression") scanCode(token.expression, (i) => at(token.expressionStart + i), emit);
|
|
11941
|
+
else if (token.type === "html") for (const { name, value, at: valueAt } of attributeValues(content, token)) {
|
|
11942
|
+
const valueIn = (i) => at(valueAt + i);
|
|
11943
|
+
if (isCodeAttribute(name)) scanSigilReferences(value, valueIn, emit);
|
|
11944
|
+
else scanInterpolations(value, valueIn, emit, options);
|
|
11945
|
+
}
|
|
11946
|
+
else if (token.type === "macro" && !token.isClose) {
|
|
11947
|
+
scanArgs(token, parametersOf(token.name), at, emit, options);
|
|
11948
|
+
if (token.selectorsStart !== void 0 && token.selectorsEnd !== void 0) {
|
|
11949
|
+
const from = token.selectorsStart;
|
|
11950
|
+
scanInterpolations(content.slice(from, token.selectorsEnd), (i) => at(from + i), emit, {
|
|
11951
|
+
...options,
|
|
11952
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11953
|
+
});
|
|
11954
|
+
}
|
|
11955
|
+
if (storeVarMacros.has(token.name.toLowerCase())) {
|
|
11956
|
+
const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
|
|
11957
|
+
const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
|
|
11958
|
+
const quoted = QUOTED_VAR_ARG_RE.exec(first);
|
|
11959
|
+
if (quoted) {
|
|
11960
|
+
const [name, ...path] = quoted[1].split(".");
|
|
11961
|
+
const start = token.argsStart + lead + 1;
|
|
11962
|
+
emit({
|
|
11963
|
+
sigil: "$",
|
|
11964
|
+
name,
|
|
11965
|
+
path,
|
|
11966
|
+
start: at(start),
|
|
11967
|
+
end: at(start + 1 + quoted[1].length)
|
|
11968
|
+
});
|
|
11969
|
+
} else if (!/^["'`]/.test(first)) scanCode(first, (i) => at(token.argsStart + lead + i), emit);
|
|
11970
|
+
}
|
|
11971
|
+
if (token.name.toLowerCase() === "do") {
|
|
11972
|
+
let close = t + 1;
|
|
11973
|
+
while (close < tokens.length) {
|
|
11974
|
+
const c = tokens[close];
|
|
11975
|
+
if (c.type === "macro" && c.isClose && c.name.toLowerCase() === "do") break;
|
|
11976
|
+
close++;
|
|
11977
|
+
}
|
|
11978
|
+
if (close < tokens.length) {
|
|
11979
|
+
scanCode(content.slice(token.end, tokens[close].start), (i) => at(token.end + i), emit, "statements");
|
|
11980
|
+
t = close;
|
|
11981
|
+
}
|
|
11982
|
+
}
|
|
11983
|
+
}
|
|
11984
|
+
}
|
|
11985
|
+
}
|
|
11986
|
+
/**
|
|
11987
|
+
* The `$` and `%` variable references a passage evaluates at runtime, in
|
|
11988
|
+
* source order: `{$var}` displays, `{$expr}` expressions, macro arguments and
|
|
11989
|
+
* `{do}` bodies (as code), quoted variable names bound by input macros, and
|
|
11990
|
+
* `{$…}` interpolations in labels and HTML attributes. Prose is literal text
|
|
11991
|
+
* and not scanned.
|
|
11992
|
+
*/
|
|
11993
|
+
function collectVariableReferences(content, options) {
|
|
11994
|
+
const found = [];
|
|
11995
|
+
withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), options));
|
|
11996
|
+
return found;
|
|
11997
|
+
}
|
|
11998
|
+
/**
|
|
11999
|
+
* The invalid variable references of the passages, against what is declared,
|
|
12000
|
+
* with their positions. The passages that hold no markup (the declarations
|
|
12001
|
+
* themselves, SaveTitle) are skipped.
|
|
12002
|
+
*/
|
|
12003
|
+
function checkVariableReferences(passages, declared, options) {
|
|
12004
|
+
const diagnostics = [];
|
|
12005
|
+
for (const passage of passages) {
|
|
12006
|
+
if (NOT_MARKUP.has(passage.name)) continue;
|
|
12007
|
+
for (const ref of collectVariableReferences(passage.content, options)) {
|
|
12008
|
+
const error = checkReference(ref, declared);
|
|
12009
|
+
if (!error) continue;
|
|
12010
|
+
diagnostics.push({
|
|
12011
|
+
passage: passage.name,
|
|
12012
|
+
code: error.code,
|
|
12013
|
+
name: ref.name,
|
|
12014
|
+
...ref.path.length > 0 ? { path: ref.path } : {},
|
|
12015
|
+
start: ref.start,
|
|
12016
|
+
end: ref.end,
|
|
12017
|
+
message: error.message
|
|
12018
|
+
});
|
|
12019
|
+
}
|
|
12020
|
+
}
|
|
12021
|
+
return diagnostics;
|
|
12022
|
+
}
|
|
11429
12023
|
//#endregion
|
|
11430
12024
|
//#region src/components/macros/include-args.ts
|
|
11431
12025
|
/**
|
|
@@ -11538,14 +12132,79 @@ function validateStoryMarkup(passages, macros, options = {}) {
|
|
|
11538
12132
|
checkPassageNames: options.checkPassageNames
|
|
11539
12133
|
});
|
|
11540
12134
|
}
|
|
12135
|
+
/** Whether a macro takes a body, among `macros` and the built-in ones. */
|
|
12136
|
+
function blockLookup(macros) {
|
|
12137
|
+
const blocks = new Set(macros.filter((m) => m.block).map((m) => m.name.toLowerCase()));
|
|
12138
|
+
return (name) => blocks.has(name.toLowerCase()) || isBlockMacro(name);
|
|
12139
|
+
}
|
|
12140
|
+
/**
|
|
12141
|
+
* What a passage's markup runs and names, and where: the pieces of code
|
|
12142
|
+
* (`{$expr}` displays, `{do}` bodies, conditions, macro arguments by their
|
|
12143
|
+
* declared parameter types, strings that hold code), the passage names written
|
|
12144
|
+
* out (links, `passage` arguments), the texts that hold markup of their own
|
|
12145
|
+
* (labels, attribute values) and the arguments that don't have their
|
|
12146
|
+
* parameters' forms, in source order with offsets (UTF-16) into `source`. The
|
|
12147
|
+
* markup in a text follows it, as pieces marked `nested` with offsets into
|
|
12148
|
+
* `source` too. Malformed tags are skipped, so it reads half-typed markup.
|
|
12149
|
+
* The macros are those the markup may use, built-in and user-defined.
|
|
12150
|
+
*/
|
|
12151
|
+
function passagePieces(source, macros = []) {
|
|
12152
|
+
const all = [...macros];
|
|
12153
|
+
const { tokens } = tokenizeMarkupTolerant(source);
|
|
12154
|
+
return [...passagePiecesOf(source, tokens, parameterLookup(all), { isBlock: blockLookup(all) })];
|
|
12155
|
+
}
|
|
11541
12156
|
/**
|
|
11542
12157
|
* The passages the markup of `source` names (see PassageReference), against
|
|
11543
12158
|
* the given macros: what the story-start check looks up. Malformed tags are
|
|
11544
|
-
* skipped, so it reads half-typed markup.
|
|
12159
|
+
* skipped, so it reads half-typed markup. It is `passagePieces`, less what
|
|
12160
|
+
* names no passage.
|
|
11545
12161
|
*/
|
|
11546
12162
|
function collectStoryPassageReferences(source, macros) {
|
|
11547
|
-
|
|
11548
|
-
|
|
12163
|
+
return referencesOf(passagePieces(source, macros));
|
|
12164
|
+
}
|
|
12165
|
+
/**
|
|
12166
|
+
* The widgets the story defines, as the runtime reads them: those of
|
|
12167
|
+
* StoryInit and of the passages tagged `widget`, with their parameters,
|
|
12168
|
+
* whether their body renders `{@children}` (a block widget) and where they
|
|
12169
|
+
* are written, in source order. Half-typed definitions are reported without a
|
|
12170
|
+
* `closeStart`. The macros are those the markup may use, built-in and
|
|
12171
|
+
* user-defined (a `{@children}` in an attribute or label counts).
|
|
12172
|
+
*/
|
|
12173
|
+
function widgetDefinitions(passages, macros = []) {
|
|
12174
|
+
return widgetDefinitions$1(passages, parameterLookup([...macros]));
|
|
12175
|
+
}
|
|
12176
|
+
/** Passages tagged so hold code or styles, not markup. */
|
|
12177
|
+
var NOT_MARKUP_TAGS = ["script", "stylesheet"];
|
|
12178
|
+
/** What reading the variable references of markup depends on. */
|
|
12179
|
+
function referenceOptions(macros) {
|
|
12180
|
+
const all = [...macros];
|
|
12181
|
+
return {
|
|
12182
|
+
storeVarMacros: new Set(all.filter((m) => m.storeVar).map((m) => m.name.toLowerCase())),
|
|
12183
|
+
parametersOf: parameterLookup(all),
|
|
12184
|
+
tolerant: true
|
|
12185
|
+
};
|
|
12186
|
+
}
|
|
12187
|
+
/**
|
|
12188
|
+
* The `$` and `%` variable references that the markup of a passage evaluates,
|
|
12189
|
+
* in source order, with the dotted path of fields accessed and where each is
|
|
12190
|
+
* written (offsets into `source`, UTF-16): `{$var}` displays, code in
|
|
12191
|
+
* expressions, conditions, `{do}` bodies and macro arguments, quoted names
|
|
12192
|
+
* bound by input macros, and the markup in labels and HTML attributes. Prose
|
|
12193
|
+
* is literal text. Malformed tags are skipped, so it reads half-typed markup.
|
|
12194
|
+
* The macros are those the markup may use, built-in and user-defined.
|
|
12195
|
+
*/
|
|
12196
|
+
function variableReferences(source, macros = []) {
|
|
12197
|
+
return collectVariableReferences(source, referenceOptions(macros));
|
|
12198
|
+
}
|
|
12199
|
+
/**
|
|
12200
|
+
* The variable references of the passages' markup that are not valid against
|
|
12201
|
+
* the declarations, as the story start checks them: a variable (or, when
|
|
12202
|
+
* `transients` is given, a transient) that is not declared, and a field of a
|
|
12203
|
+
* primitive that it has no member of. Built on `variableReferences`:
|
|
12204
|
+
* tolerant of half-typed markup, and it evaluates no project code.
|
|
12205
|
+
*/
|
|
12206
|
+
function validateVariableReferences(passages, declarations, macros = []) {
|
|
12207
|
+
return checkVariableReferences([...passages].filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros));
|
|
11549
12208
|
}
|
|
11550
12209
|
//#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 };
|
|
12210
|
+
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, isBlockMacro, isSigil, lexJs, lexTemplate, pairMarkup, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|