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