links-notation 0.28.0 → 0.30.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/dist/index.js +216 -336
- package/package.json +7 -4
- package/src/Cst.js +9 -26
- package/src/ReferenceLiteral.js +22 -0
- package/src/StreamParser.js +33 -13
- package/src/comments.js +50 -11
- package/src/grammar.pegjs +4 -2
- package/src/parser-generated.js +110 -274
- package/src/quotes.js +13 -7
- package/tests/Comments.test.js +31 -0
- package/tests/StreamParser.test.js +13 -0
package/dist/index.js
CHANGED
|
@@ -66,10 +66,10 @@ function readReference(document, start) {
|
|
|
66
66
|
return reading(document, start, quote, count, end);
|
|
67
67
|
}
|
|
68
68
|
function reading(document, start, quote, count, end) {
|
|
69
|
-
const emptyReference = count % 2 === 0 ? { value: "", length: count } : null;
|
|
70
69
|
if (end === null) {
|
|
71
|
-
return
|
|
70
|
+
return count % 2 === 0 ? { value: "", length: count, closed: false } : null;
|
|
72
71
|
}
|
|
72
|
+
const emptyReference = count % 2 === 0 ? { value: "", length: count, closed: true } : null;
|
|
73
73
|
const parts = [];
|
|
74
74
|
let position = start + count;
|
|
75
75
|
let run = document.indexOf(quote, position);
|
|
@@ -86,7 +86,7 @@ function reading(document, start, quote, count, end) {
|
|
|
86
86
|
if (emptyReference !== null && !isSubstantiveBody(value)) {
|
|
87
87
|
return emptyReference;
|
|
88
88
|
}
|
|
89
|
-
return { value, length: end - start };
|
|
89
|
+
return { value, length: end - start, closed: true };
|
|
90
90
|
}
|
|
91
91
|
function runLength(text, start, quote) {
|
|
92
92
|
let end = start;
|
|
@@ -158,6 +158,23 @@ function isSubstantiveBody(content) {
|
|
|
158
158
|
function hasReferenceLiteralPrefix(text, start = 0) {
|
|
159
159
|
return /^~[0-9]+\{/.test(text.slice(start));
|
|
160
160
|
}
|
|
161
|
+
var LITERAL_PAYLOAD_END = new Set(["}", " ", "\t", "\r", `
|
|
162
|
+
`, "(", ")"]);
|
|
163
|
+
function referenceLiteralEnd(text, start) {
|
|
164
|
+
if (text[start] !== "~")
|
|
165
|
+
return -1;
|
|
166
|
+
let index = start + 1;
|
|
167
|
+
while (index < text.length && text[index] >= "0" && text[index] <= "9") {
|
|
168
|
+
index++;
|
|
169
|
+
}
|
|
170
|
+
if (index === start + 1 || text[index] !== "{")
|
|
171
|
+
return -1;
|
|
172
|
+
index++;
|
|
173
|
+
while (index < text.length && !LITERAL_PAYLOAD_END.has(text[index])) {
|
|
174
|
+
index++;
|
|
175
|
+
}
|
|
176
|
+
return text[index] === "}" ? index + 1 : -1;
|
|
177
|
+
}
|
|
161
178
|
function encodeReferenceLiteral(text) {
|
|
162
179
|
if (typeof text !== "string" || !text.isWellFormed()) {
|
|
163
180
|
throw new TypeError("Reference must be well-formed Unicode text");
|
|
@@ -481,21 +498,17 @@ function formatLinks(links, lessParentheses = false) {
|
|
|
481
498
|
}
|
|
482
499
|
// src/comments.js
|
|
483
500
|
var COMMENT = "#";
|
|
484
|
-
var
|
|
485
|
-
`, "\r", "(", ":"];
|
|
501
|
+
var SEPARATORS = [" ", "\t", `
|
|
502
|
+
`, "\r", "(", ":", ")"];
|
|
486
503
|
var BEFORE_COMMENT = [" ", "\t", `
|
|
487
504
|
`, "\r"];
|
|
488
505
|
function stripComments(document) {
|
|
489
506
|
let blanked = null;
|
|
490
507
|
let position = 0;
|
|
508
|
+
let tokenStart = true;
|
|
491
509
|
const references = new DelimitedReferences(document);
|
|
492
510
|
while (position < document.length) {
|
|
493
511
|
const character = document[position];
|
|
494
|
-
if (QUOTES.includes(character) && follows(document, position, BEFORE_REFERENCE)) {
|
|
495
|
-
const end = references.endAt(position);
|
|
496
|
-
position = end === null ? position + 1 : end;
|
|
497
|
-
continue;
|
|
498
|
-
}
|
|
499
512
|
if (character === COMMENT && follows(document, position, BEFORE_COMMENT)) {
|
|
500
513
|
blanked = blanked ?? document.split("");
|
|
501
514
|
while (position < document.length && document[position] !== `
|
|
@@ -505,10 +518,30 @@ function stripComments(document) {
|
|
|
505
518
|
}
|
|
506
519
|
continue;
|
|
507
520
|
}
|
|
521
|
+
if (SEPARATORS.includes(character)) {
|
|
522
|
+
tokenStart = true;
|
|
523
|
+
position++;
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (tokenStart) {
|
|
527
|
+
const end = delimitedTokenEnd(document, position, references);
|
|
528
|
+
if (end !== null) {
|
|
529
|
+
position = end;
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
tokenStart = false;
|
|
508
534
|
position++;
|
|
509
535
|
}
|
|
510
536
|
return blanked === null ? document : blanked.join("");
|
|
511
537
|
}
|
|
538
|
+
function delimitedTokenEnd(document, start, references) {
|
|
539
|
+
const literal = referenceLiteralEnd(document, start);
|
|
540
|
+
if (literal !== -1) {
|
|
541
|
+
return literal;
|
|
542
|
+
}
|
|
543
|
+
return QUOTES.includes(document[start]) ? references.endAt(start) : null;
|
|
544
|
+
}
|
|
512
545
|
function follows(document, position, allowed) {
|
|
513
546
|
return position === 0 || allowed.includes(document[position - 1]);
|
|
514
547
|
}
|
|
@@ -569,28 +602,11 @@ var ESCAPES = {
|
|
|
569
602
|
function quoteText(text) {
|
|
570
603
|
return `"${text.replace(/[\\"\n\r\t]/g, (character) => ESCAPES[character])}"`;
|
|
571
604
|
}
|
|
572
|
-
var LITERAL_PAYLOAD_END = new Set(["}", " ", "\t", "\r", `
|
|
573
|
-
`, "(", ")"]);
|
|
574
|
-
function literalEnd(text, start) {
|
|
575
|
-
if (text[start] !== "~")
|
|
576
|
-
return -1;
|
|
577
|
-
let index = start + 1;
|
|
578
|
-
while (index < text.length && text[index] >= "0" && text[index] <= "9") {
|
|
579
|
-
index++;
|
|
580
|
-
}
|
|
581
|
-
if (index === start + 1 || text[index] !== "{")
|
|
582
|
-
return -1;
|
|
583
|
-
index++;
|
|
584
|
-
while (index < text.length && !LITERAL_PAYLOAD_END.has(text[index])) {
|
|
585
|
-
index++;
|
|
586
|
-
}
|
|
587
|
-
return text[index] === "}" ? index + 1 : -1;
|
|
588
|
-
}
|
|
589
605
|
var BARE_REFERENCE_END = new Set([" ", "\t", "\r", `
|
|
590
606
|
`, "(", ":", ")"]);
|
|
591
607
|
function buildCst(input, { comments = true } = {}) {
|
|
592
608
|
const prepared = comments ? stripComments(input) : input;
|
|
593
|
-
const references = new DelimitedReferences(
|
|
609
|
+
const references = new DelimitedReferences(input);
|
|
594
610
|
const document = new CstNode(CstKind.DOCUMENT);
|
|
595
611
|
const containers = [{ node: document, line: null }];
|
|
596
612
|
const add = (token) => {
|
|
@@ -654,7 +670,7 @@ function buildCst(input, { comments = true } = {}) {
|
|
|
654
670
|
return document;
|
|
655
671
|
}
|
|
656
672
|
function referenceEnd(prepared, start, references) {
|
|
657
|
-
const literal =
|
|
673
|
+
const literal = referenceLiteralEnd(prepared, start);
|
|
658
674
|
if (literal !== -1)
|
|
659
675
|
return literal;
|
|
660
676
|
if (QUOTES.includes(prepared[start])) {
|
|
@@ -668,7 +684,7 @@ function referenceEnd(prepared, start, references) {
|
|
|
668
684
|
return end;
|
|
669
685
|
}
|
|
670
686
|
function isLiteral(prepared, start, end) {
|
|
671
|
-
return
|
|
687
|
+
return referenceLiteralEnd(prepared, start) === end;
|
|
672
688
|
}
|
|
673
689
|
// src/LinksGroup.js
|
|
674
690
|
class LinksGroup {
|
|
@@ -823,11 +839,14 @@ class peg$SyntaxError extends SyntaxError {
|
|
|
823
839
|
}
|
|
824
840
|
return s;
|
|
825
841
|
}
|
|
842
|
+
function escape(s, special) {
|
|
843
|
+
return unicodeEscape(s.replace(special, "\\$&").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch)));
|
|
844
|
+
}
|
|
826
845
|
function literalEscape(s) {
|
|
827
|
-
return
|
|
846
|
+
return escape(s, /[\\"]/g);
|
|
828
847
|
}
|
|
829
848
|
function classEscape(s) {
|
|
830
|
-
return
|
|
849
|
+
return escape(s, /[\\\]^-]/g);
|
|
831
850
|
}
|
|
832
851
|
const DESCRIBE_EXPECTATION_FNS = {
|
|
833
852
|
literal(expectation) {
|
|
@@ -896,12 +915,6 @@ function peg$parse(input, options) {
|
|
|
896
915
|
const peg$c7 = "'";
|
|
897
916
|
const peg$c8 = "`";
|
|
898
917
|
const peg$c9 = " ";
|
|
899
|
-
const peg$r0 = /^[ \t]/;
|
|
900
|
-
const peg$r1 = /^[\r\n]/;
|
|
901
|
-
const peg$r2 = /^[0-9]/;
|
|
902
|
-
const peg$r3 = /^[^} \t\r\n()]/;
|
|
903
|
-
const peg$r4 = /^[ \t\n\r]/;
|
|
904
|
-
const peg$r5 = /^[^ \t\n\r(:)]/;
|
|
905
918
|
const peg$e0 = peg$classExpectation([" ", "\t"], false, false, false);
|
|
906
919
|
const peg$e1 = peg$classExpectation(["\r", `
|
|
907
920
|
`], false, false, false);
|
|
@@ -1125,6 +1138,7 @@ function peg$parse(input, options) {
|
|
|
1125
1138
|
let peg$maxFailExpected = options.peg$maxFailExpected || [];
|
|
1126
1139
|
let peg$silentFails = options.peg$silentFails | 0;
|
|
1127
1140
|
let peg$result;
|
|
1141
|
+
let peg$charCode;
|
|
1128
1142
|
if (options.startRule) {
|
|
1129
1143
|
if (!(options.startRule in peg$startRuleFunctions)) {
|
|
1130
1144
|
throw new Error(`Can't start parsing from rule "` + options.startRule + '".');
|
|
@@ -1305,62 +1319,12 @@ function peg$parse(input, options) {
|
|
|
1305
1319
|
function peg$parseskipEmptyLines() {
|
|
1306
1320
|
let s0, s1, s2, s3;
|
|
1307
1321
|
s0 = [];
|
|
1308
|
-
|
|
1309
|
-
s2 = [];
|
|
1310
|
-
s3 = input.charAt(peg$currPos);
|
|
1311
|
-
if (peg$r0.test(s3)) {
|
|
1312
|
-
peg$currPos++;
|
|
1313
|
-
} else {
|
|
1314
|
-
s3 = peg$FAILED;
|
|
1315
|
-
if (peg$silentFails === 0) {
|
|
1316
|
-
peg$fail(peg$e0);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
while (s3 !== peg$FAILED) {
|
|
1320
|
-
s2.push(s3);
|
|
1321
|
-
s3 = input.charAt(peg$currPos);
|
|
1322
|
-
if (peg$r0.test(s3)) {
|
|
1323
|
-
peg$currPos++;
|
|
1324
|
-
} else {
|
|
1325
|
-
s3 = peg$FAILED;
|
|
1326
|
-
if (peg$silentFails === 0) {
|
|
1327
|
-
peg$fail(peg$e0);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
s3 = input.charAt(peg$currPos);
|
|
1332
|
-
if (peg$r1.test(s3)) {
|
|
1333
|
-
peg$currPos++;
|
|
1334
|
-
} else {
|
|
1335
|
-
s3 = peg$FAILED;
|
|
1336
|
-
if (peg$silentFails === 0) {
|
|
1337
|
-
peg$fail(peg$e1);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
if (s3 !== peg$FAILED) {
|
|
1341
|
-
s2 = [s2, s3];
|
|
1342
|
-
s1 = s2;
|
|
1343
|
-
} else {
|
|
1344
|
-
peg$currPos = s1;
|
|
1345
|
-
s1 = peg$FAILED;
|
|
1346
|
-
}
|
|
1347
|
-
while (s1 !== peg$FAILED) {
|
|
1348
|
-
s0.push(s1);
|
|
1322
|
+
for (;; ) {
|
|
1349
1323
|
s1 = peg$currPos;
|
|
1350
1324
|
s2 = [];
|
|
1351
|
-
|
|
1352
|
-
if (peg$r0.test(s3)) {
|
|
1353
|
-
peg$currPos++;
|
|
1354
|
-
} else {
|
|
1355
|
-
s3 = peg$FAILED;
|
|
1356
|
-
if (peg$silentFails === 0) {
|
|
1357
|
-
peg$fail(peg$e0);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
while (s3 !== peg$FAILED) {
|
|
1361
|
-
s2.push(s3);
|
|
1325
|
+
for (;; ) {
|
|
1362
1326
|
s3 = input.charAt(peg$currPos);
|
|
1363
|
-
if (peg$
|
|
1327
|
+
if (peg$charCode = s3.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9) {
|
|
1364
1328
|
peg$currPos++;
|
|
1365
1329
|
} else {
|
|
1366
1330
|
s3 = peg$FAILED;
|
|
@@ -1368,9 +1332,13 @@ function peg$parse(input, options) {
|
|
|
1368
1332
|
peg$fail(peg$e0);
|
|
1369
1333
|
}
|
|
1370
1334
|
}
|
|
1335
|
+
if (s3 === peg$FAILED) {
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1338
|
+
s2.push(s3);
|
|
1371
1339
|
}
|
|
1372
1340
|
s3 = input.charAt(peg$currPos);
|
|
1373
|
-
if (peg$
|
|
1341
|
+
if (peg$charCode = s3.charCodeAt(0), peg$charCode === 13 || peg$charCode === 10) {
|
|
1374
1342
|
peg$currPos++;
|
|
1375
1343
|
} else {
|
|
1376
1344
|
s3 = peg$FAILED;
|
|
@@ -1385,6 +1353,10 @@ function peg$parse(input, options) {
|
|
|
1385
1353
|
peg$currPos = s1;
|
|
1386
1354
|
s1 = peg$FAILED;
|
|
1387
1355
|
}
|
|
1356
|
+
if (s1 === peg$FAILED) {
|
|
1357
|
+
break;
|
|
1358
|
+
}
|
|
1359
|
+
s0.push(s1);
|
|
1388
1360
|
}
|
|
1389
1361
|
return s0;
|
|
1390
1362
|
}
|
|
@@ -1394,10 +1366,12 @@ function peg$parse(input, options) {
|
|
|
1394
1366
|
s1 = peg$parsefirstLine();
|
|
1395
1367
|
if (s1 !== peg$FAILED) {
|
|
1396
1368
|
s2 = [];
|
|
1397
|
-
|
|
1398
|
-
while (s3 !== peg$FAILED) {
|
|
1399
|
-
s2.push(s3);
|
|
1369
|
+
for (;; ) {
|
|
1400
1370
|
s3 = peg$parseline();
|
|
1371
|
+
if (s3 === peg$FAILED) {
|
|
1372
|
+
break;
|
|
1373
|
+
}
|
|
1374
|
+
s2.push(s3);
|
|
1401
1375
|
}
|
|
1402
1376
|
peg$savedPos = s0;
|
|
1403
1377
|
s0 = peg$f4(s1, s2);
|
|
@@ -1649,10 +1623,12 @@ function peg$parse(input, options) {
|
|
|
1649
1623
|
if (s0 === peg$FAILED) {
|
|
1650
1624
|
s0 = peg$currPos;
|
|
1651
1625
|
s1 = [];
|
|
1652
|
-
|
|
1653
|
-
while (s2 !== peg$FAILED) {
|
|
1654
|
-
s1.push(s2);
|
|
1626
|
+
for (;; ) {
|
|
1655
1627
|
s2 = peg$parsesingleLineValueAndWhitespace();
|
|
1628
|
+
if (s2 === peg$FAILED) {
|
|
1629
|
+
break;
|
|
1630
|
+
}
|
|
1631
|
+
s1.push(s2);
|
|
1656
1632
|
}
|
|
1657
1633
|
s2 = peg$parseeol();
|
|
1658
1634
|
if (s2 !== peg$FAILED) {
|
|
@@ -1864,13 +1840,14 @@ function peg$parse(input, options) {
|
|
|
1864
1840
|
let s0, s1, s2;
|
|
1865
1841
|
s0 = peg$currPos;
|
|
1866
1842
|
s1 = [];
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
s2 = peg$parsesingleLineValueAndWhitespace();
|
|
1843
|
+
for (;; ) {
|
|
1844
|
+
s2 = peg$parsesingleLineValueAndWhitespace();
|
|
1845
|
+
if (s2 === peg$FAILED) {
|
|
1846
|
+
break;
|
|
1872
1847
|
}
|
|
1873
|
-
|
|
1848
|
+
s1.push(s2);
|
|
1849
|
+
}
|
|
1850
|
+
if (s1.length < 1) {
|
|
1874
1851
|
s1 = peg$FAILED;
|
|
1875
1852
|
}
|
|
1876
1853
|
if (s1 !== peg$FAILED) {
|
|
@@ -2025,29 +2002,22 @@ function peg$parse(input, options) {
|
|
|
2025
2002
|
}
|
|
2026
2003
|
if (s5 !== peg$FAILED) {
|
|
2027
2004
|
s6 = [];
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
peg$
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
}
|
|
2037
|
-
if (s7 !== peg$FAILED) {
|
|
2038
|
-
while (s7 !== peg$FAILED) {
|
|
2039
|
-
s6.push(s7);
|
|
2040
|
-
s7 = input.charAt(peg$currPos);
|
|
2041
|
-
if (peg$r2.test(s7)) {
|
|
2042
|
-
peg$currPos++;
|
|
2043
|
-
} else {
|
|
2044
|
-
s7 = peg$FAILED;
|
|
2045
|
-
if (peg$silentFails === 0) {
|
|
2046
|
-
peg$fail(peg$e7);
|
|
2047
|
-
}
|
|
2005
|
+
for (;; ) {
|
|
2006
|
+
s7 = input.charAt(peg$currPos);
|
|
2007
|
+
if (peg$charCode = s7.charCodeAt(0), peg$charCode >= 48 && peg$charCode <= 57) {
|
|
2008
|
+
peg$currPos++;
|
|
2009
|
+
} else {
|
|
2010
|
+
s7 = peg$FAILED;
|
|
2011
|
+
if (peg$silentFails === 0) {
|
|
2012
|
+
peg$fail(peg$e7);
|
|
2048
2013
|
}
|
|
2049
2014
|
}
|
|
2050
|
-
|
|
2015
|
+
if (s7 === peg$FAILED) {
|
|
2016
|
+
break;
|
|
2017
|
+
}
|
|
2018
|
+
s6.push(s7);
|
|
2019
|
+
}
|
|
2020
|
+
if (s6.length < 1) {
|
|
2051
2021
|
s6 = peg$FAILED;
|
|
2052
2022
|
}
|
|
2053
2023
|
if (s6 !== peg$FAILED) {
|
|
@@ -2062,19 +2032,9 @@ function peg$parse(input, options) {
|
|
|
2062
2032
|
}
|
|
2063
2033
|
if (s7 !== peg$FAILED) {
|
|
2064
2034
|
s8 = [];
|
|
2065
|
-
|
|
2066
|
-
if (peg$r3.test(s9)) {
|
|
2067
|
-
peg$currPos++;
|
|
2068
|
-
} else {
|
|
2069
|
-
s9 = peg$FAILED;
|
|
2070
|
-
if (peg$silentFails === 0) {
|
|
2071
|
-
peg$fail(peg$e9);
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
while (s9 !== peg$FAILED) {
|
|
2075
|
-
s8.push(s9);
|
|
2035
|
+
for (;; ) {
|
|
2076
2036
|
s9 = input.charAt(peg$currPos);
|
|
2077
|
-
if (peg$
|
|
2037
|
+
if (s9 !== "" && !(peg$charCode = s9.charCodeAt(0), peg$charCode === 125 || peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 13 || peg$charCode === 10 || peg$charCode === 40 || peg$charCode === 41)) {
|
|
2078
2038
|
peg$currPos++;
|
|
2079
2039
|
} else {
|
|
2080
2040
|
s9 = peg$FAILED;
|
|
@@ -2082,6 +2042,10 @@ function peg$parse(input, options) {
|
|
|
2082
2042
|
peg$fail(peg$e9);
|
|
2083
2043
|
}
|
|
2084
2044
|
}
|
|
2045
|
+
if (s9 === peg$FAILED) {
|
|
2046
|
+
break;
|
|
2047
|
+
}
|
|
2048
|
+
s8.push(s9);
|
|
2085
2049
|
}
|
|
2086
2050
|
if (input.charCodeAt(peg$currPos) === 125) {
|
|
2087
2051
|
s9 = peg$c5;
|
|
@@ -2145,13 +2109,14 @@ function peg$parse(input, options) {
|
|
|
2145
2109
|
}
|
|
2146
2110
|
if (s1 !== peg$FAILED) {
|
|
2147
2111
|
s2 = [];
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
s3 = peg$parsereferenceSymbol();
|
|
2112
|
+
for (;; ) {
|
|
2113
|
+
s3 = peg$parsereferenceSymbol();
|
|
2114
|
+
if (s3 === peg$FAILED) {
|
|
2115
|
+
break;
|
|
2153
2116
|
}
|
|
2154
|
-
|
|
2117
|
+
s2.push(s3);
|
|
2118
|
+
}
|
|
2119
|
+
if (s2.length < 1) {
|
|
2155
2120
|
s2 = peg$FAILED;
|
|
2156
2121
|
}
|
|
2157
2122
|
if (s2 !== peg$FAILED) {
|
|
@@ -2240,10 +2205,12 @@ function peg$parse(input, options) {
|
|
|
2240
2205
|
}
|
|
2241
2206
|
if (s1 !== peg$FAILED) {
|
|
2242
2207
|
s2 = [];
|
|
2243
|
-
|
|
2244
|
-
while (s3 !== peg$FAILED) {
|
|
2245
|
-
s2.push(s3);
|
|
2208
|
+
for (;; ) {
|
|
2246
2209
|
s3 = peg$parseconsumeDoubleMore();
|
|
2210
|
+
if (s3 === peg$FAILED) {
|
|
2211
|
+
break;
|
|
2212
|
+
}
|
|
2213
|
+
s2.push(s3);
|
|
2247
2214
|
}
|
|
2248
2215
|
peg$savedPos = s0;
|
|
2249
2216
|
s0 = peg$f36(s1, s2);
|
|
@@ -2348,10 +2315,12 @@ function peg$parse(input, options) {
|
|
|
2348
2315
|
}
|
|
2349
2316
|
if (s1 !== peg$FAILED) {
|
|
2350
2317
|
s2 = [];
|
|
2351
|
-
|
|
2352
|
-
while (s3 !== peg$FAILED) {
|
|
2353
|
-
s2.push(s3);
|
|
2318
|
+
for (;; ) {
|
|
2354
2319
|
s3 = peg$parseconsumeSingleMore();
|
|
2320
|
+
if (s3 === peg$FAILED) {
|
|
2321
|
+
break;
|
|
2322
|
+
}
|
|
2323
|
+
s2.push(s3);
|
|
2355
2324
|
}
|
|
2356
2325
|
peg$savedPos = s0;
|
|
2357
2326
|
s0 = peg$f41(s1, s2);
|
|
@@ -2456,10 +2425,12 @@ function peg$parse(input, options) {
|
|
|
2456
2425
|
}
|
|
2457
2426
|
if (s1 !== peg$FAILED) {
|
|
2458
2427
|
s2 = [];
|
|
2459
|
-
|
|
2460
|
-
while (s3 !== peg$FAILED) {
|
|
2461
|
-
s2.push(s3);
|
|
2428
|
+
for (;; ) {
|
|
2462
2429
|
s3 = peg$parseconsumeBacktickMore();
|
|
2430
|
+
if (s3 === peg$FAILED) {
|
|
2431
|
+
break;
|
|
2432
|
+
}
|
|
2433
|
+
s2.push(s3);
|
|
2463
2434
|
}
|
|
2464
2435
|
peg$savedPos = s0;
|
|
2465
2436
|
s0 = peg$f46(s1, s2);
|
|
@@ -2515,17 +2486,7 @@ function peg$parse(input, options) {
|
|
|
2515
2486
|
let s0, s1, s2;
|
|
2516
2487
|
s0 = peg$currPos;
|
|
2517
2488
|
s1 = [];
|
|
2518
|
-
|
|
2519
|
-
s2 = peg$c9;
|
|
2520
|
-
peg$currPos++;
|
|
2521
|
-
} else {
|
|
2522
|
-
s2 = peg$FAILED;
|
|
2523
|
-
if (peg$silentFails === 0) {
|
|
2524
|
-
peg$fail(peg$e14);
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
while (s2 !== peg$FAILED) {
|
|
2528
|
-
s1.push(s2);
|
|
2489
|
+
for (;; ) {
|
|
2529
2490
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2530
2491
|
s2 = peg$c9;
|
|
2531
2492
|
peg$currPos++;
|
|
@@ -2535,6 +2496,10 @@ function peg$parse(input, options) {
|
|
|
2535
2496
|
peg$fail(peg$e14);
|
|
2536
2497
|
}
|
|
2537
2498
|
}
|
|
2499
|
+
if (s2 === peg$FAILED) {
|
|
2500
|
+
break;
|
|
2501
|
+
}
|
|
2502
|
+
s1.push(s2);
|
|
2538
2503
|
}
|
|
2539
2504
|
peg$savedPos = s0;
|
|
2540
2505
|
s1 = peg$f50(s1);
|
|
@@ -2545,17 +2510,7 @@ function peg$parse(input, options) {
|
|
|
2545
2510
|
let s0, s1, s2;
|
|
2546
2511
|
s0 = peg$currPos;
|
|
2547
2512
|
s1 = [];
|
|
2548
|
-
|
|
2549
|
-
s2 = peg$c9;
|
|
2550
|
-
peg$currPos++;
|
|
2551
|
-
} else {
|
|
2552
|
-
s2 = peg$FAILED;
|
|
2553
|
-
if (peg$silentFails === 0) {
|
|
2554
|
-
peg$fail(peg$e14);
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
while (s2 !== peg$FAILED) {
|
|
2558
|
-
s1.push(s2);
|
|
2513
|
+
for (;; ) {
|
|
2559
2514
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2560
2515
|
s2 = peg$c9;
|
|
2561
2516
|
peg$currPos++;
|
|
@@ -2565,6 +2520,10 @@ function peg$parse(input, options) {
|
|
|
2565
2520
|
peg$fail(peg$e14);
|
|
2566
2521
|
}
|
|
2567
2522
|
}
|
|
2523
|
+
if (s2 === peg$FAILED) {
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
s1.push(s2);
|
|
2568
2527
|
}
|
|
2569
2528
|
peg$savedPos = peg$currPos;
|
|
2570
2529
|
s2 = peg$f51(s1);
|
|
@@ -2586,17 +2545,7 @@ function peg$parse(input, options) {
|
|
|
2586
2545
|
let s0, s1, s2;
|
|
2587
2546
|
s0 = peg$currPos;
|
|
2588
2547
|
s1 = [];
|
|
2589
|
-
|
|
2590
|
-
s2 = peg$c9;
|
|
2591
|
-
peg$currPos++;
|
|
2592
|
-
} else {
|
|
2593
|
-
s2 = peg$FAILED;
|
|
2594
|
-
if (peg$silentFails === 0) {
|
|
2595
|
-
peg$fail(peg$e14);
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
while (s2 !== peg$FAILED) {
|
|
2599
|
-
s1.push(s2);
|
|
2548
|
+
for (;; ) {
|
|
2600
2549
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2601
2550
|
s2 = peg$c9;
|
|
2602
2551
|
peg$currPos++;
|
|
@@ -2606,6 +2555,10 @@ function peg$parse(input, options) {
|
|
|
2606
2555
|
peg$fail(peg$e14);
|
|
2607
2556
|
}
|
|
2608
2557
|
}
|
|
2558
|
+
if (s2 === peg$FAILED) {
|
|
2559
|
+
break;
|
|
2560
|
+
}
|
|
2561
|
+
s1.push(s2);
|
|
2609
2562
|
}
|
|
2610
2563
|
peg$savedPos = peg$currPos;
|
|
2611
2564
|
s2 = peg$f53(s1);
|
|
@@ -2647,49 +2600,32 @@ function peg$parse(input, options) {
|
|
|
2647
2600
|
let s0, s1, s2, s3, s4, s5, s6;
|
|
2648
2601
|
s0 = peg$currPos;
|
|
2649
2602
|
s1 = [];
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
peg$
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
}
|
|
2659
|
-
if (s2 !== peg$FAILED) {
|
|
2660
|
-
while (s2 !== peg$FAILED) {
|
|
2661
|
-
s1.push(s2);
|
|
2662
|
-
s2 = input.charAt(peg$currPos);
|
|
2663
|
-
if (peg$r1.test(s2)) {
|
|
2664
|
-
peg$currPos++;
|
|
2665
|
-
} else {
|
|
2666
|
-
s2 = peg$FAILED;
|
|
2667
|
-
if (peg$silentFails === 0) {
|
|
2668
|
-
peg$fail(peg$e1);
|
|
2669
|
-
}
|
|
2603
|
+
for (;; ) {
|
|
2604
|
+
s2 = input.charAt(peg$currPos);
|
|
2605
|
+
if (peg$charCode = s2.charCodeAt(0), peg$charCode === 13 || peg$charCode === 10) {
|
|
2606
|
+
peg$currPos++;
|
|
2607
|
+
} else {
|
|
2608
|
+
s2 = peg$FAILED;
|
|
2609
|
+
if (peg$silentFails === 0) {
|
|
2610
|
+
peg$fail(peg$e1);
|
|
2670
2611
|
}
|
|
2671
2612
|
}
|
|
2672
|
-
|
|
2613
|
+
if (s2 === peg$FAILED) {
|
|
2614
|
+
break;
|
|
2615
|
+
}
|
|
2616
|
+
s1.push(s2);
|
|
2617
|
+
}
|
|
2618
|
+
if (s1.length < 1) {
|
|
2673
2619
|
s1 = peg$FAILED;
|
|
2674
2620
|
}
|
|
2675
2621
|
if (s1 !== peg$FAILED) {
|
|
2676
2622
|
s2 = [];
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
peg$currPos++;
|
|
2682
|
-
} else {
|
|
2683
|
-
s5 = peg$FAILED;
|
|
2684
|
-
if (peg$silentFails === 0) {
|
|
2685
|
-
peg$fail(peg$e0);
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
if (s5 !== peg$FAILED) {
|
|
2689
|
-
while (s5 !== peg$FAILED) {
|
|
2690
|
-
s4.push(s5);
|
|
2623
|
+
for (;; ) {
|
|
2624
|
+
s3 = peg$currPos;
|
|
2625
|
+
s4 = [];
|
|
2626
|
+
for (;; ) {
|
|
2691
2627
|
s5 = input.charAt(peg$currPos);
|
|
2692
|
-
if (peg$
|
|
2628
|
+
if (peg$charCode = s5.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9) {
|
|
2693
2629
|
peg$currPos++;
|
|
2694
2630
|
} else {
|
|
2695
2631
|
s5 = peg$FAILED;
|
|
@@ -2697,26 +2633,19 @@ function peg$parse(input, options) {
|
|
|
2697
2633
|
peg$fail(peg$e0);
|
|
2698
2634
|
}
|
|
2699
2635
|
}
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
s4 = peg$FAILED;
|
|
2703
|
-
}
|
|
2704
|
-
if (s4 !== peg$FAILED) {
|
|
2705
|
-
s5 = [];
|
|
2706
|
-
s6 = input.charAt(peg$currPos);
|
|
2707
|
-
if (peg$r1.test(s6)) {
|
|
2708
|
-
peg$currPos++;
|
|
2709
|
-
} else {
|
|
2710
|
-
s6 = peg$FAILED;
|
|
2711
|
-
if (peg$silentFails === 0) {
|
|
2712
|
-
peg$fail(peg$e1);
|
|
2636
|
+
if (s5 === peg$FAILED) {
|
|
2637
|
+
break;
|
|
2713
2638
|
}
|
|
2639
|
+
s4.push(s5);
|
|
2714
2640
|
}
|
|
2715
|
-
if (
|
|
2716
|
-
|
|
2717
|
-
|
|
2641
|
+
if (s4.length < 1) {
|
|
2642
|
+
s4 = peg$FAILED;
|
|
2643
|
+
}
|
|
2644
|
+
if (s4 !== peg$FAILED) {
|
|
2645
|
+
s5 = [];
|
|
2646
|
+
for (;; ) {
|
|
2718
2647
|
s6 = input.charAt(peg$currPos);
|
|
2719
|
-
if (peg$
|
|
2648
|
+
if (peg$charCode = s6.charCodeAt(0), peg$charCode === 13 || peg$charCode === 10) {
|
|
2720
2649
|
peg$currPos++;
|
|
2721
2650
|
} else {
|
|
2722
2651
|
s6 = peg$FAILED;
|
|
@@ -2724,75 +2653,12 @@ function peg$parse(input, options) {
|
|
|
2724
2653
|
peg$fail(peg$e1);
|
|
2725
2654
|
}
|
|
2726
2655
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
s5 = peg$FAILED;
|
|
2730
|
-
}
|
|
2731
|
-
if (s5 !== peg$FAILED) {
|
|
2732
|
-
s4 = [s4, s5];
|
|
2733
|
-
s3 = s4;
|
|
2734
|
-
} else {
|
|
2735
|
-
peg$currPos = s3;
|
|
2736
|
-
s3 = peg$FAILED;
|
|
2737
|
-
}
|
|
2738
|
-
} else {
|
|
2739
|
-
peg$currPos = s3;
|
|
2740
|
-
s3 = peg$FAILED;
|
|
2741
|
-
}
|
|
2742
|
-
while (s3 !== peg$FAILED) {
|
|
2743
|
-
s2.push(s3);
|
|
2744
|
-
s3 = peg$currPos;
|
|
2745
|
-
s4 = [];
|
|
2746
|
-
s5 = input.charAt(peg$currPos);
|
|
2747
|
-
if (peg$r0.test(s5)) {
|
|
2748
|
-
peg$currPos++;
|
|
2749
|
-
} else {
|
|
2750
|
-
s5 = peg$FAILED;
|
|
2751
|
-
if (peg$silentFails === 0) {
|
|
2752
|
-
peg$fail(peg$e0);
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
if (s5 !== peg$FAILED) {
|
|
2756
|
-
while (s5 !== peg$FAILED) {
|
|
2757
|
-
s4.push(s5);
|
|
2758
|
-
s5 = input.charAt(peg$currPos);
|
|
2759
|
-
if (peg$r0.test(s5)) {
|
|
2760
|
-
peg$currPos++;
|
|
2761
|
-
} else {
|
|
2762
|
-
s5 = peg$FAILED;
|
|
2763
|
-
if (peg$silentFails === 0) {
|
|
2764
|
-
peg$fail(peg$e0);
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
|
-
} else {
|
|
2769
|
-
s4 = peg$FAILED;
|
|
2770
|
-
}
|
|
2771
|
-
if (s4 !== peg$FAILED) {
|
|
2772
|
-
s5 = [];
|
|
2773
|
-
s6 = input.charAt(peg$currPos);
|
|
2774
|
-
if (peg$r1.test(s6)) {
|
|
2775
|
-
peg$currPos++;
|
|
2776
|
-
} else {
|
|
2777
|
-
s6 = peg$FAILED;
|
|
2778
|
-
if (peg$silentFails === 0) {
|
|
2779
|
-
peg$fail(peg$e1);
|
|
2656
|
+
if (s6 === peg$FAILED) {
|
|
2657
|
+
break;
|
|
2780
2658
|
}
|
|
2659
|
+
s5.push(s6);
|
|
2781
2660
|
}
|
|
2782
|
-
if (
|
|
2783
|
-
while (s6 !== peg$FAILED) {
|
|
2784
|
-
s5.push(s6);
|
|
2785
|
-
s6 = input.charAt(peg$currPos);
|
|
2786
|
-
if (peg$r1.test(s6)) {
|
|
2787
|
-
peg$currPos++;
|
|
2788
|
-
} else {
|
|
2789
|
-
s6 = peg$FAILED;
|
|
2790
|
-
if (peg$silentFails === 0) {
|
|
2791
|
-
peg$fail(peg$e1);
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
} else {
|
|
2661
|
+
if (s5.length < 1) {
|
|
2796
2662
|
s5 = peg$FAILED;
|
|
2797
2663
|
}
|
|
2798
2664
|
if (s5 !== peg$FAILED) {
|
|
@@ -2806,6 +2672,10 @@ function peg$parse(input, options) {
|
|
|
2806
2672
|
peg$currPos = s3;
|
|
2807
2673
|
s3 = peg$FAILED;
|
|
2808
2674
|
}
|
|
2675
|
+
if (s3 === peg$FAILED) {
|
|
2676
|
+
break;
|
|
2677
|
+
}
|
|
2678
|
+
s2.push(s3);
|
|
2809
2679
|
}
|
|
2810
2680
|
s1 = [s1, s2];
|
|
2811
2681
|
s0 = s1;
|
|
@@ -2882,19 +2752,9 @@ function peg$parse(input, options) {
|
|
|
2882
2752
|
function peg$parse__() {
|
|
2883
2753
|
let s0, s1;
|
|
2884
2754
|
s0 = [];
|
|
2885
|
-
|
|
2886
|
-
if (peg$r0.test(s1)) {
|
|
2887
|
-
peg$currPos++;
|
|
2888
|
-
} else {
|
|
2889
|
-
s1 = peg$FAILED;
|
|
2890
|
-
if (peg$silentFails === 0) {
|
|
2891
|
-
peg$fail(peg$e0);
|
|
2892
|
-
}
|
|
2893
|
-
}
|
|
2894
|
-
while (s1 !== peg$FAILED) {
|
|
2895
|
-
s0.push(s1);
|
|
2755
|
+
for (;; ) {
|
|
2896
2756
|
s1 = input.charAt(peg$currPos);
|
|
2897
|
-
if (peg$
|
|
2757
|
+
if (peg$charCode = s1.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9) {
|
|
2898
2758
|
peg$currPos++;
|
|
2899
2759
|
} else {
|
|
2900
2760
|
s1 = peg$FAILED;
|
|
@@ -2902,23 +2762,29 @@ function peg$parse(input, options) {
|
|
|
2902
2762
|
peg$fail(peg$e0);
|
|
2903
2763
|
}
|
|
2904
2764
|
}
|
|
2765
|
+
if (s1 === peg$FAILED) {
|
|
2766
|
+
break;
|
|
2767
|
+
}
|
|
2768
|
+
s0.push(s1);
|
|
2905
2769
|
}
|
|
2906
2770
|
return s0;
|
|
2907
2771
|
}
|
|
2908
2772
|
function peg$parse_() {
|
|
2909
2773
|
let s0, s1;
|
|
2910
2774
|
s0 = [];
|
|
2911
|
-
|
|
2912
|
-
while (s1 !== peg$FAILED) {
|
|
2913
|
-
s0.push(s1);
|
|
2775
|
+
for (;; ) {
|
|
2914
2776
|
s1 = peg$parsewhiteSpaceSymbol();
|
|
2777
|
+
if (s1 === peg$FAILED) {
|
|
2778
|
+
break;
|
|
2779
|
+
}
|
|
2780
|
+
s0.push(s1);
|
|
2915
2781
|
}
|
|
2916
2782
|
return s0;
|
|
2917
2783
|
}
|
|
2918
2784
|
function peg$parsewhiteSpaceSymbol() {
|
|
2919
2785
|
let s0;
|
|
2920
2786
|
s0 = input.charAt(peg$currPos);
|
|
2921
|
-
if (peg$
|
|
2787
|
+
if (peg$charCode = s0.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 10 || peg$charCode === 13) {
|
|
2922
2788
|
peg$currPos++;
|
|
2923
2789
|
} else {
|
|
2924
2790
|
s0 = peg$FAILED;
|
|
@@ -2931,7 +2797,7 @@ function peg$parse(input, options) {
|
|
|
2931
2797
|
function peg$parsereferenceSymbol() {
|
|
2932
2798
|
let s0;
|
|
2933
2799
|
s0 = input.charAt(peg$currPos);
|
|
2934
|
-
if (peg$
|
|
2800
|
+
if (s0 !== "" && !(peg$charCode = s0.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 10 || peg$charCode === 13 || peg$charCode === 40 || peg$charCode === 58 || peg$charCode === 41)) {
|
|
2935
2801
|
peg$currPos++;
|
|
2936
2802
|
} else {
|
|
2937
2803
|
s0 = peg$FAILED;
|
|
@@ -3019,7 +2885,7 @@ function peg$parse(input, options) {
|
|
|
3019
2885
|
function getCurrentIndentation() {
|
|
3020
2886
|
return indentationStack[indentationStack.length - 1];
|
|
3021
2887
|
}
|
|
3022
|
-
const delimitedReferences = new DelimitedReferences(
|
|
2888
|
+
const delimitedReferences = new DelimitedReferences(source);
|
|
3023
2889
|
function parseQuotedStringAt(inputStr, startPos, quoteChar) {
|
|
3024
2890
|
if (startPos >= inputStr.length || inputStr[startPos] !== quoteChar) {
|
|
3025
2891
|
return null;
|
|
@@ -3559,34 +3425,48 @@ function countNewlines(value) {
|
|
|
3559
3425
|
}
|
|
3560
3426
|
function structurallyComplete(document, comments) {
|
|
3561
3427
|
const quotes = ['"', "'", "`"];
|
|
3562
|
-
const
|
|
3563
|
-
`, "\r", "(", ":"];
|
|
3428
|
+
const separators = [" ", "\t", `
|
|
3429
|
+
`, "\r", "(", ":", ")"];
|
|
3564
3430
|
const beforeComment = [" ", "\t", `
|
|
3565
3431
|
`, "\r"];
|
|
3566
3432
|
const references = new DelimitedReferences(document);
|
|
3567
3433
|
let depth = 0;
|
|
3434
|
+
let tokenStart = true;
|
|
3568
3435
|
for (let position = 0;position < document.length; position++) {
|
|
3569
3436
|
const character = document[position];
|
|
3570
3437
|
const previous = position === 0 ? null : document[position - 1];
|
|
3571
|
-
if (quotes.includes(character) && (previous === null || beforeReference.includes(previous))) {
|
|
3572
|
-
const end = references.endAt(position);
|
|
3573
|
-
if (end === null)
|
|
3574
|
-
return false;
|
|
3575
|
-
position = end - 1;
|
|
3576
|
-
continue;
|
|
3577
|
-
}
|
|
3578
3438
|
if (comments && character === "#" && (previous === null || beforeComment.includes(previous))) {
|
|
3579
3439
|
const newline = document.indexOf(`
|
|
3580
3440
|
`, position);
|
|
3581
3441
|
if (newline === -1)
|
|
3582
3442
|
return true;
|
|
3583
3443
|
position = newline;
|
|
3444
|
+
tokenStart = true;
|
|
3445
|
+
continue;
|
|
3446
|
+
}
|
|
3447
|
+
if (separators.includes(character)) {
|
|
3448
|
+
if (character === "(")
|
|
3449
|
+
depth += 1;
|
|
3450
|
+
if (character === ")")
|
|
3451
|
+
depth -= 1;
|
|
3452
|
+
tokenStart = true;
|
|
3584
3453
|
continue;
|
|
3585
3454
|
}
|
|
3586
|
-
if (
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3455
|
+
if (tokenStart && quotes.includes(character)) {
|
|
3456
|
+
const reading = references.readAt(position);
|
|
3457
|
+
if (reading === null || !reading.closed)
|
|
3458
|
+
return false;
|
|
3459
|
+
position += reading.length - 1;
|
|
3460
|
+
continue;
|
|
3461
|
+
}
|
|
3462
|
+
if (tokenStart) {
|
|
3463
|
+
const end = referenceLiteralEnd(document, position);
|
|
3464
|
+
if (end !== -1) {
|
|
3465
|
+
position = end - 1;
|
|
3466
|
+
continue;
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
tokenStart = false;
|
|
3590
3470
|
}
|
|
3591
3471
|
return depth === 0;
|
|
3592
3472
|
}
|