links-notation 0.27.1 → 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 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 emptyReference;
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");
@@ -235,9 +252,16 @@ function unescapeReference(reference) {
235
252
  }
236
253
  return reading.value;
237
254
  }
255
+ function referenceQuote(raw) {
256
+ if (typeof raw !== "string" || !QUOTES.includes(raw[0]))
257
+ return null;
258
+ const reading = readReference(raw, 0);
259
+ return reading !== null && reading.length === raw.length ? raw[0] : null;
260
+ }
238
261
 
239
262
  // src/Link.js
240
263
  class Link {
264
+ #rawId = null;
241
265
  constructor(id = null, values = null) {
242
266
  this.id = id;
243
267
  if (values !== null && values !== undefined) {
@@ -249,6 +273,18 @@ class Link {
249
273
  this.values = [];
250
274
  }
251
275
  }
276
+ get rawId() {
277
+ return this.#rawId;
278
+ }
279
+ set rawId(raw) {
280
+ if (raw !== null && raw !== undefined && typeof raw !== "string") {
281
+ throw new TypeError("rawId must be a string or null");
282
+ }
283
+ this.#rawId = raw ?? null;
284
+ }
285
+ get quote() {
286
+ return referenceQuote(this.#rawId);
287
+ }
252
288
  toString() {
253
289
  return this.format(false);
254
290
  }
@@ -460,6 +496,196 @@ function formatLinks(links, lessParentheses = false) {
460
496
  return links.map((link) => link.format(lessParentheses)).join(`
461
497
  `);
462
498
  }
499
+ // src/comments.js
500
+ var COMMENT = "#";
501
+ var SEPARATORS = [" ", "\t", `
502
+ `, "\r", "(", ":", ")"];
503
+ var BEFORE_COMMENT = [" ", "\t", `
504
+ `, "\r"];
505
+ function stripComments(document) {
506
+ let blanked = null;
507
+ let position = 0;
508
+ let tokenStart = true;
509
+ const references = new DelimitedReferences(document);
510
+ while (position < document.length) {
511
+ const character = document[position];
512
+ if (character === COMMENT && follows(document, position, BEFORE_COMMENT)) {
513
+ blanked = blanked ?? document.split("");
514
+ while (position < document.length && document[position] !== `
515
+ ` && document[position] !== "\r") {
516
+ blanked[position] = " ";
517
+ position++;
518
+ }
519
+ continue;
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;
534
+ position++;
535
+ }
536
+ return blanked === null ? document : blanked.join("");
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
+ }
545
+ function follows(document, position, allowed) {
546
+ return position === 0 || allowed.includes(document[position - 1]);
547
+ }
548
+
549
+ // src/Cst.js
550
+ var CstKind = Object.freeze({
551
+ DOCUMENT: "document",
552
+ LINE: "line",
553
+ GROUP: "group",
554
+ WHITESPACE: "whitespace",
555
+ NEWLINE: "newline",
556
+ COMMENT: "comment",
557
+ OPEN_PAREN: "open_paren",
558
+ CLOSE_PAREN: "close_paren",
559
+ COLON: "colon",
560
+ REFERENCE: "reference"
561
+ });
562
+ var NODE_KINDS = new Set([CstKind.DOCUMENT, CstKind.LINE, CstKind.GROUP]);
563
+
564
+ class CstNode {
565
+ #text;
566
+ constructor(kind, { text = "", children = [], value = null, quote = null } = {}) {
567
+ this.kind = kind;
568
+ this.children = children;
569
+ this.value = value;
570
+ this.quote = quote;
571
+ this.#text = text;
572
+ }
573
+ get isToken() {
574
+ return !NODE_KINDS.has(this.kind);
575
+ }
576
+ get text() {
577
+ if (this.isToken)
578
+ return this.#text;
579
+ return this.children.map((child) => child.text).join("");
580
+ }
581
+ toString() {
582
+ return this.text;
583
+ }
584
+ tokens() {
585
+ if (this.isToken)
586
+ return [this];
587
+ return this.children.flatMap((child) => child.tokens());
588
+ }
589
+ toSExpression() {
590
+ if (this.isToken)
591
+ return `${this.kind}:${quoteText(this.#text)}`;
592
+ return `(${[this.kind, ...this.children.map((child) => child.toSExpression())].join(" ")})`;
593
+ }
594
+ }
595
+ var ESCAPES = {
596
+ "\\": "\\\\",
597
+ '"': "\\\"",
598
+ "\n": "\\n",
599
+ "\r": "\\r",
600
+ "\t": "\\t"
601
+ };
602
+ function quoteText(text) {
603
+ return `"${text.replace(/[\\"\n\r\t]/g, (character) => ESCAPES[character])}"`;
604
+ }
605
+ var BARE_REFERENCE_END = new Set([" ", "\t", "\r", `
606
+ `, "(", ":", ")"]);
607
+ function buildCst(input, { comments = true } = {}) {
608
+ const prepared = comments ? stripComments(input) : input;
609
+ const references = new DelimitedReferences(input);
610
+ const document = new CstNode(CstKind.DOCUMENT);
611
+ const containers = [{ node: document, line: null }];
612
+ const add = (token) => {
613
+ const container = containers[containers.length - 1];
614
+ if (container.line === null) {
615
+ container.line = new CstNode(CstKind.LINE);
616
+ container.node.children.push(container.line);
617
+ }
618
+ container.line.children.push(token);
619
+ };
620
+ const token = (kind, start, end, parts = {}) => new CstNode(kind, { text: input.slice(start, end), ...parts });
621
+ let position = 0;
622
+ while (position < input.length) {
623
+ const character = input[position];
624
+ let end = position + 1;
625
+ if (comments && character === "#" && prepared[position] !== "#") {
626
+ while (end < input.length && input[end] !== `
627
+ ` && input[end] !== "\r") {
628
+ end++;
629
+ }
630
+ add(token(CstKind.COMMENT, position, end));
631
+ } else if (character === "\r" || character === `
632
+ `) {
633
+ if (character === "\r" && input[end] === `
634
+ `)
635
+ end++;
636
+ add(token(CstKind.NEWLINE, position, end));
637
+ containers[containers.length - 1].line = null;
638
+ } else if (character === " " || character === "\t") {
639
+ while (end < input.length && (input[end] === " " || input[end] === "\t")) {
640
+ end++;
641
+ }
642
+ add(token(CstKind.WHITESPACE, position, end));
643
+ } else if (character === "(") {
644
+ const group = new CstNode(CstKind.GROUP, {
645
+ children: [token(CstKind.OPEN_PAREN, position, end)]
646
+ });
647
+ add(group);
648
+ containers.push({ node: group, line: null });
649
+ } else if (character === ")") {
650
+ if (containers.length === 1) {
651
+ throw new SyntaxError(`Unbalanced ")" at offset ${position}`);
652
+ }
653
+ containers.pop().node.children.push(token(CstKind.CLOSE_PAREN, position, end));
654
+ } else if (character === ":") {
655
+ add(token(CstKind.COLON, position, end));
656
+ } else {
657
+ end = referenceEnd(prepared, position, references);
658
+ const text = input.slice(position, end);
659
+ const quoted = QUOTES.includes(character) && references.readAt(position);
660
+ add(token(CstKind.REFERENCE, position, end, {
661
+ value: quoted ? quoted.value : character === "~" && isLiteral(prepared, position, end) ? decodeReferenceLiteral(text) : text,
662
+ quote: quoted ? character : null
663
+ }));
664
+ }
665
+ position = end;
666
+ }
667
+ if (containers.length !== 1) {
668
+ throw new SyntaxError('Unbalanced "(" at the end of the document');
669
+ }
670
+ return document;
671
+ }
672
+ function referenceEnd(prepared, start, references) {
673
+ const literal = referenceLiteralEnd(prepared, start);
674
+ if (literal !== -1)
675
+ return literal;
676
+ if (QUOTES.includes(prepared[start])) {
677
+ const end = references.endAt(start);
678
+ if (end !== null)
679
+ return end;
680
+ }
681
+ let end = start + 1;
682
+ while (end < prepared.length && !BARE_REFERENCE_END.has(prepared[end]))
683
+ end++;
684
+ return end;
685
+ }
686
+ function isLiteral(prepared, start, end) {
687
+ return referenceLiteralEnd(prepared, start) === end;
688
+ }
463
689
  // src/LinksGroup.js
464
690
  class LinksGroup {
465
691
  constructor(element, children = []) {
@@ -564,40 +790,6 @@ function windowAround(lineText, column) {
564
790
  return [quoted, target - start + shift + 1];
565
791
  }
566
792
 
567
- // src/comments.js
568
- var COMMENT = "#";
569
- var BEFORE_REFERENCE = [" ", "\t", `
570
- `, "\r", "(", ":"];
571
- var BEFORE_COMMENT = [" ", "\t", `
572
- `, "\r"];
573
- function stripComments(document) {
574
- let blanked = null;
575
- let position = 0;
576
- const references = new DelimitedReferences(document);
577
- while (position < document.length) {
578
- const character = document[position];
579
- if (QUOTES.includes(character) && follows(document, position, BEFORE_REFERENCE)) {
580
- const end = references.endAt(position);
581
- position = end === null ? position + 1 : end;
582
- continue;
583
- }
584
- if (character === COMMENT && follows(document, position, BEFORE_COMMENT)) {
585
- blanked = blanked ?? document.split("");
586
- while (position < document.length && document[position] !== `
587
- ` && document[position] !== "\r") {
588
- blanked[position] = " ";
589
- position++;
590
- }
591
- continue;
592
- }
593
- position++;
594
- }
595
- return blanked === null ? document : blanked.join("");
596
- }
597
- function follows(document, position, allowed) {
598
- return position === 0 || allowed.includes(document[position - 1]);
599
- }
600
-
601
793
  // src/parser-generated.js
602
794
  class peg$SyntaxError extends SyntaxError {
603
795
  constructor(message, expected, found, location) {
@@ -647,11 +839,14 @@ class peg$SyntaxError extends SyntaxError {
647
839
  }
648
840
  return s;
649
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
+ }
650
845
  function literalEscape(s) {
651
- return unicodeEscape(s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").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)));
846
+ return escape(s, /[\\"]/g);
652
847
  }
653
848
  function classEscape(s) {
654
- return unicodeEscape(s.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").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)));
849
+ return escape(s, /[\\\]^-]/g);
655
850
  }
656
851
  const DESCRIBE_EXPECTATION_FNS = {
657
852
  literal(expectation) {
@@ -720,12 +915,6 @@ function peg$parse(input, options) {
720
915
  const peg$c7 = "'";
721
916
  const peg$c8 = "`";
722
917
  const peg$c9 = " ";
723
- const peg$r0 = /^[ \t]/;
724
- const peg$r1 = /^[\r\n]/;
725
- const peg$r2 = /^[0-9]/;
726
- const peg$r3 = /^[^} \t\r\n()]/;
727
- const peg$r4 = /^[ \t\n\r]/;
728
- const peg$r5 = /^[^ \t\n\r(:)]/;
729
918
  const peg$e0 = peg$classExpectation([" ", "\t"], false, false, false);
730
919
  const peg$e1 = peg$classExpectation(["\r", `
731
920
  `], false, false, false);
@@ -789,8 +978,8 @@ function peg$parse(input, options) {
789
978
  function peg$f11(l) {
790
979
  return l;
791
980
  }
792
- function peg$f12(i) {
793
- return { id: i };
981
+ function peg$f12(r) {
982
+ return { id: r.value, rawId: r.raw };
794
983
  }
795
984
  function peg$f13(g, rest) {
796
985
  return rest === null ? g : { values: [g].concat(rest) };
@@ -834,27 +1023,31 @@ function peg$parse(input, options) {
834
1023
  return list;
835
1024
  }
836
1025
  function peg$f26(id, v) {
837
- return { id, values: v };
1026
+ return { id: id.value, rawId: id.raw, values: v };
838
1027
  }
839
1028
  function peg$f27(v) {
840
1029
  return { values: v };
841
1030
  }
842
1031
  function peg$f28(id) {
843
- return { id, values: [] };
1032
+ return { id: id.value, rawId: id.raw, values: [] };
1033
+ }
1034
+ function peg$f29(value) {
1035
+ const { start, end } = range();
1036
+ return { value, raw: source.slice(start, end) };
844
1037
  }
845
- function peg$f29() {
1038
+ function peg$f30() {
846
1039
  return hasReferenceLiteralPrefix(input, offset());
847
1040
  }
848
- function peg$f30(literal) {
1041
+ function peg$f31(literal) {
849
1042
  return decodeReferenceLiteral(literal);
850
1043
  }
851
- function peg$f31() {
1044
+ function peg$f32() {
852
1045
  return !hasReferenceLiteralPrefix(input, offset());
853
1046
  }
854
- function peg$f32(chars) {
1047
+ function peg$f33(chars) {
855
1048
  return chars.join("");
856
1049
  }
857
- function peg$f33() {
1050
+ function peg$f34() {
858
1051
  const pos = offset();
859
1052
  const result = parseQuotedStringAt(input, pos, '"');
860
1053
  if (result) {
@@ -864,19 +1057,19 @@ function peg$parse(input, options) {
864
1057
  }
865
1058
  return false;
866
1059
  }
867
- function peg$f34(chars) {
1060
+ function peg$f35(chars) {
868
1061
  return parsedValue;
869
1062
  }
870
- function peg$f35(c, cs) {
1063
+ function peg$f36(c, cs) {
871
1064
  return [c].concat(cs).join("");
872
1065
  }
873
- function peg$f36() {
1066
+ function peg$f37() {
874
1067
  return parsedLength > 1 && (parsedLength--, true);
875
1068
  }
876
- function peg$f37(c) {
1069
+ function peg$f38(c) {
877
1070
  return c;
878
1071
  }
879
- function peg$f38() {
1072
+ function peg$f39() {
880
1073
  const pos = offset();
881
1074
  const result = parseQuotedStringAt(input, pos, "'");
882
1075
  if (result) {
@@ -886,19 +1079,19 @@ function peg$parse(input, options) {
886
1079
  }
887
1080
  return false;
888
1081
  }
889
- function peg$f39(chars) {
1082
+ function peg$f40(chars) {
890
1083
  return parsedValue;
891
1084
  }
892
- function peg$f40(c, cs) {
1085
+ function peg$f41(c, cs) {
893
1086
  return [c].concat(cs).join("");
894
1087
  }
895
- function peg$f41() {
1088
+ function peg$f42() {
896
1089
  return parsedLength > 1 && (parsedLength--, true);
897
1090
  }
898
- function peg$f42(c) {
1091
+ function peg$f43(c) {
899
1092
  return c;
900
1093
  }
901
- function peg$f43() {
1094
+ function peg$f44() {
902
1095
  const pos = offset();
903
1096
  const result = parseQuotedStringAt(input, pos, "`");
904
1097
  if (result) {
@@ -908,34 +1101,34 @@ function peg$parse(input, options) {
908
1101
  }
909
1102
  return false;
910
1103
  }
911
- function peg$f44(chars) {
1104
+ function peg$f45(chars) {
912
1105
  return parsedValue;
913
1106
  }
914
- function peg$f45(c, cs) {
1107
+ function peg$f46(c, cs) {
915
1108
  return [c].concat(cs).join("");
916
1109
  }
917
- function peg$f46() {
1110
+ function peg$f47() {
918
1111
  return parsedLength > 1 && (parsedLength--, true);
919
1112
  }
920
- function peg$f47(c) {
1113
+ function peg$f48(c) {
921
1114
  return c;
922
1115
  }
923
- function peg$f48() {
1116
+ function peg$f49() {
924
1117
  return indentationStack.slice();
925
1118
  }
926
- function peg$f49(spaces) {
1119
+ function peg$f50(spaces) {
927
1120
  setBaseIndentation(spaces);
928
1121
  }
929
- function peg$f50(spaces) {
1122
+ function peg$f51(spaces) {
930
1123
  return normalizeIndentation(spaces) > getCurrentIndentation();
931
1124
  }
932
- function peg$f51(spaces) {
1125
+ function peg$f52(spaces) {
933
1126
  pushIndentation(spaces);
934
1127
  }
935
- function peg$f52(spaces) {
1128
+ function peg$f53(spaces) {
936
1129
  return checkIndentation(spaces);
937
1130
  }
938
- function peg$f53() {
1131
+ function peg$f54() {
939
1132
  return isInsideNestedContext();
940
1133
  }
941
1134
  let peg$currPos = options.peg$currPos | 0;
@@ -945,6 +1138,7 @@ function peg$parse(input, options) {
945
1138
  let peg$maxFailExpected = options.peg$maxFailExpected || [];
946
1139
  let peg$silentFails = options.peg$silentFails | 0;
947
1140
  let peg$result;
1141
+ let peg$charCode;
948
1142
  if (options.startRule) {
949
1143
  if (!(options.startRule in peg$startRuleFunctions)) {
950
1144
  throw new Error(`Can't start parsing from rule "` + options.startRule + '".');
@@ -1125,62 +1319,12 @@ function peg$parse(input, options) {
1125
1319
  function peg$parseskipEmptyLines() {
1126
1320
  let s0, s1, s2, s3;
1127
1321
  s0 = [];
1128
- s1 = peg$currPos;
1129
- s2 = [];
1130
- s3 = input.charAt(peg$currPos);
1131
- if (peg$r0.test(s3)) {
1132
- peg$currPos++;
1133
- } else {
1134
- s3 = peg$FAILED;
1135
- if (peg$silentFails === 0) {
1136
- peg$fail(peg$e0);
1137
- }
1138
- }
1139
- while (s3 !== peg$FAILED) {
1140
- s2.push(s3);
1141
- s3 = input.charAt(peg$currPos);
1142
- if (peg$r0.test(s3)) {
1143
- peg$currPos++;
1144
- } else {
1145
- s3 = peg$FAILED;
1146
- if (peg$silentFails === 0) {
1147
- peg$fail(peg$e0);
1148
- }
1149
- }
1150
- }
1151
- s3 = input.charAt(peg$currPos);
1152
- if (peg$r1.test(s3)) {
1153
- peg$currPos++;
1154
- } else {
1155
- s3 = peg$FAILED;
1156
- if (peg$silentFails === 0) {
1157
- peg$fail(peg$e1);
1158
- }
1159
- }
1160
- if (s3 !== peg$FAILED) {
1161
- s2 = [s2, s3];
1162
- s1 = s2;
1163
- } else {
1164
- peg$currPos = s1;
1165
- s1 = peg$FAILED;
1166
- }
1167
- while (s1 !== peg$FAILED) {
1168
- s0.push(s1);
1322
+ for (;; ) {
1169
1323
  s1 = peg$currPos;
1170
1324
  s2 = [];
1171
- s3 = input.charAt(peg$currPos);
1172
- if (peg$r0.test(s3)) {
1173
- peg$currPos++;
1174
- } else {
1175
- s3 = peg$FAILED;
1176
- if (peg$silentFails === 0) {
1177
- peg$fail(peg$e0);
1178
- }
1179
- }
1180
- while (s3 !== peg$FAILED) {
1181
- s2.push(s3);
1325
+ for (;; ) {
1182
1326
  s3 = input.charAt(peg$currPos);
1183
- if (peg$r0.test(s3)) {
1327
+ if (peg$charCode = s3.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9) {
1184
1328
  peg$currPos++;
1185
1329
  } else {
1186
1330
  s3 = peg$FAILED;
@@ -1188,9 +1332,13 @@ function peg$parse(input, options) {
1188
1332
  peg$fail(peg$e0);
1189
1333
  }
1190
1334
  }
1335
+ if (s3 === peg$FAILED) {
1336
+ break;
1337
+ }
1338
+ s2.push(s3);
1191
1339
  }
1192
1340
  s3 = input.charAt(peg$currPos);
1193
- if (peg$r1.test(s3)) {
1341
+ if (peg$charCode = s3.charCodeAt(0), peg$charCode === 13 || peg$charCode === 10) {
1194
1342
  peg$currPos++;
1195
1343
  } else {
1196
1344
  s3 = peg$FAILED;
@@ -1205,6 +1353,10 @@ function peg$parse(input, options) {
1205
1353
  peg$currPos = s1;
1206
1354
  s1 = peg$FAILED;
1207
1355
  }
1356
+ if (s1 === peg$FAILED) {
1357
+ break;
1358
+ }
1359
+ s0.push(s1);
1208
1360
  }
1209
1361
  return s0;
1210
1362
  }
@@ -1214,10 +1366,12 @@ function peg$parse(input, options) {
1214
1366
  s1 = peg$parsefirstLine();
1215
1367
  if (s1 !== peg$FAILED) {
1216
1368
  s2 = [];
1217
- s3 = peg$parseline();
1218
- while (s3 !== peg$FAILED) {
1219
- s2.push(s3);
1369
+ for (;; ) {
1220
1370
  s3 = peg$parseline();
1371
+ if (s3 === peg$FAILED) {
1372
+ break;
1373
+ }
1374
+ s2.push(s3);
1221
1375
  }
1222
1376
  peg$savedPos = s0;
1223
1377
  s0 = peg$f4(s1, s2);
@@ -1469,10 +1623,12 @@ function peg$parse(input, options) {
1469
1623
  if (s0 === peg$FAILED) {
1470
1624
  s0 = peg$currPos;
1471
1625
  s1 = [];
1472
- s2 = peg$parsesingleLineValueAndWhitespace();
1473
- while (s2 !== peg$FAILED) {
1474
- s1.push(s2);
1626
+ for (;; ) {
1475
1627
  s2 = peg$parsesingleLineValueAndWhitespace();
1628
+ if (s2 === peg$FAILED) {
1629
+ break;
1630
+ }
1631
+ s1.push(s2);
1476
1632
  }
1477
1633
  s2 = peg$parseeol();
1478
1634
  if (s2 !== peg$FAILED) {
@@ -1684,13 +1840,14 @@ function peg$parse(input, options) {
1684
1840
  let s0, s1, s2;
1685
1841
  s0 = peg$currPos;
1686
1842
  s1 = [];
1687
- s2 = peg$parsesingleLineValueAndWhitespace();
1688
- if (s2 !== peg$FAILED) {
1689
- while (s2 !== peg$FAILED) {
1690
- s1.push(s2);
1691
- s2 = peg$parsesingleLineValueAndWhitespace();
1843
+ for (;; ) {
1844
+ s2 = peg$parsesingleLineValueAndWhitespace();
1845
+ if (s2 === peg$FAILED) {
1846
+ break;
1692
1847
  }
1693
- } else {
1848
+ s1.push(s2);
1849
+ }
1850
+ if (s1.length < 1) {
1694
1851
  s1 = peg$FAILED;
1695
1852
  }
1696
1853
  if (s1 !== peg$FAILED) {
@@ -1781,6 +1938,17 @@ function peg$parse(input, options) {
1781
1938
  return s0;
1782
1939
  }
1783
1940
  function peg$parsereference() {
1941
+ let s0, s1;
1942
+ s0 = peg$currPos;
1943
+ s1 = peg$parsereferenceValue();
1944
+ if (s1 !== peg$FAILED) {
1945
+ peg$savedPos = s0;
1946
+ s1 = peg$f29(s1);
1947
+ }
1948
+ s0 = s1;
1949
+ return s0;
1950
+ }
1951
+ function peg$parsereferenceValue() {
1784
1952
  let s0;
1785
1953
  s0 = peg$parsereferenceLiteral();
1786
1954
  if (s0 === peg$FAILED) {
@@ -1814,7 +1982,7 @@ function peg$parse(input, options) {
1814
1982
  }
1815
1983
  if (s1 !== peg$FAILED) {
1816
1984
  peg$savedPos = peg$currPos;
1817
- s2 = peg$f29();
1985
+ s2 = peg$f30();
1818
1986
  if (s2) {
1819
1987
  s2 = undefined;
1820
1988
  } else {
@@ -1834,29 +2002,22 @@ function peg$parse(input, options) {
1834
2002
  }
1835
2003
  if (s5 !== peg$FAILED) {
1836
2004
  s6 = [];
1837
- s7 = input.charAt(peg$currPos);
1838
- if (peg$r2.test(s7)) {
1839
- peg$currPos++;
1840
- } else {
1841
- s7 = peg$FAILED;
1842
- if (peg$silentFails === 0) {
1843
- peg$fail(peg$e7);
1844
- }
1845
- }
1846
- if (s7 !== peg$FAILED) {
1847
- while (s7 !== peg$FAILED) {
1848
- s6.push(s7);
1849
- s7 = input.charAt(peg$currPos);
1850
- if (peg$r2.test(s7)) {
1851
- peg$currPos++;
1852
- } else {
1853
- s7 = peg$FAILED;
1854
- if (peg$silentFails === 0) {
1855
- peg$fail(peg$e7);
1856
- }
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);
1857
2013
  }
1858
2014
  }
1859
- } else {
2015
+ if (s7 === peg$FAILED) {
2016
+ break;
2017
+ }
2018
+ s6.push(s7);
2019
+ }
2020
+ if (s6.length < 1) {
1860
2021
  s6 = peg$FAILED;
1861
2022
  }
1862
2023
  if (s6 !== peg$FAILED) {
@@ -1871,19 +2032,9 @@ function peg$parse(input, options) {
1871
2032
  }
1872
2033
  if (s7 !== peg$FAILED) {
1873
2034
  s8 = [];
1874
- s9 = input.charAt(peg$currPos);
1875
- if (peg$r3.test(s9)) {
1876
- peg$currPos++;
1877
- } else {
1878
- s9 = peg$FAILED;
1879
- if (peg$silentFails === 0) {
1880
- peg$fail(peg$e9);
1881
- }
1882
- }
1883
- while (s9 !== peg$FAILED) {
1884
- s8.push(s9);
2035
+ for (;; ) {
1885
2036
  s9 = input.charAt(peg$currPos);
1886
- if (peg$r3.test(s9)) {
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)) {
1887
2038
  peg$currPos++;
1888
2039
  } else {
1889
2040
  s9 = peg$FAILED;
@@ -1891,6 +2042,10 @@ function peg$parse(input, options) {
1891
2042
  peg$fail(peg$e9);
1892
2043
  }
1893
2044
  }
2045
+ if (s9 === peg$FAILED) {
2046
+ break;
2047
+ }
2048
+ s8.push(s9);
1894
2049
  }
1895
2050
  if (input.charCodeAt(peg$currPos) === 125) {
1896
2051
  s9 = peg$c5;
@@ -1927,7 +2082,7 @@ function peg$parse(input, options) {
1927
2082
  }
1928
2083
  if (s3 !== peg$FAILED) {
1929
2084
  peg$savedPos = s0;
1930
- s0 = peg$f30(s3);
2085
+ s0 = peg$f31(s3);
1931
2086
  } else {
1932
2087
  peg$currPos = s0;
1933
2088
  s0 = peg$FAILED;
@@ -1946,7 +2101,7 @@ function peg$parse(input, options) {
1946
2101
  let s0, s1, s2, s3;
1947
2102
  s0 = peg$currPos;
1948
2103
  peg$savedPos = peg$currPos;
1949
- s1 = peg$f31();
2104
+ s1 = peg$f32();
1950
2105
  if (s1) {
1951
2106
  s1 = undefined;
1952
2107
  } else {
@@ -1954,18 +2109,19 @@ function peg$parse(input, options) {
1954
2109
  }
1955
2110
  if (s1 !== peg$FAILED) {
1956
2111
  s2 = [];
1957
- s3 = peg$parsereferenceSymbol();
1958
- if (s3 !== peg$FAILED) {
1959
- while (s3 !== peg$FAILED) {
1960
- s2.push(s3);
1961
- s3 = peg$parsereferenceSymbol();
2112
+ for (;; ) {
2113
+ s3 = peg$parsereferenceSymbol();
2114
+ if (s3 === peg$FAILED) {
2115
+ break;
1962
2116
  }
1963
- } else {
2117
+ s2.push(s3);
2118
+ }
2119
+ if (s2.length < 1) {
1964
2120
  s2 = peg$FAILED;
1965
2121
  }
1966
2122
  if (s2 !== peg$FAILED) {
1967
2123
  peg$savedPos = s0;
1968
- s0 = peg$f32(s2);
2124
+ s0 = peg$f33(s2);
1969
2125
  } else {
1970
2126
  peg$currPos = s0;
1971
2127
  s0 = peg$FAILED;
@@ -2010,7 +2166,7 @@ function peg$parse(input, options) {
2010
2166
  }
2011
2167
  if (s1 !== peg$FAILED) {
2012
2168
  peg$savedPos = peg$currPos;
2013
- s2 = peg$f33();
2169
+ s2 = peg$f34();
2014
2170
  if (s2) {
2015
2171
  s2 = undefined;
2016
2172
  } else {
@@ -2020,7 +2176,7 @@ function peg$parse(input, options) {
2020
2176
  s3 = peg$parseconsumeDouble();
2021
2177
  if (s3 !== peg$FAILED) {
2022
2178
  peg$savedPos = s0;
2023
- s0 = peg$f34(s3);
2179
+ s0 = peg$f35(s3);
2024
2180
  } else {
2025
2181
  peg$currPos = s0;
2026
2182
  s0 = peg$FAILED;
@@ -2049,13 +2205,15 @@ function peg$parse(input, options) {
2049
2205
  }
2050
2206
  if (s1 !== peg$FAILED) {
2051
2207
  s2 = [];
2052
- s3 = peg$parseconsumeDoubleMore();
2053
- while (s3 !== peg$FAILED) {
2054
- s2.push(s3);
2208
+ for (;; ) {
2055
2209
  s3 = peg$parseconsumeDoubleMore();
2210
+ if (s3 === peg$FAILED) {
2211
+ break;
2212
+ }
2213
+ s2.push(s3);
2056
2214
  }
2057
2215
  peg$savedPos = s0;
2058
- s0 = peg$f35(s1, s2);
2216
+ s0 = peg$f36(s1, s2);
2059
2217
  } else {
2060
2218
  peg$currPos = s0;
2061
2219
  s0 = peg$FAILED;
@@ -2066,7 +2224,7 @@ function peg$parse(input, options) {
2066
2224
  let s0, s1, s2;
2067
2225
  s0 = peg$currPos;
2068
2226
  peg$savedPos = peg$currPos;
2069
- s1 = peg$f36();
2227
+ s1 = peg$f37();
2070
2228
  if (s1) {
2071
2229
  s1 = undefined;
2072
2230
  } else {
@@ -2084,7 +2242,7 @@ function peg$parse(input, options) {
2084
2242
  }
2085
2243
  if (s2 !== peg$FAILED) {
2086
2244
  peg$savedPos = s0;
2087
- s0 = peg$f37(s2);
2245
+ s0 = peg$f38(s2);
2088
2246
  } else {
2089
2247
  peg$currPos = s0;
2090
2248
  s0 = peg$FAILED;
@@ -2118,7 +2276,7 @@ function peg$parse(input, options) {
2118
2276
  }
2119
2277
  if (s1 !== peg$FAILED) {
2120
2278
  peg$savedPos = peg$currPos;
2121
- s2 = peg$f38();
2279
+ s2 = peg$f39();
2122
2280
  if (s2) {
2123
2281
  s2 = undefined;
2124
2282
  } else {
@@ -2128,7 +2286,7 @@ function peg$parse(input, options) {
2128
2286
  s3 = peg$parseconsumeSingle();
2129
2287
  if (s3 !== peg$FAILED) {
2130
2288
  peg$savedPos = s0;
2131
- s0 = peg$f39(s3);
2289
+ s0 = peg$f40(s3);
2132
2290
  } else {
2133
2291
  peg$currPos = s0;
2134
2292
  s0 = peg$FAILED;
@@ -2157,13 +2315,15 @@ function peg$parse(input, options) {
2157
2315
  }
2158
2316
  if (s1 !== peg$FAILED) {
2159
2317
  s2 = [];
2160
- s3 = peg$parseconsumeSingleMore();
2161
- while (s3 !== peg$FAILED) {
2162
- s2.push(s3);
2318
+ for (;; ) {
2163
2319
  s3 = peg$parseconsumeSingleMore();
2320
+ if (s3 === peg$FAILED) {
2321
+ break;
2322
+ }
2323
+ s2.push(s3);
2164
2324
  }
2165
2325
  peg$savedPos = s0;
2166
- s0 = peg$f40(s1, s2);
2326
+ s0 = peg$f41(s1, s2);
2167
2327
  } else {
2168
2328
  peg$currPos = s0;
2169
2329
  s0 = peg$FAILED;
@@ -2174,7 +2334,7 @@ function peg$parse(input, options) {
2174
2334
  let s0, s1, s2;
2175
2335
  s0 = peg$currPos;
2176
2336
  peg$savedPos = peg$currPos;
2177
- s1 = peg$f41();
2337
+ s1 = peg$f42();
2178
2338
  if (s1) {
2179
2339
  s1 = undefined;
2180
2340
  } else {
@@ -2192,7 +2352,7 @@ function peg$parse(input, options) {
2192
2352
  }
2193
2353
  if (s2 !== peg$FAILED) {
2194
2354
  peg$savedPos = s0;
2195
- s0 = peg$f42(s2);
2355
+ s0 = peg$f43(s2);
2196
2356
  } else {
2197
2357
  peg$currPos = s0;
2198
2358
  s0 = peg$FAILED;
@@ -2226,7 +2386,7 @@ function peg$parse(input, options) {
2226
2386
  }
2227
2387
  if (s1 !== peg$FAILED) {
2228
2388
  peg$savedPos = peg$currPos;
2229
- s2 = peg$f43();
2389
+ s2 = peg$f44();
2230
2390
  if (s2) {
2231
2391
  s2 = undefined;
2232
2392
  } else {
@@ -2236,7 +2396,7 @@ function peg$parse(input, options) {
2236
2396
  s3 = peg$parseconsumeBacktick();
2237
2397
  if (s3 !== peg$FAILED) {
2238
2398
  peg$savedPos = s0;
2239
- s0 = peg$f44(s3);
2399
+ s0 = peg$f45(s3);
2240
2400
  } else {
2241
2401
  peg$currPos = s0;
2242
2402
  s0 = peg$FAILED;
@@ -2265,13 +2425,15 @@ function peg$parse(input, options) {
2265
2425
  }
2266
2426
  if (s1 !== peg$FAILED) {
2267
2427
  s2 = [];
2268
- s3 = peg$parseconsumeBacktickMore();
2269
- while (s3 !== peg$FAILED) {
2270
- s2.push(s3);
2428
+ for (;; ) {
2271
2429
  s3 = peg$parseconsumeBacktickMore();
2430
+ if (s3 === peg$FAILED) {
2431
+ break;
2432
+ }
2433
+ s2.push(s3);
2272
2434
  }
2273
2435
  peg$savedPos = s0;
2274
- s0 = peg$f45(s1, s2);
2436
+ s0 = peg$f46(s1, s2);
2275
2437
  } else {
2276
2438
  peg$currPos = s0;
2277
2439
  s0 = peg$FAILED;
@@ -2282,7 +2444,7 @@ function peg$parse(input, options) {
2282
2444
  let s0, s1, s2;
2283
2445
  s0 = peg$currPos;
2284
2446
  peg$savedPos = peg$currPos;
2285
- s1 = peg$f46();
2447
+ s1 = peg$f47();
2286
2448
  if (s1) {
2287
2449
  s1 = undefined;
2288
2450
  } else {
@@ -2300,7 +2462,7 @@ function peg$parse(input, options) {
2300
2462
  }
2301
2463
  if (s2 !== peg$FAILED) {
2302
2464
  peg$savedPos = s0;
2303
- s0 = peg$f47(s2);
2465
+ s0 = peg$f48(s2);
2304
2466
  } else {
2305
2467
  peg$currPos = s0;
2306
2468
  s0 = peg$FAILED;
@@ -2316,7 +2478,7 @@ function peg$parse(input, options) {
2316
2478
  s0 = peg$currPos;
2317
2479
  s1 = "";
2318
2480
  peg$savedPos = s0;
2319
- s1 = peg$f48();
2481
+ s1 = peg$f49();
2320
2482
  s0 = s1;
2321
2483
  return s0;
2322
2484
  }
@@ -2324,17 +2486,7 @@ function peg$parse(input, options) {
2324
2486
  let s0, s1, s2;
2325
2487
  s0 = peg$currPos;
2326
2488
  s1 = [];
2327
- if (input.charCodeAt(peg$currPos) === 32) {
2328
- s2 = peg$c9;
2329
- peg$currPos++;
2330
- } else {
2331
- s2 = peg$FAILED;
2332
- if (peg$silentFails === 0) {
2333
- peg$fail(peg$e14);
2334
- }
2335
- }
2336
- while (s2 !== peg$FAILED) {
2337
- s1.push(s2);
2489
+ for (;; ) {
2338
2490
  if (input.charCodeAt(peg$currPos) === 32) {
2339
2491
  s2 = peg$c9;
2340
2492
  peg$currPos++;
@@ -2344,9 +2496,13 @@ function peg$parse(input, options) {
2344
2496
  peg$fail(peg$e14);
2345
2497
  }
2346
2498
  }
2499
+ if (s2 === peg$FAILED) {
2500
+ break;
2501
+ }
2502
+ s1.push(s2);
2347
2503
  }
2348
2504
  peg$savedPos = s0;
2349
- s1 = peg$f49(s1);
2505
+ s1 = peg$f50(s1);
2350
2506
  s0 = s1;
2351
2507
  return s0;
2352
2508
  }
@@ -2354,17 +2510,7 @@ function peg$parse(input, options) {
2354
2510
  let s0, s1, s2;
2355
2511
  s0 = peg$currPos;
2356
2512
  s1 = [];
2357
- if (input.charCodeAt(peg$currPos) === 32) {
2358
- s2 = peg$c9;
2359
- peg$currPos++;
2360
- } else {
2361
- s2 = peg$FAILED;
2362
- if (peg$silentFails === 0) {
2363
- peg$fail(peg$e14);
2364
- }
2365
- }
2366
- while (s2 !== peg$FAILED) {
2367
- s1.push(s2);
2513
+ for (;; ) {
2368
2514
  if (input.charCodeAt(peg$currPos) === 32) {
2369
2515
  s2 = peg$c9;
2370
2516
  peg$currPos++;
@@ -2374,9 +2520,13 @@ function peg$parse(input, options) {
2374
2520
  peg$fail(peg$e14);
2375
2521
  }
2376
2522
  }
2523
+ if (s2 === peg$FAILED) {
2524
+ break;
2525
+ }
2526
+ s1.push(s2);
2377
2527
  }
2378
2528
  peg$savedPos = peg$currPos;
2379
- s2 = peg$f50(s1);
2529
+ s2 = peg$f51(s1);
2380
2530
  if (s2) {
2381
2531
  s2 = undefined;
2382
2532
  } else {
@@ -2384,7 +2534,7 @@ function peg$parse(input, options) {
2384
2534
  }
2385
2535
  if (s2 !== peg$FAILED) {
2386
2536
  peg$savedPos = s0;
2387
- s0 = peg$f51(s1);
2537
+ s0 = peg$f52(s1);
2388
2538
  } else {
2389
2539
  peg$currPos = s0;
2390
2540
  s0 = peg$FAILED;
@@ -2395,17 +2545,7 @@ function peg$parse(input, options) {
2395
2545
  let s0, s1, s2;
2396
2546
  s0 = peg$currPos;
2397
2547
  s1 = [];
2398
- if (input.charCodeAt(peg$currPos) === 32) {
2399
- s2 = peg$c9;
2400
- peg$currPos++;
2401
- } else {
2402
- s2 = peg$FAILED;
2403
- if (peg$silentFails === 0) {
2404
- peg$fail(peg$e14);
2405
- }
2406
- }
2407
- while (s2 !== peg$FAILED) {
2408
- s1.push(s2);
2548
+ for (;; ) {
2409
2549
  if (input.charCodeAt(peg$currPos) === 32) {
2410
2550
  s2 = peg$c9;
2411
2551
  peg$currPos++;
@@ -2415,9 +2555,13 @@ function peg$parse(input, options) {
2415
2555
  peg$fail(peg$e14);
2416
2556
  }
2417
2557
  }
2558
+ if (s2 === peg$FAILED) {
2559
+ break;
2560
+ }
2561
+ s1.push(s2);
2418
2562
  }
2419
2563
  peg$savedPos = peg$currPos;
2420
- s2 = peg$f52(s1);
2564
+ s2 = peg$f53(s1);
2421
2565
  if (s2) {
2422
2566
  s2 = undefined;
2423
2567
  } else {
@@ -2456,49 +2600,32 @@ function peg$parse(input, options) {
2456
2600
  let s0, s1, s2, s3, s4, s5, s6;
2457
2601
  s0 = peg$currPos;
2458
2602
  s1 = [];
2459
- s2 = input.charAt(peg$currPos);
2460
- if (peg$r1.test(s2)) {
2461
- peg$currPos++;
2462
- } else {
2463
- s2 = peg$FAILED;
2464
- if (peg$silentFails === 0) {
2465
- peg$fail(peg$e1);
2466
- }
2467
- }
2468
- if (s2 !== peg$FAILED) {
2469
- while (s2 !== peg$FAILED) {
2470
- s1.push(s2);
2471
- s2 = input.charAt(peg$currPos);
2472
- if (peg$r1.test(s2)) {
2473
- peg$currPos++;
2474
- } else {
2475
- s2 = peg$FAILED;
2476
- if (peg$silentFails === 0) {
2477
- peg$fail(peg$e1);
2478
- }
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);
2479
2611
  }
2480
2612
  }
2481
- } else {
2613
+ if (s2 === peg$FAILED) {
2614
+ break;
2615
+ }
2616
+ s1.push(s2);
2617
+ }
2618
+ if (s1.length < 1) {
2482
2619
  s1 = peg$FAILED;
2483
2620
  }
2484
2621
  if (s1 !== peg$FAILED) {
2485
2622
  s2 = [];
2486
- s3 = peg$currPos;
2487
- s4 = [];
2488
- s5 = input.charAt(peg$currPos);
2489
- if (peg$r0.test(s5)) {
2490
- peg$currPos++;
2491
- } else {
2492
- s5 = peg$FAILED;
2493
- if (peg$silentFails === 0) {
2494
- peg$fail(peg$e0);
2495
- }
2496
- }
2497
- if (s5 !== peg$FAILED) {
2498
- while (s5 !== peg$FAILED) {
2499
- s4.push(s5);
2623
+ for (;; ) {
2624
+ s3 = peg$currPos;
2625
+ s4 = [];
2626
+ for (;; ) {
2500
2627
  s5 = input.charAt(peg$currPos);
2501
- if (peg$r0.test(s5)) {
2628
+ if (peg$charCode = s5.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9) {
2502
2629
  peg$currPos++;
2503
2630
  } else {
2504
2631
  s5 = peg$FAILED;
@@ -2506,26 +2633,19 @@ function peg$parse(input, options) {
2506
2633
  peg$fail(peg$e0);
2507
2634
  }
2508
2635
  }
2509
- }
2510
- } else {
2511
- s4 = peg$FAILED;
2512
- }
2513
- if (s4 !== peg$FAILED) {
2514
- s5 = [];
2515
- s6 = input.charAt(peg$currPos);
2516
- if (peg$r1.test(s6)) {
2517
- peg$currPos++;
2518
- } else {
2519
- s6 = peg$FAILED;
2520
- if (peg$silentFails === 0) {
2521
- peg$fail(peg$e1);
2636
+ if (s5 === peg$FAILED) {
2637
+ break;
2522
2638
  }
2639
+ s4.push(s5);
2523
2640
  }
2524
- if (s6 !== peg$FAILED) {
2525
- while (s6 !== peg$FAILED) {
2526
- s5.push(s6);
2641
+ if (s4.length < 1) {
2642
+ s4 = peg$FAILED;
2643
+ }
2644
+ if (s4 !== peg$FAILED) {
2645
+ s5 = [];
2646
+ for (;; ) {
2527
2647
  s6 = input.charAt(peg$currPos);
2528
- if (peg$r1.test(s6)) {
2648
+ if (peg$charCode = s6.charCodeAt(0), peg$charCode === 13 || peg$charCode === 10) {
2529
2649
  peg$currPos++;
2530
2650
  } else {
2531
2651
  s6 = peg$FAILED;
@@ -2533,75 +2653,12 @@ function peg$parse(input, options) {
2533
2653
  peg$fail(peg$e1);
2534
2654
  }
2535
2655
  }
2536
- }
2537
- } else {
2538
- s5 = peg$FAILED;
2539
- }
2540
- if (s5 !== peg$FAILED) {
2541
- s4 = [s4, s5];
2542
- s3 = s4;
2543
- } else {
2544
- peg$currPos = s3;
2545
- s3 = peg$FAILED;
2546
- }
2547
- } else {
2548
- peg$currPos = s3;
2549
- s3 = peg$FAILED;
2550
- }
2551
- while (s3 !== peg$FAILED) {
2552
- s2.push(s3);
2553
- s3 = peg$currPos;
2554
- s4 = [];
2555
- s5 = input.charAt(peg$currPos);
2556
- if (peg$r0.test(s5)) {
2557
- peg$currPos++;
2558
- } else {
2559
- s5 = peg$FAILED;
2560
- if (peg$silentFails === 0) {
2561
- peg$fail(peg$e0);
2562
- }
2563
- }
2564
- if (s5 !== peg$FAILED) {
2565
- while (s5 !== peg$FAILED) {
2566
- s4.push(s5);
2567
- s5 = input.charAt(peg$currPos);
2568
- if (peg$r0.test(s5)) {
2569
- peg$currPos++;
2570
- } else {
2571
- s5 = peg$FAILED;
2572
- if (peg$silentFails === 0) {
2573
- peg$fail(peg$e0);
2574
- }
2575
- }
2576
- }
2577
- } else {
2578
- s4 = peg$FAILED;
2579
- }
2580
- if (s4 !== peg$FAILED) {
2581
- s5 = [];
2582
- s6 = input.charAt(peg$currPos);
2583
- if (peg$r1.test(s6)) {
2584
- peg$currPos++;
2585
- } else {
2586
- s6 = peg$FAILED;
2587
- if (peg$silentFails === 0) {
2588
- peg$fail(peg$e1);
2656
+ if (s6 === peg$FAILED) {
2657
+ break;
2589
2658
  }
2659
+ s5.push(s6);
2590
2660
  }
2591
- if (s6 !== peg$FAILED) {
2592
- while (s6 !== peg$FAILED) {
2593
- s5.push(s6);
2594
- s6 = input.charAt(peg$currPos);
2595
- if (peg$r1.test(s6)) {
2596
- peg$currPos++;
2597
- } else {
2598
- s6 = peg$FAILED;
2599
- if (peg$silentFails === 0) {
2600
- peg$fail(peg$e1);
2601
- }
2602
- }
2603
- }
2604
- } else {
2661
+ if (s5.length < 1) {
2605
2662
  s5 = peg$FAILED;
2606
2663
  }
2607
2664
  if (s5 !== peg$FAILED) {
@@ -2615,6 +2672,10 @@ function peg$parse(input, options) {
2615
2672
  peg$currPos = s3;
2616
2673
  s3 = peg$FAILED;
2617
2674
  }
2675
+ if (s3 === peg$FAILED) {
2676
+ break;
2677
+ }
2678
+ s2.push(s3);
2618
2679
  }
2619
2680
  s1 = [s1, s2];
2620
2681
  s0 = s1;
@@ -2628,7 +2689,7 @@ function peg$parse(input, options) {
2628
2689
  let s0, s1, s2, s3;
2629
2690
  s0 = peg$currPos;
2630
2691
  peg$savedPos = peg$currPos;
2631
- s1 = peg$f53();
2692
+ s1 = peg$f54();
2632
2693
  if (s1) {
2633
2694
  s1 = undefined;
2634
2695
  } else {
@@ -2691,19 +2752,9 @@ function peg$parse(input, options) {
2691
2752
  function peg$parse__() {
2692
2753
  let s0, s1;
2693
2754
  s0 = [];
2694
- s1 = input.charAt(peg$currPos);
2695
- if (peg$r0.test(s1)) {
2696
- peg$currPos++;
2697
- } else {
2698
- s1 = peg$FAILED;
2699
- if (peg$silentFails === 0) {
2700
- peg$fail(peg$e0);
2701
- }
2702
- }
2703
- while (s1 !== peg$FAILED) {
2704
- s0.push(s1);
2755
+ for (;; ) {
2705
2756
  s1 = input.charAt(peg$currPos);
2706
- if (peg$r0.test(s1)) {
2757
+ if (peg$charCode = s1.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9) {
2707
2758
  peg$currPos++;
2708
2759
  } else {
2709
2760
  s1 = peg$FAILED;
@@ -2711,23 +2762,29 @@ function peg$parse(input, options) {
2711
2762
  peg$fail(peg$e0);
2712
2763
  }
2713
2764
  }
2765
+ if (s1 === peg$FAILED) {
2766
+ break;
2767
+ }
2768
+ s0.push(s1);
2714
2769
  }
2715
2770
  return s0;
2716
2771
  }
2717
2772
  function peg$parse_() {
2718
2773
  let s0, s1;
2719
2774
  s0 = [];
2720
- s1 = peg$parsewhiteSpaceSymbol();
2721
- while (s1 !== peg$FAILED) {
2722
- s0.push(s1);
2775
+ for (;; ) {
2723
2776
  s1 = peg$parsewhiteSpaceSymbol();
2777
+ if (s1 === peg$FAILED) {
2778
+ break;
2779
+ }
2780
+ s0.push(s1);
2724
2781
  }
2725
2782
  return s0;
2726
2783
  }
2727
2784
  function peg$parsewhiteSpaceSymbol() {
2728
2785
  let s0;
2729
2786
  s0 = input.charAt(peg$currPos);
2730
- if (peg$r4.test(s0)) {
2787
+ if (peg$charCode = s0.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 10 || peg$charCode === 13) {
2731
2788
  peg$currPos++;
2732
2789
  } else {
2733
2790
  s0 = peg$FAILED;
@@ -2740,7 +2797,7 @@ function peg$parse(input, options) {
2740
2797
  function peg$parsereferenceSymbol() {
2741
2798
  let s0;
2742
2799
  s0 = input.charAt(peg$currPos);
2743
- if (peg$r5.test(s0)) {
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)) {
2744
2801
  peg$currPos++;
2745
2802
  } else {
2746
2803
  s0 = peg$FAILED;
@@ -2755,6 +2812,7 @@ function peg$parse(input, options) {
2755
2812
  let contextStack = [];
2756
2813
  let contextDepth = 0;
2757
2814
  const maxDepth = options.maxDepth ?? Infinity;
2815
+ const source = options.source ?? input;
2758
2816
  let unreadableLines = new Set;
2759
2817
  function resetState() {
2760
2818
  indentationStack = [0];
@@ -2827,7 +2885,7 @@ function peg$parse(input, options) {
2827
2885
  function getCurrentIndentation() {
2828
2886
  return indentationStack[indentationStack.length - 1];
2829
2887
  }
2830
- const delimitedReferences = new DelimitedReferences(input);
2888
+ const delimitedReferences = new DelimitedReferences(source);
2831
2889
  function parseQuotedStringAt(inputStr, startPos, quoteChar) {
2832
2890
  if (startPos >= inputStr.length || inputStr[startPos] !== quoteChar) {
2833
2891
  return null;
@@ -2870,6 +2928,7 @@ class Parser {
2870
2928
  this.maxInputSize = options.maxInputSize || 10 * 1024 * 1024;
2871
2929
  this.maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;
2872
2930
  this.comments = options.comments ?? true;
2931
+ this.syntax = options.syntax ?? true;
2873
2932
  }
2874
2933
  parse(input) {
2875
2934
  return this._parse(input, (raw) => this.transformResult(raw));
@@ -2877,6 +2936,10 @@ class Parser {
2877
2936
  parseGroups(input) {
2878
2937
  return this._parse(input, (raw) => raw.map((item) => this._transformGroup(item)));
2879
2938
  }
2939
+ parseCst(input) {
2940
+ this.parse(input);
2941
+ return buildCst(input, { comments: this.comments });
2942
+ }
2880
2943
  _transformGroup(item) {
2881
2944
  return new LinksGroup(this.transformLink(item), (item.children || []).map((child) => this._transformGroup(child)));
2882
2945
  }
@@ -2890,7 +2953,8 @@ class Parser {
2890
2953
  const prepared = this.comments ? stripComments(input) : input;
2891
2954
  try {
2892
2955
  const rawResult = peg$parse(prepared, {
2893
- maxDepth: this.maxDepth
2956
+ maxDepth: this.maxDepth,
2957
+ source: input
2894
2958
  });
2895
2959
  return transform(rawResult);
2896
2960
  } catch (error) {
@@ -2920,6 +2984,7 @@ class Parser {
2920
2984
  const childValues = item.children.map((child) => this.transformIndentedValue(child));
2921
2985
  const linkWithChildren = {
2922
2986
  id: item.id,
2987
+ rawId: item.rawId,
2923
2988
  values: childValues
2924
2989
  };
2925
2990
  const currentLink = this.transformLink(linkWithChildren);
@@ -2952,14 +3017,14 @@ class Parser {
2952
3017
  transformIndentedValue(item) {
2953
3018
  const children = item.children || [];
2954
3019
  if (children.length && item.id != null && !item.values?.length) {
2955
- return new Link(item.id, children.map((child) => this.transformIndentedValue(child)));
3020
+ return this._withRawId(new Link(item.id, children.map((child) => this.transformIndentedValue(child))), item);
2956
3021
  }
2957
3022
  const current = this.transformLink(item);
2958
3023
  if (children.length) {
2959
- return new Link(current.id, [
3024
+ return this._withRawId(new Link(current.id, [
2960
3025
  ...current.values,
2961
3026
  ...children.map((child) => this.transformIndentedValue(child))
2962
- ]);
3027
+ ]), item);
2963
3028
  }
2964
3029
  if (item.id == null && item.nested === undefined && current.values.length === 1) {
2965
3030
  return current.values[0];
@@ -3004,14 +3069,20 @@ class Parser {
3004
3069
  return this.transformNested(item.nested);
3005
3070
  }
3006
3071
  if (item.id !== undefined && !item.values && !item.children) {
3007
- return new Link(item.id);
3072
+ return this._withRawId(new Link(item.id), item);
3008
3073
  }
3009
3074
  if (item.values && Array.isArray(item.values)) {
3010
- const link = new Link(item.id ?? null, []);
3075
+ const link = this._withRawId(new Link(item.id ?? null, []), item);
3011
3076
  link.values = item.values.map((v) => this.transformLink(v));
3012
3077
  return link;
3013
3078
  }
3014
- return new Link(item.id ?? null, []);
3079
+ return this._withRawId(new Link(item.id ?? null, []), item);
3080
+ }
3081
+ _withRawId(link, item) {
3082
+ if (this.syntax && link.id !== null && typeof item.rawId === "string") {
3083
+ link.rawId = item.rawId;
3084
+ }
3085
+ return link;
3015
3086
  }
3016
3087
  }
3017
3088
 
@@ -3354,34 +3425,48 @@ function countNewlines(value) {
3354
3425
  }
3355
3426
  function structurallyComplete(document, comments) {
3356
3427
  const quotes = ['"', "'", "`"];
3357
- const beforeReference = [" ", "\t", `
3358
- `, "\r", "(", ":"];
3428
+ const separators = [" ", "\t", `
3429
+ `, "\r", "(", ":", ")"];
3359
3430
  const beforeComment = [" ", "\t", `
3360
3431
  `, "\r"];
3361
3432
  const references = new DelimitedReferences(document);
3362
3433
  let depth = 0;
3434
+ let tokenStart = true;
3363
3435
  for (let position = 0;position < document.length; position++) {
3364
3436
  const character = document[position];
3365
3437
  const previous = position === 0 ? null : document[position - 1];
3366
- if (quotes.includes(character) && (previous === null || beforeReference.includes(previous))) {
3367
- const end = references.endAt(position);
3368
- if (end === null)
3369
- return false;
3370
- position = end - 1;
3371
- continue;
3372
- }
3373
3438
  if (comments && character === "#" && (previous === null || beforeComment.includes(previous))) {
3374
3439
  const newline = document.indexOf(`
3375
3440
  `, position);
3376
3441
  if (newline === -1)
3377
3442
  return true;
3378
3443
  position = newline;
3444
+ tokenStart = true;
3379
3445
  continue;
3380
3446
  }
3381
- if (character === "(")
3382
- depth += 1;
3383
- if (character === ")")
3384
- depth -= 1;
3447
+ if (separators.includes(character)) {
3448
+ if (character === "(")
3449
+ depth += 1;
3450
+ if (character === ")")
3451
+ depth -= 1;
3452
+ tokenStart = true;
3453
+ continue;
3454
+ }
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;
3385
3470
  }
3386
3471
  return depth === 0;
3387
3472
  }
@@ -3985,6 +4070,8 @@ export {
3985
4070
  ArityRange,
3986
4071
  BinaryLinoCodec,
3987
4072
  BinaryLinoOptions,
4073
+ CstKind,
4074
+ CstNode,
3988
4075
  DEFAULT_MAX_DEPTH,
3989
4076
  DecodeLimits,
3990
4077
  External,
@@ -4007,6 +4094,7 @@ export {
4007
4094
  formatIndentedDocument,
4008
4095
  formatLinks,
4009
4096
  parseIndentedDocument,
4097
+ referenceQuote,
4010
4098
  stripComments,
4011
4099
  unescapeReference
4012
4100
  };