links-notation 0.21.2 → 0.22.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.
@@ -182,11 +182,11 @@ function peg$parse(input, options) {
182
182
 
183
183
  const peg$e0 = peg$classExpectation([" ", "\t"], false, false, false);
184
184
  const peg$e1 = peg$classExpectation(["\r", "\n"], false, false, false);
185
- const peg$e2 = peg$literalExpectation("(", false);
186
- const peg$e3 = peg$literalExpectation(")", false);
187
- const peg$e4 = peg$literalExpectation(":", false);
188
- const peg$e5 = peg$literalExpectation("\"", false);
189
- const peg$e6 = peg$anyExpectation();
185
+ const peg$e2 = peg$anyExpectation();
186
+ const peg$e3 = peg$literalExpectation("(", false);
187
+ const peg$e4 = peg$literalExpectation(")", false);
188
+ const peg$e5 = peg$literalExpectation(":", false);
189
+ const peg$e6 = peg$literalExpectation("\"", false);
190
190
  const peg$e7 = peg$literalExpectation("'", false);
191
191
  const peg$e8 = peg$literalExpectation("`", false);
192
192
  const peg$e9 = peg$literalExpectation(" ", false);
@@ -200,31 +200,43 @@ function peg$parse(input, options) {
200
200
  function peg$f4(fl, list) { popIndentation(); return [fl].concat(list || []); }
201
201
  function peg$f5(l) { return l; }
202
202
  function peg$f6(l) { return l; }
203
- function peg$f7(e, l) {
203
+ function peg$f7() { return !unreadableLines.has(lineKey(offset())); }
204
+ function peg$f8(start, e) { return checkDepth(depth(), start); }
205
+ function peg$f9(start, e, saved, l) {
206
+ if (l === null) {
207
+ // No child line followed the indentation. Forget what looking for one
208
+ // pushed, so the next line is compared with this line's indentation.
209
+ indentationStack = saved;
210
+ return e;
211
+ }
204
212
  return Object.assign({}, e, { children: l });
205
213
  }
206
- function peg$f8(e) { return e; }
207
- function peg$f9(l) { return l; }
208
- function peg$f10(i) { return { id: i }; }
209
- function peg$f11(ml) { return ml; }
210
- function peg$f12(il) { return il; }
211
- function peg$f13(sl) { return sl; }
212
- function peg$f14(fl) { return fl; }
213
- function peg$f15(vl) { return vl; }
214
- function peg$f16(body) {
214
+ function peg$f10() { unreadableLines.add(lineKey(offset())); return false; }
215
+ function peg$f11(l) { return l; }
216
+ function peg$f12(i) { return { id: i }; }
217
+ function peg$f13(g, rest) {
218
+ return rest === null ? g : { values: [g].concat(rest) };
219
+ }
220
+ function peg$f14() { return null; }
221
+ function peg$f15(fl) { return fl; }
222
+ function peg$f16(vl) { return vl; }
223
+ function peg$f17(start) { return checkDepth(depth() + 1, start); }
224
+ function peg$f18(start, body) {
215
225
  exitNestedContext();
216
226
  return body;
217
227
  }
218
- function peg$f17(l) { return { nested: l }; }
219
- function peg$f18() { return { nested: [] }; }
220
- function peg$f19() { return enterNestedContext(); }
221
- function peg$f20(value) { return value; }
222
- function peg$f21(list) { return list; }
223
- function peg$f22(id, v) { return { id: id, values: v }; }
224
- function peg$f23(v) { return { values: v }; }
225
- function peg$f24(id) { return { id: id, values: [] }; }
226
- function peg$f25(chars) { return chars.join(''); }
227
- function peg$f26() {
228
+ function peg$f19() { exitNestedContext(); return false; }
229
+ function peg$f20(l) { return { nested: l }; }
230
+ function peg$f21() { return { nested: [] }; }
231
+ function peg$f22() { return enterNestedContext(); }
232
+ function peg$f23() { return location(); }
233
+ function peg$f24(value) { return value; }
234
+ function peg$f25(list) { return list; }
235
+ function peg$f26(id, v) { return { id: id, values: v }; }
236
+ function peg$f27(v) { return { values: v }; }
237
+ function peg$f28(id) { return { id: id, values: [] }; }
238
+ function peg$f29(chars) { return chars.join(''); }
239
+ function peg$f30() {
228
240
  const pos = offset();
229
241
  const result = parseQuotedStringAt(input, pos, '"');
230
242
  if (result) {
@@ -234,11 +246,11 @@ function peg$parse(input, options) {
234
246
  }
235
247
  return false;
236
248
  }
237
- function peg$f27(chars) { return parsedValue; }
238
- function peg$f28(c, cs) { return [c].concat(cs).join(''); }
239
- function peg$f29() { return parsedLength > 1 && (parsedLength--, true); }
240
- function peg$f30(c) { return c; }
241
- function peg$f31() {
249
+ function peg$f31(chars) { return parsedValue; }
250
+ function peg$f32(c, cs) { return [c].concat(cs).join(''); }
251
+ function peg$f33() { return parsedLength > 1 && (parsedLength--, true); }
252
+ function peg$f34(c) { return c; }
253
+ function peg$f35() {
242
254
  const pos = offset();
243
255
  const result = parseQuotedStringAt(input, pos, "'");
244
256
  if (result) {
@@ -248,11 +260,11 @@ function peg$parse(input, options) {
248
260
  }
249
261
  return false;
250
262
  }
251
- function peg$f32(chars) { return parsedValue; }
252
- function peg$f33(c, cs) { return [c].concat(cs).join(''); }
253
- function peg$f34() { return parsedLength > 1 && (parsedLength--, true); }
254
- function peg$f35(c) { return c; }
255
- function peg$f36() {
263
+ function peg$f36(chars) { return parsedValue; }
264
+ function peg$f37(c, cs) { return [c].concat(cs).join(''); }
265
+ function peg$f38() { return parsedLength > 1 && (parsedLength--, true); }
266
+ function peg$f39(c) { return c; }
267
+ function peg$f40() {
256
268
  const pos = offset();
257
269
  const result = parseQuotedStringAt(input, pos, '`');
258
270
  if (result) {
@@ -262,15 +274,16 @@ function peg$parse(input, options) {
262
274
  }
263
275
  return false;
264
276
  }
265
- function peg$f37(chars) { return parsedValue; }
266
- function peg$f38(c, cs) { return [c].concat(cs).join(''); }
267
- function peg$f39() { return parsedLength > 1 && (parsedLength--, true); }
268
- function peg$f40(c) { return c; }
269
- function peg$f41(spaces) { setBaseIndentation(spaces); }
270
- function peg$f42(spaces) { return normalizeIndentation(spaces) > getCurrentIndentation(); }
271
- function peg$f43(spaces) { pushIndentation(spaces); }
272
- function peg$f44(spaces) { return checkIndentation(spaces); }
273
- function peg$f45() { return isInsideNestedContext(); }
277
+ function peg$f41(chars) { return parsedValue; }
278
+ function peg$f42(c, cs) { return [c].concat(cs).join(''); }
279
+ function peg$f43() { return parsedLength > 1 && (parsedLength--, true); }
280
+ function peg$f44(c) { return c; }
281
+ function peg$f45() { return indentationStack.slice(); }
282
+ function peg$f46(spaces) { setBaseIndentation(spaces); }
283
+ function peg$f47(spaces) { return normalizeIndentation(spaces) > getCurrentIndentation(); }
284
+ function peg$f48(spaces) { pushIndentation(spaces); }
285
+ function peg$f49(spaces) { return checkIndentation(spaces); }
286
+ function peg$f50() { return isInsideNestedContext(); }
274
287
  let peg$currPos = options.peg$currPos | 0;
275
288
  let peg$savedPos = peg$currPos;
276
289
  const peg$posDetailsCache = [{ line: 1, column: 1 }];
@@ -640,17 +653,48 @@ function peg$parse(input, options) {
640
653
  }
641
654
 
642
655
  function peg$parseelement() {
643
- let s0, s1, s2, s3;
656
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
644
657
 
645
658
  s0 = peg$currPos;
646
- s1 = peg$parseanyLink();
659
+ peg$savedPos = peg$currPos;
660
+ s1 = peg$f7();
661
+ if (s1) {
662
+ s1 = undefined;
663
+ } else {
664
+ s1 = peg$FAILED;
665
+ }
647
666
  if (s1 !== peg$FAILED) {
648
- s2 = peg$parsePUSH_INDENTATION();
649
- if (s2 !== peg$FAILED) {
650
- s3 = peg$parselinks();
651
- if (s3 !== peg$FAILED) {
667
+ s2 = peg$parseHERE();
668
+ s3 = peg$parseanyLink();
669
+ if (s3 !== peg$FAILED) {
670
+ peg$savedPos = peg$currPos;
671
+ s4 = peg$f8(s2, s3);
672
+ if (s4) {
673
+ s4 = undefined;
674
+ } else {
675
+ s4 = peg$FAILED;
676
+ }
677
+ if (s4 !== peg$FAILED) {
678
+ s5 = peg$parseSAVE_INDENTATION();
679
+ s6 = peg$currPos;
680
+ s7 = peg$parsePUSH_INDENTATION();
681
+ if (s7 !== peg$FAILED) {
682
+ s8 = peg$parselinks();
683
+ if (s8 !== peg$FAILED) {
684
+ s6 = s8;
685
+ } else {
686
+ peg$currPos = s6;
687
+ s6 = peg$FAILED;
688
+ }
689
+ } else {
690
+ peg$currPos = s6;
691
+ s6 = peg$FAILED;
692
+ }
693
+ if (s6 === peg$FAILED) {
694
+ s6 = null;
695
+ }
652
696
  peg$savedPos = s0;
653
- s0 = peg$f7(s1, s3);
697
+ s0 = peg$f9(s2, s3, s5, s6);
654
698
  } else {
655
699
  peg$currPos = s0;
656
700
  s0 = peg$FAILED;
@@ -665,12 +709,32 @@ function peg$parse(input, options) {
665
709
  }
666
710
  if (s0 === peg$FAILED) {
667
711
  s0 = peg$currPos;
668
- s1 = peg$parseanyLink();
712
+ peg$savedPos = peg$currPos;
713
+ s1 = peg$f10();
714
+ if (s1) {
715
+ s1 = undefined;
716
+ } else {
717
+ s1 = peg$FAILED;
718
+ }
669
719
  if (s1 !== peg$FAILED) {
670
- peg$savedPos = s0;
671
- s1 = peg$f8(s1);
720
+ if (input.length > peg$currPos) {
721
+ s2 = input.charAt(peg$currPos);
722
+ peg$currPos++;
723
+ } else {
724
+ s2 = peg$FAILED;
725
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
726
+ }
727
+ if (s2 !== peg$FAILED) {
728
+ s1 = [s1, s2];
729
+ s0 = s1;
730
+ } else {
731
+ peg$currPos = s0;
732
+ s0 = peg$FAILED;
733
+ }
734
+ } else {
735
+ peg$currPos = s0;
736
+ s0 = peg$FAILED;
672
737
  }
673
- s0 = s1;
674
738
  }
675
739
 
676
740
  return s0;
@@ -683,7 +747,7 @@ function peg$parse(input, options) {
683
747
  s1 = peg$parsenestedGroup();
684
748
  if (s1 !== peg$FAILED) {
685
749
  peg$savedPos = s0;
686
- s1 = peg$f9(s1);
750
+ s1 = peg$f11(s1);
687
751
  }
688
752
  s0 = s1;
689
753
  if (s0 === peg$FAILED) {
@@ -691,7 +755,7 @@ function peg$parse(input, options) {
691
755
  s1 = peg$parsereference();
692
756
  if (s1 !== peg$FAILED) {
693
757
  peg$savedPos = s0;
694
- s1 = peg$f10(s1);
758
+ s1 = peg$f12(s1);
695
759
  }
696
760
  s0 = s1;
697
761
  }
@@ -703,12 +767,26 @@ function peg$parse(input, options) {
703
767
  let s0, s1, s2;
704
768
 
705
769
  s0 = peg$currPos;
706
- s1 = peg$parsenestedGroup();
770
+ s1 = peg$currPos;
771
+ peg$silentFails++;
772
+ if (input.charCodeAt(peg$currPos) === 40) {
773
+ s2 = peg$c0;
774
+ peg$currPos++;
775
+ } else {
776
+ s2 = peg$FAILED;
777
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
778
+ }
779
+ peg$silentFails--;
780
+ if (s2 !== peg$FAILED) {
781
+ peg$currPos = s1;
782
+ s1 = undefined;
783
+ } else {
784
+ s1 = peg$FAILED;
785
+ }
707
786
  if (s1 !== peg$FAILED) {
708
- s2 = peg$parseeol();
787
+ s2 = peg$parsegroupLink();
709
788
  if (s2 !== peg$FAILED) {
710
- peg$savedPos = s0;
711
- s0 = peg$f11(s1);
789
+ s0 = s2;
712
790
  } else {
713
791
  peg$currPos = s0;
714
792
  s0 = peg$FAILED;
@@ -719,20 +797,88 @@ function peg$parse(input, options) {
719
797
  }
720
798
  if (s0 === peg$FAILED) {
721
799
  s0 = peg$currPos;
722
- s1 = peg$parseindentedIdLink();
800
+ s1 = peg$currPos;
801
+ peg$silentFails++;
802
+ if (input.charCodeAt(peg$currPos) === 40) {
803
+ s2 = peg$c0;
804
+ peg$currPos++;
805
+ } else {
806
+ s2 = peg$FAILED;
807
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
808
+ }
809
+ peg$silentFails--;
810
+ if (s2 === peg$FAILED) {
811
+ s1 = undefined;
812
+ } else {
813
+ peg$currPos = s1;
814
+ s1 = peg$FAILED;
815
+ }
723
816
  if (s1 !== peg$FAILED) {
817
+ s2 = peg$parseindentedIdLink();
818
+ if (s2 === peg$FAILED) {
819
+ s2 = peg$parsesingleLineAnyLink();
820
+ }
821
+ if (s2 !== peg$FAILED) {
822
+ s0 = s2;
823
+ } else {
824
+ peg$currPos = s0;
825
+ s0 = peg$FAILED;
826
+ }
827
+ } else {
828
+ peg$currPos = s0;
829
+ s0 = peg$FAILED;
830
+ }
831
+ }
832
+
833
+ return s0;
834
+ }
835
+
836
+ function peg$parsegroupLink() {
837
+ let s0, s1, s2;
838
+
839
+ s0 = peg$currPos;
840
+ s1 = peg$parsenestedGroup();
841
+ if (s1 !== peg$FAILED) {
842
+ s2 = peg$parsegroupLinkRest();
843
+ if (s2 !== peg$FAILED) {
724
844
  peg$savedPos = s0;
725
- s1 = peg$f12(s1);
845
+ s0 = peg$f13(s1, s2);
846
+ } else {
847
+ peg$currPos = s0;
848
+ s0 = peg$FAILED;
726
849
  }
727
- s0 = s1;
728
- if (s0 === peg$FAILED) {
729
- s0 = peg$currPos;
730
- s1 = peg$parsesingleLineAnyLink();
731
- if (s1 !== peg$FAILED) {
732
- peg$savedPos = s0;
733
- s1 = peg$f13(s1);
734
- }
850
+ } else {
851
+ peg$currPos = s0;
852
+ s0 = peg$FAILED;
853
+ }
854
+
855
+ return s0;
856
+ }
857
+
858
+ function peg$parsegroupLinkRest() {
859
+ let s0, s1, s2;
860
+
861
+ s0 = peg$currPos;
862
+ s1 = peg$parseeol();
863
+ if (s1 !== peg$FAILED) {
864
+ peg$savedPos = s0;
865
+ s1 = peg$f14();
866
+ }
867
+ s0 = s1;
868
+ if (s0 === peg$FAILED) {
869
+ s0 = peg$currPos;
870
+ s1 = [];
871
+ s2 = peg$parsesingleLineValueAndWhitespace();
872
+ while (s2 !== peg$FAILED) {
873
+ s1.push(s2);
874
+ s2 = peg$parsesingleLineValueAndWhitespace();
875
+ }
876
+ s2 = peg$parseeol();
877
+ if (s2 !== peg$FAILED) {
735
878
  s0 = s1;
879
+ } else {
880
+ peg$currPos = s0;
881
+ s0 = peg$FAILED;
736
882
  }
737
883
  }
738
884
 
@@ -748,7 +894,7 @@ function peg$parse(input, options) {
748
894
  s2 = peg$parseeol();
749
895
  if (s2 !== peg$FAILED) {
750
896
  peg$savedPos = s0;
751
- s0 = peg$f14(s1);
897
+ s0 = peg$f15(s1);
752
898
  } else {
753
899
  peg$currPos = s0;
754
900
  s0 = peg$FAILED;
@@ -764,7 +910,7 @@ function peg$parse(input, options) {
764
910
  s2 = peg$parseeol();
765
911
  if (s2 !== peg$FAILED) {
766
912
  peg$savedPos = s0;
767
- s0 = peg$f15(s1);
913
+ s0 = peg$f16(s1);
768
914
  } else {
769
915
  peg$currPos = s0;
770
916
  s0 = peg$FAILED;
@@ -779,23 +925,36 @@ function peg$parse(input, options) {
779
925
  }
780
926
 
781
927
  function peg$parsenestedGroup() {
782
- let s0, s1, s2, s3;
928
+ let s0, s1, s2, s3, s4, s5;
783
929
 
784
930
  s0 = peg$currPos;
931
+ s1 = peg$parseHERE();
785
932
  if (input.charCodeAt(peg$currPos) === 40) {
786
- s1 = peg$c0;
933
+ s2 = peg$c0;
787
934
  peg$currPos++;
788
935
  } else {
789
- s1 = peg$FAILED;
790
- if (peg$silentFails === 0) { peg$fail(peg$e2); }
936
+ s2 = peg$FAILED;
937
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
791
938
  }
792
- if (s1 !== peg$FAILED) {
793
- s2 = peg$parseENTER_NESTED_CONTEXT();
794
- if (s2 !== peg$FAILED) {
795
- s3 = peg$parsenestedGroupBody();
796
- if (s3 !== peg$FAILED) {
797
- peg$savedPos = s0;
798
- s0 = peg$f16(s3);
939
+ if (s2 !== peg$FAILED) {
940
+ peg$savedPos = peg$currPos;
941
+ s3 = peg$f17(s1);
942
+ if (s3) {
943
+ s3 = undefined;
944
+ } else {
945
+ s3 = peg$FAILED;
946
+ }
947
+ if (s3 !== peg$FAILED) {
948
+ s4 = peg$parseENTER_NESTED_CONTEXT();
949
+ if (s4 !== peg$FAILED) {
950
+ s5 = peg$parsenestedGroupBody();
951
+ if (s5 !== peg$FAILED) {
952
+ peg$savedPos = s0;
953
+ s0 = peg$f18(s1, s5);
954
+ } else {
955
+ peg$currPos = s0;
956
+ s0 = peg$FAILED;
957
+ }
799
958
  } else {
800
959
  peg$currPos = s0;
801
960
  s0 = peg$FAILED;
@@ -808,6 +967,35 @@ function peg$parse(input, options) {
808
967
  peg$currPos = s0;
809
968
  s0 = peg$FAILED;
810
969
  }
970
+ if (s0 === peg$FAILED) {
971
+ s0 = peg$currPos;
972
+ if (input.charCodeAt(peg$currPos) === 40) {
973
+ s1 = peg$c0;
974
+ peg$currPos++;
975
+ } else {
976
+ s1 = peg$FAILED;
977
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
978
+ }
979
+ if (s1 !== peg$FAILED) {
980
+ peg$savedPos = peg$currPos;
981
+ s2 = peg$f19();
982
+ if (s2) {
983
+ s2 = undefined;
984
+ } else {
985
+ s2 = peg$FAILED;
986
+ }
987
+ if (s2 !== peg$FAILED) {
988
+ s1 = [s1, s2];
989
+ s0 = s1;
990
+ } else {
991
+ peg$currPos = s0;
992
+ s0 = peg$FAILED;
993
+ }
994
+ } else {
995
+ peg$currPos = s0;
996
+ s0 = peg$FAILED;
997
+ }
998
+ }
811
999
 
812
1000
  return s0;
813
1001
  }
@@ -825,11 +1013,11 @@ function peg$parse(input, options) {
825
1013
  peg$currPos++;
826
1014
  } else {
827
1015
  s4 = peg$FAILED;
828
- if (peg$silentFails === 0) { peg$fail(peg$e3); }
1016
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
829
1017
  }
830
1018
  if (s4 !== peg$FAILED) {
831
1019
  peg$savedPos = s0;
832
- s0 = peg$f17(s2);
1020
+ s0 = peg$f20(s2);
833
1021
  } else {
834
1022
  peg$currPos = s0;
835
1023
  s0 = peg$FAILED;
@@ -846,11 +1034,11 @@ function peg$parse(input, options) {
846
1034
  peg$currPos++;
847
1035
  } else {
848
1036
  s2 = peg$FAILED;
849
- if (peg$silentFails === 0) { peg$fail(peg$e3); }
1037
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
850
1038
  }
851
1039
  if (s2 !== peg$FAILED) {
852
1040
  peg$savedPos = s0;
853
- s0 = peg$f18();
1041
+ s0 = peg$f21();
854
1042
  } else {
855
1043
  peg$currPos = s0;
856
1044
  s0 = peg$FAILED;
@@ -864,7 +1052,7 @@ function peg$parse(input, options) {
864
1052
  let s0;
865
1053
 
866
1054
  peg$savedPos = peg$currPos;
867
- s0 = peg$f19();
1055
+ s0 = peg$f22();
868
1056
  if (s0) {
869
1057
  s0 = undefined;
870
1058
  } else {
@@ -874,6 +1062,18 @@ function peg$parse(input, options) {
874
1062
  return s0;
875
1063
  }
876
1064
 
1065
+ function peg$parseHERE() {
1066
+ let s0, s1;
1067
+
1068
+ s0 = peg$currPos;
1069
+ s1 = '';
1070
+ peg$savedPos = s0;
1071
+ s1 = peg$f23();
1072
+ s0 = s1;
1073
+
1074
+ return s0;
1075
+ }
1076
+
877
1077
  function peg$parsesingleLineValueAndWhitespace() {
878
1078
  let s0, s1, s2;
879
1079
 
@@ -882,7 +1082,7 @@ function peg$parse(input, options) {
882
1082
  s2 = peg$parsereferenceOrLink();
883
1083
  if (s2 !== peg$FAILED) {
884
1084
  peg$savedPos = s0;
885
- s0 = peg$f20(s2);
1085
+ s0 = peg$f24(s2);
886
1086
  } else {
887
1087
  peg$currPos = s0;
888
1088
  s0 = peg$FAILED;
@@ -907,7 +1107,7 @@ function peg$parse(input, options) {
907
1107
  }
908
1108
  if (s1 !== peg$FAILED) {
909
1109
  peg$savedPos = s0;
910
- s1 = peg$f21(s1);
1110
+ s1 = peg$f25(s1);
911
1111
  }
912
1112
  s0 = s1;
913
1113
 
@@ -927,13 +1127,13 @@ function peg$parse(input, options) {
927
1127
  peg$currPos++;
928
1128
  } else {
929
1129
  s4 = peg$FAILED;
930
- if (peg$silentFails === 0) { peg$fail(peg$e4); }
1130
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
931
1131
  }
932
1132
  if (s4 !== peg$FAILED) {
933
1133
  s5 = peg$parsesingleLineValues();
934
1134
  if (s5 !== peg$FAILED) {
935
1135
  peg$savedPos = s0;
936
- s0 = peg$f22(s2, s5);
1136
+ s0 = peg$f26(s2, s5);
937
1137
  } else {
938
1138
  peg$currPos = s0;
939
1139
  s0 = peg$FAILED;
@@ -957,7 +1157,7 @@ function peg$parse(input, options) {
957
1157
  s1 = peg$parsesingleLineValues();
958
1158
  if (s1 !== peg$FAILED) {
959
1159
  peg$savedPos = s0;
960
- s1 = peg$f23(s1);
1160
+ s1 = peg$f27(s1);
961
1161
  }
962
1162
  s0 = s1;
963
1163
 
@@ -976,13 +1176,13 @@ function peg$parse(input, options) {
976
1176
  peg$currPos++;
977
1177
  } else {
978
1178
  s3 = peg$FAILED;
979
- if (peg$silentFails === 0) { peg$fail(peg$e4); }
1179
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
980
1180
  }
981
1181
  if (s3 !== peg$FAILED) {
982
1182
  s4 = peg$parseeol();
983
1183
  if (s4 !== peg$FAILED) {
984
1184
  peg$savedPos = s0;
985
- s0 = peg$f24(s1);
1185
+ s0 = peg$f28(s1);
986
1186
  } else {
987
1187
  peg$currPos = s0;
988
1188
  s0 = peg$FAILED;
@@ -1026,7 +1226,7 @@ function peg$parse(input, options) {
1026
1226
  }
1027
1227
  if (s1 !== peg$FAILED) {
1028
1228
  peg$savedPos = s0;
1029
- s1 = peg$f25(s1);
1229
+ s1 = peg$f29(s1);
1030
1230
  }
1031
1231
  s0 = s1;
1032
1232
 
@@ -1058,7 +1258,7 @@ function peg$parse(input, options) {
1058
1258
  peg$currPos++;
1059
1259
  } else {
1060
1260
  s2 = peg$FAILED;
1061
- if (peg$silentFails === 0) { peg$fail(peg$e5); }
1261
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
1062
1262
  }
1063
1263
  peg$silentFails--;
1064
1264
  if (s2 !== peg$FAILED) {
@@ -1069,7 +1269,7 @@ function peg$parse(input, options) {
1069
1269
  }
1070
1270
  if (s1 !== peg$FAILED) {
1071
1271
  peg$savedPos = peg$currPos;
1072
- s2 = peg$f26();
1272
+ s2 = peg$f30();
1073
1273
  if (s2) {
1074
1274
  s2 = undefined;
1075
1275
  } else {
@@ -1079,7 +1279,7 @@ function peg$parse(input, options) {
1079
1279
  s3 = peg$parseconsumeDouble();
1080
1280
  if (s3 !== peg$FAILED) {
1081
1281
  peg$savedPos = s0;
1082
- s0 = peg$f27(s3);
1282
+ s0 = peg$f31(s3);
1083
1283
  } else {
1084
1284
  peg$currPos = s0;
1085
1285
  s0 = peg$FAILED;
@@ -1105,7 +1305,7 @@ function peg$parse(input, options) {
1105
1305
  peg$currPos++;
1106
1306
  } else {
1107
1307
  s1 = peg$FAILED;
1108
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1308
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1109
1309
  }
1110
1310
  if (s1 !== peg$FAILED) {
1111
1311
  s2 = [];
@@ -1115,7 +1315,7 @@ function peg$parse(input, options) {
1115
1315
  s3 = peg$parseconsumeDoubleMore();
1116
1316
  }
1117
1317
  peg$savedPos = s0;
1118
- s0 = peg$f28(s1, s2);
1318
+ s0 = peg$f32(s1, s2);
1119
1319
  } else {
1120
1320
  peg$currPos = s0;
1121
1321
  s0 = peg$FAILED;
@@ -1129,7 +1329,7 @@ function peg$parse(input, options) {
1129
1329
 
1130
1330
  s0 = peg$currPos;
1131
1331
  peg$savedPos = peg$currPos;
1132
- s1 = peg$f29();
1332
+ s1 = peg$f33();
1133
1333
  if (s1) {
1134
1334
  s1 = undefined;
1135
1335
  } else {
@@ -1141,11 +1341,11 @@ function peg$parse(input, options) {
1141
1341
  peg$currPos++;
1142
1342
  } else {
1143
1343
  s2 = peg$FAILED;
1144
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1344
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1145
1345
  }
1146
1346
  if (s2 !== peg$FAILED) {
1147
1347
  peg$savedPos = s0;
1148
- s0 = peg$f30(s2);
1348
+ s0 = peg$f34(s2);
1149
1349
  } else {
1150
1350
  peg$currPos = s0;
1151
1351
  s0 = peg$FAILED;
@@ -1180,7 +1380,7 @@ function peg$parse(input, options) {
1180
1380
  }
1181
1381
  if (s1 !== peg$FAILED) {
1182
1382
  peg$savedPos = peg$currPos;
1183
- s2 = peg$f31();
1383
+ s2 = peg$f35();
1184
1384
  if (s2) {
1185
1385
  s2 = undefined;
1186
1386
  } else {
@@ -1190,7 +1390,7 @@ function peg$parse(input, options) {
1190
1390
  s3 = peg$parseconsumeSingle();
1191
1391
  if (s3 !== peg$FAILED) {
1192
1392
  peg$savedPos = s0;
1193
- s0 = peg$f32(s3);
1393
+ s0 = peg$f36(s3);
1194
1394
  } else {
1195
1395
  peg$currPos = s0;
1196
1396
  s0 = peg$FAILED;
@@ -1216,7 +1416,7 @@ function peg$parse(input, options) {
1216
1416
  peg$currPos++;
1217
1417
  } else {
1218
1418
  s1 = peg$FAILED;
1219
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1419
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1220
1420
  }
1221
1421
  if (s1 !== peg$FAILED) {
1222
1422
  s2 = [];
@@ -1226,7 +1426,7 @@ function peg$parse(input, options) {
1226
1426
  s3 = peg$parseconsumeSingleMore();
1227
1427
  }
1228
1428
  peg$savedPos = s0;
1229
- s0 = peg$f33(s1, s2);
1429
+ s0 = peg$f37(s1, s2);
1230
1430
  } else {
1231
1431
  peg$currPos = s0;
1232
1432
  s0 = peg$FAILED;
@@ -1240,7 +1440,7 @@ function peg$parse(input, options) {
1240
1440
 
1241
1441
  s0 = peg$currPos;
1242
1442
  peg$savedPos = peg$currPos;
1243
- s1 = peg$f34();
1443
+ s1 = peg$f38();
1244
1444
  if (s1) {
1245
1445
  s1 = undefined;
1246
1446
  } else {
@@ -1252,11 +1452,11 @@ function peg$parse(input, options) {
1252
1452
  peg$currPos++;
1253
1453
  } else {
1254
1454
  s2 = peg$FAILED;
1255
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1455
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1256
1456
  }
1257
1457
  if (s2 !== peg$FAILED) {
1258
1458
  peg$savedPos = s0;
1259
- s0 = peg$f35(s2);
1459
+ s0 = peg$f39(s2);
1260
1460
  } else {
1261
1461
  peg$currPos = s0;
1262
1462
  s0 = peg$FAILED;
@@ -1291,7 +1491,7 @@ function peg$parse(input, options) {
1291
1491
  }
1292
1492
  if (s1 !== peg$FAILED) {
1293
1493
  peg$savedPos = peg$currPos;
1294
- s2 = peg$f36();
1494
+ s2 = peg$f40();
1295
1495
  if (s2) {
1296
1496
  s2 = undefined;
1297
1497
  } else {
@@ -1301,7 +1501,7 @@ function peg$parse(input, options) {
1301
1501
  s3 = peg$parseconsumeBacktick();
1302
1502
  if (s3 !== peg$FAILED) {
1303
1503
  peg$savedPos = s0;
1304
- s0 = peg$f37(s3);
1504
+ s0 = peg$f41(s3);
1305
1505
  } else {
1306
1506
  peg$currPos = s0;
1307
1507
  s0 = peg$FAILED;
@@ -1327,7 +1527,7 @@ function peg$parse(input, options) {
1327
1527
  peg$currPos++;
1328
1528
  } else {
1329
1529
  s1 = peg$FAILED;
1330
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1530
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1331
1531
  }
1332
1532
  if (s1 !== peg$FAILED) {
1333
1533
  s2 = [];
@@ -1337,7 +1537,7 @@ function peg$parse(input, options) {
1337
1537
  s3 = peg$parseconsumeBacktickMore();
1338
1538
  }
1339
1539
  peg$savedPos = s0;
1340
- s0 = peg$f38(s1, s2);
1540
+ s0 = peg$f42(s1, s2);
1341
1541
  } else {
1342
1542
  peg$currPos = s0;
1343
1543
  s0 = peg$FAILED;
@@ -1351,7 +1551,7 @@ function peg$parse(input, options) {
1351
1551
 
1352
1552
  s0 = peg$currPos;
1353
1553
  peg$savedPos = peg$currPos;
1354
- s1 = peg$f39();
1554
+ s1 = peg$f43();
1355
1555
  if (s1) {
1356
1556
  s1 = undefined;
1357
1557
  } else {
@@ -1363,11 +1563,11 @@ function peg$parse(input, options) {
1363
1563
  peg$currPos++;
1364
1564
  } else {
1365
1565
  s2 = peg$FAILED;
1366
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1566
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1367
1567
  }
1368
1568
  if (s2 !== peg$FAILED) {
1369
1569
  peg$savedPos = s0;
1370
- s0 = peg$f40(s2);
1570
+ s0 = peg$f44(s2);
1371
1571
  } else {
1372
1572
  peg$currPos = s0;
1373
1573
  s0 = peg$FAILED;
@@ -1380,6 +1580,18 @@ function peg$parse(input, options) {
1380
1580
  return s0;
1381
1581
  }
1382
1582
 
1583
+ function peg$parseSAVE_INDENTATION() {
1584
+ let s0, s1;
1585
+
1586
+ s0 = peg$currPos;
1587
+ s1 = '';
1588
+ peg$savedPos = s0;
1589
+ s1 = peg$f45();
1590
+ s0 = s1;
1591
+
1592
+ return s0;
1593
+ }
1594
+
1383
1595
  function peg$parseSET_BASE_INDENTATION() {
1384
1596
  let s0, s1, s2;
1385
1597
 
@@ -1403,7 +1615,7 @@ function peg$parse(input, options) {
1403
1615
  }
1404
1616
  }
1405
1617
  peg$savedPos = s0;
1406
- s1 = peg$f41(s1);
1618
+ s1 = peg$f46(s1);
1407
1619
  s0 = s1;
1408
1620
 
1409
1621
  return s0;
@@ -1432,7 +1644,7 @@ function peg$parse(input, options) {
1432
1644
  }
1433
1645
  }
1434
1646
  peg$savedPos = peg$currPos;
1435
- s2 = peg$f42(s1);
1647
+ s2 = peg$f47(s1);
1436
1648
  if (s2) {
1437
1649
  s2 = undefined;
1438
1650
  } else {
@@ -1440,7 +1652,7 @@ function peg$parse(input, options) {
1440
1652
  }
1441
1653
  if (s2 !== peg$FAILED) {
1442
1654
  peg$savedPos = s0;
1443
- s0 = peg$f43(s1);
1655
+ s0 = peg$f48(s1);
1444
1656
  } else {
1445
1657
  peg$currPos = s0;
1446
1658
  s0 = peg$FAILED;
@@ -1472,7 +1684,7 @@ function peg$parse(input, options) {
1472
1684
  }
1473
1685
  }
1474
1686
  peg$savedPos = peg$currPos;
1475
- s2 = peg$f44(s1);
1687
+ s2 = peg$f49(s1);
1476
1688
  if (s2) {
1477
1689
  s2 = undefined;
1478
1690
  } else {
@@ -1672,7 +1884,7 @@ function peg$parse(input, options) {
1672
1884
 
1673
1885
  s0 = peg$currPos;
1674
1886
  peg$savedPos = peg$currPos;
1675
- s1 = peg$f45();
1887
+ s1 = peg$f50();
1676
1888
  if (s1) {
1677
1889
  s1 = undefined;
1678
1890
  } else {
@@ -1686,7 +1898,7 @@ function peg$parse(input, options) {
1686
1898
  peg$currPos++;
1687
1899
  } else {
1688
1900
  s3 = peg$FAILED;
1689
- if (peg$silentFails === 0) { peg$fail(peg$e3); }
1901
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
1690
1902
  }
1691
1903
  peg$silentFails--;
1692
1904
  if (s3 !== peg$FAILED) {
@@ -1720,7 +1932,7 @@ function peg$parse(input, options) {
1720
1932
  peg$currPos++;
1721
1933
  } else {
1722
1934
  s1 = peg$FAILED;
1723
- if (peg$silentFails === 0) { peg$fail(peg$e6); }
1935
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1724
1936
  }
1725
1937
  peg$silentFails--;
1726
1938
  if (s1 === peg$FAILED) {
@@ -1806,16 +2018,37 @@ function peg$parse(input, options) {
1806
2018
  // group opens a nested context that starts fresh at indentation level zero,
1807
2019
  // so line breaks and indentation mean the same thing at every depth.
1808
2020
  let contextStack = [];
2021
+ // How deeply the current context is nested: the enclosing groups and the
2022
+ // indentation levels around them. Every level is a level of recursion, so
2023
+ // links nested deeper than maxDepth are refused rather than recursed into
2024
+ // until the stack overflows.
2025
+ let contextDepth = 0;
2026
+ const maxDepth = options.maxDepth ?? Infinity;
2027
+ // Lines already found unreadable, keyed by where they start and whether they
2028
+ // are inside a parenthesised group. Reading a line depends on nothing else: a
2029
+ // group starts a fresh indentation context, and indentation only decides
2030
+ // which lines become children, so a line that could not be read once never
2031
+ // can be. A line that does not parse as the first child of the line above it
2032
+ // is tried again as a sibling at every enclosing indentation level, and
2033
+ // without this each of those attempts would read the whole line again.
2034
+ let unreadableLines = new Set();
1809
2035
 
1810
2036
  function resetState() {
1811
2037
  indentationStack = [0];
1812
2038
  baseIndentation = null;
1813
2039
  contextStack = [];
2040
+ contextDepth = 0;
2041
+ unreadableLines = new Set();
1814
2042
  return true;
1815
2043
  }
1816
2044
 
2045
+ function lineKey(position) {
2046
+ return contextStack.length > 0 ? -1 - position : position;
2047
+ }
2048
+
1817
2049
  function enterNestedContext() {
1818
- contextStack.push({ indentationStack, baseIndentation });
2050
+ contextStack.push({ indentationStack, baseIndentation, contextDepth });
2051
+ contextDepth = depth() + 1;
1819
2052
  indentationStack = [0];
1820
2053
  baseIndentation = null;
1821
2054
  return true;
@@ -1826,10 +2059,32 @@ function peg$parse(input, options) {
1826
2059
  if (saved) {
1827
2060
  indentationStack = saved.indentationStack;
1828
2061
  baseIndentation = saved.baseIndentation;
2062
+ contextDepth = saved.contextDepth;
1829
2063
  }
1830
2064
  return true;
1831
2065
  }
1832
2066
 
2067
+ // The nesting depth of the line being read: every enclosing group and every
2068
+ // indentation level is one level, and the lines of a document are at level 0.
2069
+ function depth() {
2070
+ return contextDepth + indentationStack.length - 1;
2071
+ }
2072
+
2073
+ // Refuses links at the given depth when it is deeper than maxDepth. The error
2074
+ // is thrown rather than returned as a failed match, so no alternative is
2075
+ // tried in its place, and says where the nesting got too deep.
2076
+ function checkDepth(levels, where) {
2077
+ if (levels <= maxDepth) {
2078
+ return true;
2079
+ }
2080
+ try {
2081
+ error(`nesting depth exceeds the maximum of ${maxDepth}`, where);
2082
+ } catch (tooDeep) {
2083
+ tooDeep.maxDepth = maxDepth;
2084
+ throw tooDeep;
2085
+ }
2086
+ }
2087
+
1833
2088
  function isInsideNestedContext() {
1834
2089
  return contextStack.length > 0;
1835
2090
  }