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