links-notation 0.11.2 → 0.13.0
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/.eslintrc.json +28 -0
- package/.prettierignore +4 -0
- package/.prettierrc +4 -0
- package/README.md +52 -7
- package/README.ru.md +3 -6
- package/bun.lock +200 -0
- package/dist/index.js +582 -119
- package/package.json +6 -3
- package/src/FormatConfig.js +19 -0
- package/src/FormatOptions.js +52 -0
- package/src/Link.js +340 -40
- package/src/LinksGroup.js +2 -2
- package/src/Parser.js +57 -22
- package/src/grammar.pegjs +105 -4
- package/src/index.js +3 -1
- package/src/parser-generated.js +401 -88
- package/tests/ApiTests.test.js +104 -7
- package/tests/EdgeCaseParser.test.js +12 -12
- package/tests/FormatConfig.test.js +148 -0
- package/tests/IndentationConsistency.test.js +1 -1
- package/tests/IndentedIdSyntax.test.js +39 -39
- package/tests/Link.test.js +3 -3
- package/tests/LinksGroup.test.js +35 -5
- package/tests/MixedIndentationModes.test.js +35 -35
- package/tests/MultiQuoteParser.test.js +463 -0
- package/tests/MultilineParser.test.js +17 -17
- package/tests/MultilineQuotedString.test.js +9 -9
- package/tests/NestedParser.test.js +36 -7
- package/tests/NestedSelfReference.test.js +104 -0
- package/tests/SingleLineParser.test.js +88 -8
package/dist/index.js
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
class Link {
|
|
3
3
|
constructor(id = null, values = null) {
|
|
4
4
|
this.id = id;
|
|
5
|
-
|
|
5
|
+
if (values !== null && values !== undefined) {
|
|
6
|
+
if (!Array.isArray(values)) {
|
|
7
|
+
throw new TypeError("values must be an array or null");
|
|
8
|
+
}
|
|
9
|
+
this.values = values;
|
|
10
|
+
} else {
|
|
11
|
+
this.values = [];
|
|
12
|
+
}
|
|
6
13
|
}
|
|
7
14
|
toString() {
|
|
8
15
|
return this.format(false);
|
|
@@ -16,7 +23,9 @@ class Link {
|
|
|
16
23
|
} else if (this.values.length === 1) {
|
|
17
24
|
return this.values[0];
|
|
18
25
|
} else {
|
|
19
|
-
const newValues = this.values.map((v) =>
|
|
26
|
+
const newValues = this.values.map((v) => {
|
|
27
|
+
return v && typeof v.simplify === "function" ? v.simplify() : v;
|
|
28
|
+
});
|
|
20
29
|
return new Link(this.id, newValues);
|
|
21
30
|
}
|
|
22
31
|
}
|
|
@@ -24,21 +33,29 @@ class Link {
|
|
|
24
33
|
return new Link(null, [this, other]);
|
|
25
34
|
}
|
|
26
35
|
static getValueString(value) {
|
|
27
|
-
return value.toLinkOrIdString();
|
|
36
|
+
return value && typeof value.toLinkOrIdString === "function" ? value.toLinkOrIdString() : String(value);
|
|
28
37
|
}
|
|
29
38
|
static escapeReference(reference) {
|
|
30
39
|
if (!reference || reference.trim() === "") {
|
|
31
40
|
return "";
|
|
32
41
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
const hasSingleQuote = reference.includes("'");
|
|
43
|
+
const hasDoubleQuote = reference.includes('"');
|
|
44
|
+
const needsQuoting = reference.includes(":") || reference.includes("(") || reference.includes(")") || reference.includes(" ") || reference.includes("\t") || reference.includes(`
|
|
45
|
+
`) || reference.includes("\r") || hasDoubleQuote || hasSingleQuote;
|
|
46
|
+
if (hasSingleQuote && hasDoubleQuote) {
|
|
47
|
+
return `'${reference.replace(/'/g, "\\'")}'`;
|
|
48
|
+
}
|
|
49
|
+
if (hasDoubleQuote) {
|
|
36
50
|
return `'${reference}'`;
|
|
37
|
-
}
|
|
51
|
+
}
|
|
52
|
+
if (hasSingleQuote) {
|
|
38
53
|
return `"${reference}"`;
|
|
39
|
-
} else {
|
|
40
|
-
return reference;
|
|
41
54
|
}
|
|
55
|
+
if (needsQuoting) {
|
|
56
|
+
return `'${reference}'`;
|
|
57
|
+
}
|
|
58
|
+
return reference;
|
|
42
59
|
}
|
|
43
60
|
toLinkOrIdString() {
|
|
44
61
|
if (!this.values || this.values.length === 0) {
|
|
@@ -51,16 +68,27 @@ class Link {
|
|
|
51
68
|
return false;
|
|
52
69
|
if (this.id !== other.id)
|
|
53
70
|
return false;
|
|
54
|
-
|
|
71
|
+
const thisValues = this.values || [];
|
|
72
|
+
const otherValues = other.values || [];
|
|
73
|
+
if (thisValues.length !== otherValues.length)
|
|
55
74
|
return false;
|
|
56
|
-
for (let i = 0;i <
|
|
57
|
-
if (
|
|
58
|
-
|
|
75
|
+
for (let i = 0;i < thisValues.length; i++) {
|
|
76
|
+
if (thisValues[i] && typeof thisValues[i].equals === "function") {
|
|
77
|
+
if (!thisValues[i].equals(otherValues[i])) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
if (thisValues[i] !== otherValues[i]) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
59
84
|
}
|
|
60
85
|
}
|
|
61
86
|
return true;
|
|
62
87
|
}
|
|
63
88
|
format(lessParentheses = false, isCompoundValue = false) {
|
|
89
|
+
if (lessParentheses && typeof lessParentheses === "object" && (lessParentheses.constructor.name === "FormatOptions" || lessParentheses.constructor.name === "FormatConfig")) {
|
|
90
|
+
return this._formatWithOptions(lessParentheses, isCompoundValue);
|
|
91
|
+
}
|
|
64
92
|
if (this.id === null && (!this.values || this.values.length === 0)) {
|
|
65
93
|
return lessParentheses ? "" : "()";
|
|
66
94
|
}
|
|
@@ -88,8 +116,8 @@ class Link {
|
|
|
88
116
|
return lessParentheses && !this.needsParentheses(this.id) ? withColon : `(${withColon})`;
|
|
89
117
|
}
|
|
90
118
|
formatValue(value) {
|
|
91
|
-
if (!value.format) {
|
|
92
|
-
return Link.escapeReference(value.id || "");
|
|
119
|
+
if (!value || !value.format) {
|
|
120
|
+
return Link.escapeReference(value && value.id || "");
|
|
93
121
|
}
|
|
94
122
|
const isCompoundFromPaths = this._isFromPathCombination === true;
|
|
95
123
|
if (isCompoundFromPaths) {
|
|
@@ -103,10 +131,110 @@ class Link {
|
|
|
103
131
|
needsParentheses(str) {
|
|
104
132
|
return str && (str.includes(" ") || str.includes(":") || str.includes("(") || str.includes(")"));
|
|
105
133
|
}
|
|
134
|
+
_formatWithOptions(options, isCompoundValue = false) {
|
|
135
|
+
if (this.id === null && (!this.values || this.values.length === 0)) {
|
|
136
|
+
return options.lessParentheses ? "" : "()";
|
|
137
|
+
}
|
|
138
|
+
if (!this.values || this.values.length === 0) {
|
|
139
|
+
const escapedId = Link.escapeReference(this.id);
|
|
140
|
+
if (isCompoundValue) {
|
|
141
|
+
return `(${escapedId})`;
|
|
142
|
+
}
|
|
143
|
+
return options.lessParentheses && !this.needsParentheses(this.id) ? escapedId : `(${escapedId})`;
|
|
144
|
+
}
|
|
145
|
+
let shouldIndent = false;
|
|
146
|
+
if (options.shouldIndentByRefCount(this.values.length)) {
|
|
147
|
+
shouldIndent = true;
|
|
148
|
+
} else {
|
|
149
|
+
const valuesStr2 = this.values.map((v) => this.formatValue(v)).join(" ");
|
|
150
|
+
let testLine;
|
|
151
|
+
if (this.id !== null) {
|
|
152
|
+
const idStr2 = Link.escapeReference(this.id);
|
|
153
|
+
testLine = options.lessParentheses ? `${idStr2}: ${valuesStr2}` : `(${idStr2}: ${valuesStr2})`;
|
|
154
|
+
} else {
|
|
155
|
+
testLine = options.lessParentheses ? valuesStr2 : `(${valuesStr2})`;
|
|
156
|
+
}
|
|
157
|
+
if (options.shouldIndentByLength(testLine)) {
|
|
158
|
+
shouldIndent = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (shouldIndent && options.preferInline === false) {
|
|
162
|
+
return this._formatIndented(options);
|
|
163
|
+
}
|
|
164
|
+
const valuesStr = this.values.map((v) => this.formatValue(v)).join(" ");
|
|
165
|
+
if (this.id === null) {
|
|
166
|
+
if (options.lessParentheses) {
|
|
167
|
+
const allSimple = this.values.every((v) => !v.values || v.values.length === 0);
|
|
168
|
+
if (allSimple) {
|
|
169
|
+
return this.values.map((v) => Link.escapeReference(v.id)).join(" ");
|
|
170
|
+
}
|
|
171
|
+
return valuesStr;
|
|
172
|
+
}
|
|
173
|
+
return `(${valuesStr})`;
|
|
174
|
+
}
|
|
175
|
+
const idStr = Link.escapeReference(this.id);
|
|
176
|
+
const withColon = `${idStr}: ${valuesStr}`;
|
|
177
|
+
return options.lessParentheses && !this.needsParentheses(this.id) ? withColon : `(${withColon})`;
|
|
178
|
+
}
|
|
179
|
+
_formatIndented(options) {
|
|
180
|
+
if (this.id === null) {
|
|
181
|
+
const lines2 = this.values.map((v) => options.indentString + this.formatValue(v));
|
|
182
|
+
return lines2.join(`
|
|
183
|
+
`);
|
|
184
|
+
}
|
|
185
|
+
const idStr = Link.escapeReference(this.id);
|
|
186
|
+
const lines = [`${idStr}:`];
|
|
187
|
+
for (const v of this.values) {
|
|
188
|
+
lines.push(options.indentString + this.formatValue(v));
|
|
189
|
+
}
|
|
190
|
+
return lines.join(`
|
|
191
|
+
`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function _groupConsecutiveLinks(links) {
|
|
195
|
+
if (!links || links.length === 0) {
|
|
196
|
+
return links;
|
|
197
|
+
}
|
|
198
|
+
const grouped = [];
|
|
199
|
+
let i = 0;
|
|
200
|
+
while (i < links.length) {
|
|
201
|
+
const current = links[i];
|
|
202
|
+
if (current.id !== null && current.values && current.values.length > 0) {
|
|
203
|
+
const sameIdValues = [...current.values];
|
|
204
|
+
let j = i + 1;
|
|
205
|
+
while (j < links.length) {
|
|
206
|
+
const nextLink = links[j];
|
|
207
|
+
if (nextLink.id === current.id && nextLink.values && nextLink.values.length > 0) {
|
|
208
|
+
sameIdValues.push(...nextLink.values);
|
|
209
|
+
j++;
|
|
210
|
+
} else {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (j > i + 1) {
|
|
215
|
+
const groupedLink = new Link(current.id, sameIdValues);
|
|
216
|
+
grouped.push(groupedLink);
|
|
217
|
+
i = j;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
grouped.push(current);
|
|
222
|
+
i++;
|
|
223
|
+
}
|
|
224
|
+
return grouped;
|
|
106
225
|
}
|
|
107
226
|
function formatLinks(links, lessParentheses = false) {
|
|
108
227
|
if (!links || links.length === 0)
|
|
109
228
|
return "";
|
|
229
|
+
if (lessParentheses && typeof lessParentheses === "object" && (lessParentheses.constructor.name === "FormatOptions" || lessParentheses.constructor.name === "FormatConfig")) {
|
|
230
|
+
const options = lessParentheses;
|
|
231
|
+
let linksToFormat = links;
|
|
232
|
+
if (options.groupConsecutive) {
|
|
233
|
+
linksToFormat = _groupConsecutiveLinks(links);
|
|
234
|
+
}
|
|
235
|
+
return linksToFormat.map((link) => link.format(options)).join(`
|
|
236
|
+
`);
|
|
237
|
+
}
|
|
110
238
|
return links.map((link) => link.format(lessParentheses)).join(`
|
|
111
239
|
`);
|
|
112
240
|
}
|
|
@@ -255,13 +383,12 @@ function peg$parse(input, options) {
|
|
|
255
383
|
const peg$c2 = ")";
|
|
256
384
|
const peg$c3 = '"';
|
|
257
385
|
const peg$c4 = "'";
|
|
258
|
-
const peg$c5 = "
|
|
386
|
+
const peg$c5 = "`";
|
|
387
|
+
const peg$c6 = " ";
|
|
259
388
|
const peg$r0 = /^[ \t]/;
|
|
260
389
|
const peg$r1 = /^[\r\n]/;
|
|
261
|
-
const peg$r2 = /^[
|
|
262
|
-
const peg$r3 = /^[^
|
|
263
|
-
const peg$r4 = /^[ \t\n\r]/;
|
|
264
|
-
const peg$r5 = /^[^ \t\n\r(:)]/;
|
|
390
|
+
const peg$r2 = /^[ \t\n\r]/;
|
|
391
|
+
const peg$r3 = /^[^ \t\n\r(:)]/;
|
|
265
392
|
const peg$e0 = peg$classExpectation([" ", "\t"], false, false, false);
|
|
266
393
|
const peg$e1 = peg$classExpectation(["\r", `
|
|
267
394
|
`], false, false, false);
|
|
@@ -269,14 +396,13 @@ function peg$parse(input, options) {
|
|
|
269
396
|
const peg$e3 = peg$literalExpectation("(", false);
|
|
270
397
|
const peg$e4 = peg$literalExpectation(")", false);
|
|
271
398
|
const peg$e5 = peg$literalExpectation('"', false);
|
|
272
|
-
const peg$e6 = peg$
|
|
399
|
+
const peg$e6 = peg$anyExpectation();
|
|
273
400
|
const peg$e7 = peg$literalExpectation("'", false);
|
|
274
|
-
const peg$e8 = peg$
|
|
401
|
+
const peg$e8 = peg$literalExpectation("`", false);
|
|
275
402
|
const peg$e9 = peg$literalExpectation(" ", false);
|
|
276
|
-
const peg$e10 = peg$
|
|
277
|
-
const peg$e11 = peg$classExpectation([" ", "\t", `
|
|
403
|
+
const peg$e10 = peg$classExpectation([" ", "\t", `
|
|
278
404
|
`, "\r"], false, false, false);
|
|
279
|
-
const peg$
|
|
405
|
+
const peg$e11 = peg$classExpectation([" ", "\t", `
|
|
280
406
|
`, "\r", "(", ":", ")"], true, false, false);
|
|
281
407
|
function peg$f0() {
|
|
282
408
|
indentationStack = [0];
|
|
@@ -361,22 +487,82 @@ function peg$parse(input, options) {
|
|
|
361
487
|
function peg$f25(chars) {
|
|
362
488
|
return chars.join("");
|
|
363
489
|
}
|
|
364
|
-
function peg$f26(
|
|
365
|
-
|
|
490
|
+
function peg$f26() {
|
|
491
|
+
const pos = offset();
|
|
492
|
+
const result = parseQuotedStringAt(input, pos, '"');
|
|
493
|
+
if (result) {
|
|
494
|
+
parsedValue = result.value;
|
|
495
|
+
parsedLength = result.length;
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
return false;
|
|
366
499
|
}
|
|
367
|
-
function peg$f27(
|
|
368
|
-
return
|
|
500
|
+
function peg$f27(chars) {
|
|
501
|
+
return parsedValue;
|
|
502
|
+
}
|
|
503
|
+
function peg$f28(c, cs) {
|
|
504
|
+
return [c].concat(cs).join("");
|
|
505
|
+
}
|
|
506
|
+
function peg$f29() {
|
|
507
|
+
return parsedLength > 1 && (parsedLength--, true);
|
|
508
|
+
}
|
|
509
|
+
function peg$f30(c) {
|
|
510
|
+
return c;
|
|
511
|
+
}
|
|
512
|
+
function peg$f31() {
|
|
513
|
+
const pos = offset();
|
|
514
|
+
const result = parseQuotedStringAt(input, pos, "'");
|
|
515
|
+
if (result) {
|
|
516
|
+
parsedValue = result.value;
|
|
517
|
+
parsedLength = result.length;
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
return false;
|
|
369
521
|
}
|
|
370
|
-
function peg$
|
|
522
|
+
function peg$f32(chars) {
|
|
523
|
+
return parsedValue;
|
|
524
|
+
}
|
|
525
|
+
function peg$f33(c, cs) {
|
|
526
|
+
return [c].concat(cs).join("");
|
|
527
|
+
}
|
|
528
|
+
function peg$f34() {
|
|
529
|
+
return parsedLength > 1 && (parsedLength--, true);
|
|
530
|
+
}
|
|
531
|
+
function peg$f35(c) {
|
|
532
|
+
return c;
|
|
533
|
+
}
|
|
534
|
+
function peg$f36() {
|
|
535
|
+
const pos = offset();
|
|
536
|
+
const result = parseQuotedStringAt(input, pos, "`");
|
|
537
|
+
if (result) {
|
|
538
|
+
parsedValue = result.value;
|
|
539
|
+
parsedLength = result.length;
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
function peg$f37(chars) {
|
|
545
|
+
return parsedValue;
|
|
546
|
+
}
|
|
547
|
+
function peg$f38(c, cs) {
|
|
548
|
+
return [c].concat(cs).join("");
|
|
549
|
+
}
|
|
550
|
+
function peg$f39() {
|
|
551
|
+
return parsedLength > 1 && (parsedLength--, true);
|
|
552
|
+
}
|
|
553
|
+
function peg$f40(c) {
|
|
554
|
+
return c;
|
|
555
|
+
}
|
|
556
|
+
function peg$f41(spaces) {
|
|
371
557
|
setBaseIndentation(spaces);
|
|
372
558
|
}
|
|
373
|
-
function peg$
|
|
559
|
+
function peg$f42(spaces) {
|
|
374
560
|
return normalizeIndentation(spaces) > getCurrentIndentation();
|
|
375
561
|
}
|
|
376
|
-
function peg$
|
|
562
|
+
function peg$f43(spaces) {
|
|
377
563
|
pushIndentation(spaces);
|
|
378
564
|
}
|
|
379
|
-
function peg$
|
|
565
|
+
function peg$f44(spaces) {
|
|
380
566
|
return checkIndentation(spaces);
|
|
381
567
|
}
|
|
382
568
|
let peg$currPos = options.peg$currPos | 0;
|
|
@@ -1076,12 +1262,9 @@ function peg$parse(input, options) {
|
|
|
1076
1262
|
}
|
|
1077
1263
|
function peg$parsereference() {
|
|
1078
1264
|
let s0;
|
|
1079
|
-
s0 = peg$
|
|
1265
|
+
s0 = peg$parsequotedReference();
|
|
1080
1266
|
if (s0 === peg$FAILED) {
|
|
1081
|
-
s0 = peg$
|
|
1082
|
-
if (s0 === peg$FAILED) {
|
|
1083
|
-
s0 = peg$parsesimpleReference();
|
|
1084
|
-
}
|
|
1267
|
+
s0 = peg$parsesimpleReference();
|
|
1085
1268
|
}
|
|
1086
1269
|
return s0;
|
|
1087
1270
|
}
|
|
@@ -1105,58 +1288,159 @@ function peg$parse(input, options) {
|
|
|
1105
1288
|
s0 = s1;
|
|
1106
1289
|
return s0;
|
|
1107
1290
|
}
|
|
1108
|
-
function peg$
|
|
1291
|
+
function peg$parsequotedReference() {
|
|
1292
|
+
let s0;
|
|
1293
|
+
s0 = peg$parsedoubleQuotedUniversal();
|
|
1294
|
+
if (s0 === peg$FAILED) {
|
|
1295
|
+
s0 = peg$parsesingleQuotedUniversal();
|
|
1296
|
+
if (s0 === peg$FAILED) {
|
|
1297
|
+
s0 = peg$parsebacktickQuotedUniversal();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return s0;
|
|
1301
|
+
}
|
|
1302
|
+
function peg$parsedoubleQuotedUniversal() {
|
|
1109
1303
|
let s0, s1, s2, s3;
|
|
1110
1304
|
s0 = peg$currPos;
|
|
1305
|
+
s1 = peg$currPos;
|
|
1306
|
+
peg$silentFails++;
|
|
1111
1307
|
if (input.charCodeAt(peg$currPos) === 34) {
|
|
1112
|
-
|
|
1308
|
+
s2 = peg$c3;
|
|
1113
1309
|
peg$currPos++;
|
|
1114
1310
|
} else {
|
|
1115
|
-
|
|
1311
|
+
s2 = peg$FAILED;
|
|
1116
1312
|
if (peg$silentFails === 0) {
|
|
1117
1313
|
peg$fail(peg$e5);
|
|
1118
1314
|
}
|
|
1119
1315
|
}
|
|
1316
|
+
peg$silentFails--;
|
|
1317
|
+
if (s2 !== peg$FAILED) {
|
|
1318
|
+
peg$currPos = s1;
|
|
1319
|
+
s1 = undefined;
|
|
1320
|
+
} else {
|
|
1321
|
+
s1 = peg$FAILED;
|
|
1322
|
+
}
|
|
1323
|
+
if (s1 !== peg$FAILED) {
|
|
1324
|
+
peg$savedPos = peg$currPos;
|
|
1325
|
+
s2 = peg$f26();
|
|
1326
|
+
if (s2) {
|
|
1327
|
+
s2 = undefined;
|
|
1328
|
+
} else {
|
|
1329
|
+
s2 = peg$FAILED;
|
|
1330
|
+
}
|
|
1331
|
+
if (s2 !== peg$FAILED) {
|
|
1332
|
+
s3 = peg$parseconsumeDouble();
|
|
1333
|
+
if (s3 !== peg$FAILED) {
|
|
1334
|
+
peg$savedPos = s0;
|
|
1335
|
+
s0 = peg$f27(s3);
|
|
1336
|
+
} else {
|
|
1337
|
+
peg$currPos = s0;
|
|
1338
|
+
s0 = peg$FAILED;
|
|
1339
|
+
}
|
|
1340
|
+
} else {
|
|
1341
|
+
peg$currPos = s0;
|
|
1342
|
+
s0 = peg$FAILED;
|
|
1343
|
+
}
|
|
1344
|
+
} else {
|
|
1345
|
+
peg$currPos = s0;
|
|
1346
|
+
s0 = peg$FAILED;
|
|
1347
|
+
}
|
|
1348
|
+
return s0;
|
|
1349
|
+
}
|
|
1350
|
+
function peg$parseconsumeDouble() {
|
|
1351
|
+
let s0, s1, s2, s3;
|
|
1352
|
+
s0 = peg$currPos;
|
|
1353
|
+
if (input.length > peg$currPos) {
|
|
1354
|
+
s1 = input.charAt(peg$currPos);
|
|
1355
|
+
peg$currPos++;
|
|
1356
|
+
} else {
|
|
1357
|
+
s1 = peg$FAILED;
|
|
1358
|
+
if (peg$silentFails === 0) {
|
|
1359
|
+
peg$fail(peg$e6);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1120
1362
|
if (s1 !== peg$FAILED) {
|
|
1121
1363
|
s2 = [];
|
|
1122
|
-
s3 =
|
|
1123
|
-
|
|
1364
|
+
s3 = peg$parseconsumeDoubleMore();
|
|
1365
|
+
while (s3 !== peg$FAILED) {
|
|
1366
|
+
s2.push(s3);
|
|
1367
|
+
s3 = peg$parseconsumeDoubleMore();
|
|
1368
|
+
}
|
|
1369
|
+
peg$savedPos = s0;
|
|
1370
|
+
s0 = peg$f28(s1, s2);
|
|
1371
|
+
} else {
|
|
1372
|
+
peg$currPos = s0;
|
|
1373
|
+
s0 = peg$FAILED;
|
|
1374
|
+
}
|
|
1375
|
+
return s0;
|
|
1376
|
+
}
|
|
1377
|
+
function peg$parseconsumeDoubleMore() {
|
|
1378
|
+
let s0, s1, s2;
|
|
1379
|
+
s0 = peg$currPos;
|
|
1380
|
+
peg$savedPos = peg$currPos;
|
|
1381
|
+
s1 = peg$f29();
|
|
1382
|
+
if (s1) {
|
|
1383
|
+
s1 = undefined;
|
|
1384
|
+
} else {
|
|
1385
|
+
s1 = peg$FAILED;
|
|
1386
|
+
}
|
|
1387
|
+
if (s1 !== peg$FAILED) {
|
|
1388
|
+
if (input.length > peg$currPos) {
|
|
1389
|
+
s2 = input.charAt(peg$currPos);
|
|
1124
1390
|
peg$currPos++;
|
|
1125
1391
|
} else {
|
|
1126
|
-
|
|
1392
|
+
s2 = peg$FAILED;
|
|
1127
1393
|
if (peg$silentFails === 0) {
|
|
1128
1394
|
peg$fail(peg$e6);
|
|
1129
1395
|
}
|
|
1130
1396
|
}
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1397
|
+
if (s2 !== peg$FAILED) {
|
|
1398
|
+
peg$savedPos = s0;
|
|
1399
|
+
s0 = peg$f30(s2);
|
|
1400
|
+
} else {
|
|
1401
|
+
peg$currPos = s0;
|
|
1402
|
+
s0 = peg$FAILED;
|
|
1403
|
+
}
|
|
1404
|
+
} else {
|
|
1405
|
+
peg$currPos = s0;
|
|
1406
|
+
s0 = peg$FAILED;
|
|
1407
|
+
}
|
|
1408
|
+
return s0;
|
|
1409
|
+
}
|
|
1410
|
+
function peg$parsesingleQuotedUniversal() {
|
|
1411
|
+
let s0, s1, s2, s3;
|
|
1412
|
+
s0 = peg$currPos;
|
|
1413
|
+
s1 = peg$currPos;
|
|
1414
|
+
peg$silentFails++;
|
|
1415
|
+
if (input.charCodeAt(peg$currPos) === 39) {
|
|
1416
|
+
s2 = peg$c4;
|
|
1417
|
+
peg$currPos++;
|
|
1418
|
+
} else {
|
|
1419
|
+
s2 = peg$FAILED;
|
|
1420
|
+
if (peg$silentFails === 0) {
|
|
1421
|
+
peg$fail(peg$e7);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
peg$silentFails--;
|
|
1425
|
+
if (s2 !== peg$FAILED) {
|
|
1426
|
+
peg$currPos = s1;
|
|
1427
|
+
s1 = undefined;
|
|
1428
|
+
} else {
|
|
1429
|
+
s1 = peg$FAILED;
|
|
1430
|
+
}
|
|
1431
|
+
if (s1 !== peg$FAILED) {
|
|
1432
|
+
peg$savedPos = peg$currPos;
|
|
1433
|
+
s2 = peg$f31();
|
|
1434
|
+
if (s2) {
|
|
1435
|
+
s2 = undefined;
|
|
1144
1436
|
} else {
|
|
1145
1437
|
s2 = peg$FAILED;
|
|
1146
1438
|
}
|
|
1147
1439
|
if (s2 !== peg$FAILED) {
|
|
1148
|
-
|
|
1149
|
-
s3 = peg$c3;
|
|
1150
|
-
peg$currPos++;
|
|
1151
|
-
} else {
|
|
1152
|
-
s3 = peg$FAILED;
|
|
1153
|
-
if (peg$silentFails === 0) {
|
|
1154
|
-
peg$fail(peg$e5);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1440
|
+
s3 = peg$parseconsumeSingle();
|
|
1157
1441
|
if (s3 !== peg$FAILED) {
|
|
1158
1442
|
peg$savedPos = s0;
|
|
1159
|
-
s0 = peg$
|
|
1443
|
+
s0 = peg$f32(s3);
|
|
1160
1444
|
} else {
|
|
1161
1445
|
peg$currPos = s0;
|
|
1162
1446
|
s0 = peg$FAILED;
|
|
@@ -1171,58 +1455,100 @@ function peg$parse(input, options) {
|
|
|
1171
1455
|
}
|
|
1172
1456
|
return s0;
|
|
1173
1457
|
}
|
|
1174
|
-
function peg$
|
|
1458
|
+
function peg$parseconsumeSingle() {
|
|
1175
1459
|
let s0, s1, s2, s3;
|
|
1176
1460
|
s0 = peg$currPos;
|
|
1177
|
-
if (input.
|
|
1178
|
-
s1 = peg$
|
|
1461
|
+
if (input.length > peg$currPos) {
|
|
1462
|
+
s1 = input.charAt(peg$currPos);
|
|
1179
1463
|
peg$currPos++;
|
|
1180
1464
|
} else {
|
|
1181
1465
|
s1 = peg$FAILED;
|
|
1182
1466
|
if (peg$silentFails === 0) {
|
|
1183
|
-
peg$fail(peg$
|
|
1467
|
+
peg$fail(peg$e6);
|
|
1184
1468
|
}
|
|
1185
1469
|
}
|
|
1186
1470
|
if (s1 !== peg$FAILED) {
|
|
1187
1471
|
s2 = [];
|
|
1188
|
-
s3 =
|
|
1189
|
-
|
|
1472
|
+
s3 = peg$parseconsumeSingleMore();
|
|
1473
|
+
while (s3 !== peg$FAILED) {
|
|
1474
|
+
s2.push(s3);
|
|
1475
|
+
s3 = peg$parseconsumeSingleMore();
|
|
1476
|
+
}
|
|
1477
|
+
peg$savedPos = s0;
|
|
1478
|
+
s0 = peg$f33(s1, s2);
|
|
1479
|
+
} else {
|
|
1480
|
+
peg$currPos = s0;
|
|
1481
|
+
s0 = peg$FAILED;
|
|
1482
|
+
}
|
|
1483
|
+
return s0;
|
|
1484
|
+
}
|
|
1485
|
+
function peg$parseconsumeSingleMore() {
|
|
1486
|
+
let s0, s1, s2;
|
|
1487
|
+
s0 = peg$currPos;
|
|
1488
|
+
peg$savedPos = peg$currPos;
|
|
1489
|
+
s1 = peg$f34();
|
|
1490
|
+
if (s1) {
|
|
1491
|
+
s1 = undefined;
|
|
1492
|
+
} else {
|
|
1493
|
+
s1 = peg$FAILED;
|
|
1494
|
+
}
|
|
1495
|
+
if (s1 !== peg$FAILED) {
|
|
1496
|
+
if (input.length > peg$currPos) {
|
|
1497
|
+
s2 = input.charAt(peg$currPos);
|
|
1190
1498
|
peg$currPos++;
|
|
1191
1499
|
} else {
|
|
1192
|
-
|
|
1500
|
+
s2 = peg$FAILED;
|
|
1193
1501
|
if (peg$silentFails === 0) {
|
|
1194
|
-
peg$fail(peg$
|
|
1502
|
+
peg$fail(peg$e6);
|
|
1195
1503
|
}
|
|
1196
1504
|
}
|
|
1197
|
-
if (
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1505
|
+
if (s2 !== peg$FAILED) {
|
|
1506
|
+
peg$savedPos = s0;
|
|
1507
|
+
s0 = peg$f35(s2);
|
|
1508
|
+
} else {
|
|
1509
|
+
peg$currPos = s0;
|
|
1510
|
+
s0 = peg$FAILED;
|
|
1511
|
+
}
|
|
1512
|
+
} else {
|
|
1513
|
+
peg$currPos = s0;
|
|
1514
|
+
s0 = peg$FAILED;
|
|
1515
|
+
}
|
|
1516
|
+
return s0;
|
|
1517
|
+
}
|
|
1518
|
+
function peg$parsebacktickQuotedUniversal() {
|
|
1519
|
+
let s0, s1, s2, s3;
|
|
1520
|
+
s0 = peg$currPos;
|
|
1521
|
+
s1 = peg$currPos;
|
|
1522
|
+
peg$silentFails++;
|
|
1523
|
+
if (input.charCodeAt(peg$currPos) === 96) {
|
|
1524
|
+
s2 = peg$c5;
|
|
1525
|
+
peg$currPos++;
|
|
1526
|
+
} else {
|
|
1527
|
+
s2 = peg$FAILED;
|
|
1528
|
+
if (peg$silentFails === 0) {
|
|
1529
|
+
peg$fail(peg$e8);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
peg$silentFails--;
|
|
1533
|
+
if (s2 !== peg$FAILED) {
|
|
1534
|
+
peg$currPos = s1;
|
|
1535
|
+
s1 = undefined;
|
|
1536
|
+
} else {
|
|
1537
|
+
s1 = peg$FAILED;
|
|
1538
|
+
}
|
|
1539
|
+
if (s1 !== peg$FAILED) {
|
|
1540
|
+
peg$savedPos = peg$currPos;
|
|
1541
|
+
s2 = peg$f36();
|
|
1542
|
+
if (s2) {
|
|
1543
|
+
s2 = undefined;
|
|
1210
1544
|
} else {
|
|
1211
1545
|
s2 = peg$FAILED;
|
|
1212
1546
|
}
|
|
1213
1547
|
if (s2 !== peg$FAILED) {
|
|
1214
|
-
|
|
1215
|
-
s3 = peg$c4;
|
|
1216
|
-
peg$currPos++;
|
|
1217
|
-
} else {
|
|
1218
|
-
s3 = peg$FAILED;
|
|
1219
|
-
if (peg$silentFails === 0) {
|
|
1220
|
-
peg$fail(peg$e7);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1548
|
+
s3 = peg$parseconsumeBacktick();
|
|
1223
1549
|
if (s3 !== peg$FAILED) {
|
|
1224
1550
|
peg$savedPos = s0;
|
|
1225
|
-
s0 = peg$
|
|
1551
|
+
s0 = peg$f37(s3);
|
|
1226
1552
|
} else {
|
|
1227
1553
|
peg$currPos = s0;
|
|
1228
1554
|
s0 = peg$FAILED;
|
|
@@ -1237,12 +1563,72 @@ function peg$parse(input, options) {
|
|
|
1237
1563
|
}
|
|
1238
1564
|
return s0;
|
|
1239
1565
|
}
|
|
1566
|
+
function peg$parseconsumeBacktick() {
|
|
1567
|
+
let s0, s1, s2, s3;
|
|
1568
|
+
s0 = peg$currPos;
|
|
1569
|
+
if (input.length > peg$currPos) {
|
|
1570
|
+
s1 = input.charAt(peg$currPos);
|
|
1571
|
+
peg$currPos++;
|
|
1572
|
+
} else {
|
|
1573
|
+
s1 = peg$FAILED;
|
|
1574
|
+
if (peg$silentFails === 0) {
|
|
1575
|
+
peg$fail(peg$e6);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
if (s1 !== peg$FAILED) {
|
|
1579
|
+
s2 = [];
|
|
1580
|
+
s3 = peg$parseconsumeBacktickMore();
|
|
1581
|
+
while (s3 !== peg$FAILED) {
|
|
1582
|
+
s2.push(s3);
|
|
1583
|
+
s3 = peg$parseconsumeBacktickMore();
|
|
1584
|
+
}
|
|
1585
|
+
peg$savedPos = s0;
|
|
1586
|
+
s0 = peg$f38(s1, s2);
|
|
1587
|
+
} else {
|
|
1588
|
+
peg$currPos = s0;
|
|
1589
|
+
s0 = peg$FAILED;
|
|
1590
|
+
}
|
|
1591
|
+
return s0;
|
|
1592
|
+
}
|
|
1593
|
+
function peg$parseconsumeBacktickMore() {
|
|
1594
|
+
let s0, s1, s2;
|
|
1595
|
+
s0 = peg$currPos;
|
|
1596
|
+
peg$savedPos = peg$currPos;
|
|
1597
|
+
s1 = peg$f39();
|
|
1598
|
+
if (s1) {
|
|
1599
|
+
s1 = undefined;
|
|
1600
|
+
} else {
|
|
1601
|
+
s1 = peg$FAILED;
|
|
1602
|
+
}
|
|
1603
|
+
if (s1 !== peg$FAILED) {
|
|
1604
|
+
if (input.length > peg$currPos) {
|
|
1605
|
+
s2 = input.charAt(peg$currPos);
|
|
1606
|
+
peg$currPos++;
|
|
1607
|
+
} else {
|
|
1608
|
+
s2 = peg$FAILED;
|
|
1609
|
+
if (peg$silentFails === 0) {
|
|
1610
|
+
peg$fail(peg$e6);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
if (s2 !== peg$FAILED) {
|
|
1614
|
+
peg$savedPos = s0;
|
|
1615
|
+
s0 = peg$f40(s2);
|
|
1616
|
+
} else {
|
|
1617
|
+
peg$currPos = s0;
|
|
1618
|
+
s0 = peg$FAILED;
|
|
1619
|
+
}
|
|
1620
|
+
} else {
|
|
1621
|
+
peg$currPos = s0;
|
|
1622
|
+
s0 = peg$FAILED;
|
|
1623
|
+
}
|
|
1624
|
+
return s0;
|
|
1625
|
+
}
|
|
1240
1626
|
function peg$parseSET_BASE_INDENTATION() {
|
|
1241
1627
|
let s0, s1, s2;
|
|
1242
1628
|
s0 = peg$currPos;
|
|
1243
1629
|
s1 = [];
|
|
1244
1630
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
1245
|
-
s2 = peg$
|
|
1631
|
+
s2 = peg$c6;
|
|
1246
1632
|
peg$currPos++;
|
|
1247
1633
|
} else {
|
|
1248
1634
|
s2 = peg$FAILED;
|
|
@@ -1253,7 +1639,7 @@ function peg$parse(input, options) {
|
|
|
1253
1639
|
while (s2 !== peg$FAILED) {
|
|
1254
1640
|
s1.push(s2);
|
|
1255
1641
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
1256
|
-
s2 = peg$
|
|
1642
|
+
s2 = peg$c6;
|
|
1257
1643
|
peg$currPos++;
|
|
1258
1644
|
} else {
|
|
1259
1645
|
s2 = peg$FAILED;
|
|
@@ -1263,7 +1649,7 @@ function peg$parse(input, options) {
|
|
|
1263
1649
|
}
|
|
1264
1650
|
}
|
|
1265
1651
|
peg$savedPos = s0;
|
|
1266
|
-
s1 = peg$
|
|
1652
|
+
s1 = peg$f41(s1);
|
|
1267
1653
|
s0 = s1;
|
|
1268
1654
|
return s0;
|
|
1269
1655
|
}
|
|
@@ -1272,7 +1658,7 @@ function peg$parse(input, options) {
|
|
|
1272
1658
|
s0 = peg$currPos;
|
|
1273
1659
|
s1 = [];
|
|
1274
1660
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
1275
|
-
s2 = peg$
|
|
1661
|
+
s2 = peg$c6;
|
|
1276
1662
|
peg$currPos++;
|
|
1277
1663
|
} else {
|
|
1278
1664
|
s2 = peg$FAILED;
|
|
@@ -1283,7 +1669,7 @@ function peg$parse(input, options) {
|
|
|
1283
1669
|
while (s2 !== peg$FAILED) {
|
|
1284
1670
|
s1.push(s2);
|
|
1285
1671
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
1286
|
-
s2 = peg$
|
|
1672
|
+
s2 = peg$c6;
|
|
1287
1673
|
peg$currPos++;
|
|
1288
1674
|
} else {
|
|
1289
1675
|
s2 = peg$FAILED;
|
|
@@ -1293,7 +1679,7 @@ function peg$parse(input, options) {
|
|
|
1293
1679
|
}
|
|
1294
1680
|
}
|
|
1295
1681
|
peg$savedPos = peg$currPos;
|
|
1296
|
-
s2 = peg$
|
|
1682
|
+
s2 = peg$f42(s1);
|
|
1297
1683
|
if (s2) {
|
|
1298
1684
|
s2 = undefined;
|
|
1299
1685
|
} else {
|
|
@@ -1301,7 +1687,7 @@ function peg$parse(input, options) {
|
|
|
1301
1687
|
}
|
|
1302
1688
|
if (s2 !== peg$FAILED) {
|
|
1303
1689
|
peg$savedPos = s0;
|
|
1304
|
-
s0 = peg$
|
|
1690
|
+
s0 = peg$f43(s1);
|
|
1305
1691
|
} else {
|
|
1306
1692
|
peg$currPos = s0;
|
|
1307
1693
|
s0 = peg$FAILED;
|
|
@@ -1313,7 +1699,7 @@ function peg$parse(input, options) {
|
|
|
1313
1699
|
s0 = peg$currPos;
|
|
1314
1700
|
s1 = [];
|
|
1315
1701
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
1316
|
-
s2 = peg$
|
|
1702
|
+
s2 = peg$c6;
|
|
1317
1703
|
peg$currPos++;
|
|
1318
1704
|
} else {
|
|
1319
1705
|
s2 = peg$FAILED;
|
|
@@ -1324,7 +1710,7 @@ function peg$parse(input, options) {
|
|
|
1324
1710
|
while (s2 !== peg$FAILED) {
|
|
1325
1711
|
s1.push(s2);
|
|
1326
1712
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
1327
|
-
s2 = peg$
|
|
1713
|
+
s2 = peg$c6;
|
|
1328
1714
|
peg$currPos++;
|
|
1329
1715
|
} else {
|
|
1330
1716
|
s2 = peg$FAILED;
|
|
@@ -1334,7 +1720,7 @@ function peg$parse(input, options) {
|
|
|
1334
1720
|
}
|
|
1335
1721
|
}
|
|
1336
1722
|
peg$savedPos = peg$currPos;
|
|
1337
|
-
s2 = peg$
|
|
1723
|
+
s2 = peg$f44(s1);
|
|
1338
1724
|
if (s2) {
|
|
1339
1725
|
s2 = undefined;
|
|
1340
1726
|
} else {
|
|
@@ -1401,7 +1787,7 @@ function peg$parse(input, options) {
|
|
|
1401
1787
|
} else {
|
|
1402
1788
|
s1 = peg$FAILED;
|
|
1403
1789
|
if (peg$silentFails === 0) {
|
|
1404
|
-
peg$fail(peg$
|
|
1790
|
+
peg$fail(peg$e6);
|
|
1405
1791
|
}
|
|
1406
1792
|
}
|
|
1407
1793
|
peg$silentFails--;
|
|
@@ -1452,12 +1838,12 @@ function peg$parse(input, options) {
|
|
|
1452
1838
|
function peg$parsewhiteSpaceSymbol() {
|
|
1453
1839
|
let s0;
|
|
1454
1840
|
s0 = input.charAt(peg$currPos);
|
|
1455
|
-
if (peg$
|
|
1841
|
+
if (peg$r2.test(s0)) {
|
|
1456
1842
|
peg$currPos++;
|
|
1457
1843
|
} else {
|
|
1458
1844
|
s0 = peg$FAILED;
|
|
1459
1845
|
if (peg$silentFails === 0) {
|
|
1460
|
-
peg$fail(peg$
|
|
1846
|
+
peg$fail(peg$e10);
|
|
1461
1847
|
}
|
|
1462
1848
|
}
|
|
1463
1849
|
return s0;
|
|
@@ -1465,12 +1851,12 @@ function peg$parse(input, options) {
|
|
|
1465
1851
|
function peg$parsereferenceSymbol() {
|
|
1466
1852
|
let s0;
|
|
1467
1853
|
s0 = input.charAt(peg$currPos);
|
|
1468
|
-
if (peg$
|
|
1854
|
+
if (peg$r3.test(s0)) {
|
|
1469
1855
|
peg$currPos++;
|
|
1470
1856
|
} else {
|
|
1471
1857
|
s0 = peg$FAILED;
|
|
1472
1858
|
if (peg$silentFails === 0) {
|
|
1473
|
-
peg$fail(peg$
|
|
1859
|
+
peg$fail(peg$e11);
|
|
1474
1860
|
}
|
|
1475
1861
|
}
|
|
1476
1862
|
return s0;
|
|
@@ -1504,6 +1890,41 @@ function peg$parse(input, options) {
|
|
|
1504
1890
|
function getCurrentIndentation() {
|
|
1505
1891
|
return indentationStack[indentationStack.length - 1];
|
|
1506
1892
|
}
|
|
1893
|
+
function parseQuotedStringAt(inputStr, startPos, quoteChar) {
|
|
1894
|
+
if (startPos >= inputStr.length || inputStr[startPos] !== quoteChar) {
|
|
1895
|
+
return null;
|
|
1896
|
+
}
|
|
1897
|
+
let quoteCount = 0;
|
|
1898
|
+
let pos = startPos;
|
|
1899
|
+
while (pos < inputStr.length && inputStr[pos] === quoteChar) {
|
|
1900
|
+
quoteCount++;
|
|
1901
|
+
pos++;
|
|
1902
|
+
}
|
|
1903
|
+
const closeSeq = quoteChar.repeat(quoteCount);
|
|
1904
|
+
const escapeSeq = quoteChar.repeat(quoteCount * 2);
|
|
1905
|
+
let content = "";
|
|
1906
|
+
while (pos < inputStr.length) {
|
|
1907
|
+
if (inputStr.substr(pos, escapeSeq.length) === escapeSeq) {
|
|
1908
|
+
content += closeSeq;
|
|
1909
|
+
pos += escapeSeq.length;
|
|
1910
|
+
continue;
|
|
1911
|
+
}
|
|
1912
|
+
if (inputStr.substr(pos, quoteCount) === closeSeq) {
|
|
1913
|
+
const afterClose = pos + quoteCount;
|
|
1914
|
+
if (afterClose >= inputStr.length || inputStr[afterClose] !== quoteChar) {
|
|
1915
|
+
return {
|
|
1916
|
+
value: content,
|
|
1917
|
+
length: afterClose - startPos
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
content += inputStr[pos];
|
|
1922
|
+
pos++;
|
|
1923
|
+
}
|
|
1924
|
+
return null;
|
|
1925
|
+
}
|
|
1926
|
+
let parsedValue = null;
|
|
1927
|
+
let parsedLength = 0;
|
|
1507
1928
|
peg$result = peg$startRuleFunction();
|
|
1508
1929
|
const peg$success = peg$result !== peg$FAILED && peg$currPos === input.length;
|
|
1509
1930
|
function peg$throw() {
|
|
@@ -1532,27 +1953,39 @@ function peg$parse(input, options) {
|
|
|
1532
1953
|
|
|
1533
1954
|
// src/Parser.js
|
|
1534
1955
|
class Parser {
|
|
1535
|
-
constructor() {
|
|
1956
|
+
constructor(options = {}) {
|
|
1957
|
+
this.maxInputSize = options.maxInputSize || 10 * 1024 * 1024;
|
|
1958
|
+
this.maxDepth = options.maxDepth || 1000;
|
|
1959
|
+
}
|
|
1536
1960
|
parse(input) {
|
|
1961
|
+
if (typeof input !== "string") {
|
|
1962
|
+
throw new TypeError("Input must be a string");
|
|
1963
|
+
}
|
|
1964
|
+
if (input.length > this.maxInputSize) {
|
|
1965
|
+
throw new Error(`Input size exceeds maximum allowed size of ${this.maxInputSize} bytes`);
|
|
1966
|
+
}
|
|
1537
1967
|
try {
|
|
1538
1968
|
const rawResult = peg$parse(input);
|
|
1539
1969
|
return this.transformResult(rawResult);
|
|
1540
1970
|
} catch (error) {
|
|
1541
|
-
|
|
1971
|
+
const parseError = new Error(`Parse error: ${error.message}`);
|
|
1972
|
+
parseError.cause = error;
|
|
1973
|
+
parseError.location = error.location;
|
|
1974
|
+
throw parseError;
|
|
1542
1975
|
}
|
|
1543
1976
|
}
|
|
1544
1977
|
transformResult(rawResult) {
|
|
1545
1978
|
const links = [];
|
|
1546
1979
|
const items = Array.isArray(rawResult) ? rawResult : [rawResult];
|
|
1547
1980
|
for (const item of items) {
|
|
1548
|
-
if (item) {
|
|
1981
|
+
if (item !== null && item !== undefined) {
|
|
1549
1982
|
this.collectLinks(item, [], links);
|
|
1550
1983
|
}
|
|
1551
1984
|
}
|
|
1552
1985
|
return links;
|
|
1553
1986
|
}
|
|
1554
1987
|
collectLinks(item, parentPath, result) {
|
|
1555
|
-
if (
|
|
1988
|
+
if (item === null || item === undefined)
|
|
1556
1989
|
return;
|
|
1557
1990
|
if (item.children && item.children.length > 0) {
|
|
1558
1991
|
if (item.id && (!item.values || item.values.length === 0)) {
|
|
@@ -1609,7 +2042,7 @@ class Parser {
|
|
|
1609
2042
|
return combined;
|
|
1610
2043
|
}
|
|
1611
2044
|
transformLink(item) {
|
|
1612
|
-
if (
|
|
2045
|
+
if (item === null || item === undefined)
|
|
1613
2046
|
return null;
|
|
1614
2047
|
if (item instanceof Link) {
|
|
1615
2048
|
return item;
|
|
@@ -1625,9 +2058,39 @@ class Parser {
|
|
|
1625
2058
|
return new Link(item.id || null, []);
|
|
1626
2059
|
}
|
|
1627
2060
|
}
|
|
2061
|
+
// src/FormatOptions.js
|
|
2062
|
+
class FormatOptions {
|
|
2063
|
+
constructor(options = {}) {
|
|
2064
|
+
this.lessParentheses = options.lessParentheses ?? false;
|
|
2065
|
+
this.maxLineLength = options.maxLineLength ?? 80;
|
|
2066
|
+
this.indentLongLines = options.indentLongLines ?? false;
|
|
2067
|
+
this.maxInlineRefs = options.maxInlineRefs ?? null;
|
|
2068
|
+
this.groupConsecutive = options.groupConsecutive ?? false;
|
|
2069
|
+
this.indentString = options.indentString ?? " ";
|
|
2070
|
+
this.preferInline = options.preferInline ?? true;
|
|
2071
|
+
}
|
|
2072
|
+
shouldIndentByLength(line) {
|
|
2073
|
+
if (!this.indentLongLines) {
|
|
2074
|
+
return false;
|
|
2075
|
+
}
|
|
2076
|
+
return line.length > this.maxLineLength;
|
|
2077
|
+
}
|
|
2078
|
+
shouldIndentByRefCount(refCount) {
|
|
2079
|
+
if (this.maxInlineRefs === null) {
|
|
2080
|
+
return false;
|
|
2081
|
+
}
|
|
2082
|
+
return refCount > this.maxInlineRefs;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
// src/FormatConfig.js
|
|
2087
|
+
class FormatConfig extends FormatOptions {
|
|
2088
|
+
}
|
|
1628
2089
|
export {
|
|
1629
2090
|
formatLinks,
|
|
1630
2091
|
Parser,
|
|
1631
2092
|
LinksGroup,
|
|
1632
|
-
Link
|
|
2093
|
+
Link,
|
|
2094
|
+
FormatOptions,
|
|
2095
|
+
FormatConfig
|
|
1633
2096
|
};
|