links-notation 0.21.3 → 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.
@@ -201,7 +201,8 @@ function peg$parse(input, options) {
201
201
  function peg$f5(l) { return l; }
202
202
  function peg$f6(l) { return l; }
203
203
  function peg$f7() { return !unreadableLines.has(lineKey(offset())); }
204
- function peg$f8(e, saved, l) {
204
+ function peg$f8(start, e) { return checkDepth(depth(), start); }
205
+ function peg$f9(start, e, saved, l) {
205
206
  if (l === null) {
206
207
  // No child line followed the indentation. Forget what looking for one
207
208
  // pushed, so the next line is compared with this line's indentation.
@@ -210,30 +211,32 @@ function peg$parse(input, options) {
210
211
  }
211
212
  return Object.assign({}, e, { children: l });
212
213
  }
213
- function peg$f9() { unreadableLines.add(lineKey(offset())); return false; }
214
- function peg$f10(l) { return l; }
215
- function peg$f11(i) { return { id: i }; }
216
- function peg$f12(g, rest) {
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) {
217
218
  return rest === null ? g : { values: [g].concat(rest) };
218
219
  }
219
- function peg$f13() { return null; }
220
- function peg$f14(fl) { return fl; }
221
- function peg$f15(vl) { return vl; }
222
- function peg$f16(body) {
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) {
223
225
  exitNestedContext();
224
226
  return body;
225
227
  }
226
- function peg$f17() { exitNestedContext(); return false; }
227
- function peg$f18(l) { return { nested: l }; }
228
- function peg$f19() { return { nested: [] }; }
229
- function peg$f20() { return enterNestedContext(); }
230
- function peg$f21(value) { return value; }
231
- function peg$f22(list) { return list; }
232
- function peg$f23(id, v) { return { id: id, values: v }; }
233
- function peg$f24(v) { return { values: v }; }
234
- function peg$f25(id) { return { id: id, values: [] }; }
235
- function peg$f26(chars) { return chars.join(''); }
236
- function peg$f27() {
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() {
237
240
  const pos = offset();
238
241
  const result = parseQuotedStringAt(input, pos, '"');
239
242
  if (result) {
@@ -243,11 +246,11 @@ function peg$parse(input, options) {
243
246
  }
244
247
  return false;
245
248
  }
246
- function peg$f28(chars) { return parsedValue; }
247
- function peg$f29(c, cs) { return [c].concat(cs).join(''); }
248
- function peg$f30() { return parsedLength > 1 && (parsedLength--, true); }
249
- function peg$f31(c) { return c; }
250
- function peg$f32() {
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() {
251
254
  const pos = offset();
252
255
  const result = parseQuotedStringAt(input, pos, "'");
253
256
  if (result) {
@@ -257,11 +260,11 @@ function peg$parse(input, options) {
257
260
  }
258
261
  return false;
259
262
  }
260
- function peg$f33(chars) { return parsedValue; }
261
- function peg$f34(c, cs) { return [c].concat(cs).join(''); }
262
- function peg$f35() { return parsedLength > 1 && (parsedLength--, true); }
263
- function peg$f36(c) { return c; }
264
- function peg$f37() {
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() {
265
268
  const pos = offset();
266
269
  const result = parseQuotedStringAt(input, pos, '`');
267
270
  if (result) {
@@ -271,16 +274,16 @@ function peg$parse(input, options) {
271
274
  }
272
275
  return false;
273
276
  }
274
- function peg$f38(chars) { return parsedValue; }
275
- function peg$f39(c, cs) { return [c].concat(cs).join(''); }
276
- function peg$f40() { return parsedLength > 1 && (parsedLength--, true); }
277
- function peg$f41(c) { return c; }
278
- function peg$f42() { return indentationStack.slice(); }
279
- function peg$f43(spaces) { setBaseIndentation(spaces); }
280
- function peg$f44(spaces) { return normalizeIndentation(spaces) > getCurrentIndentation(); }
281
- function peg$f45(spaces) { pushIndentation(spaces); }
282
- function peg$f46(spaces) { return checkIndentation(spaces); }
283
- function peg$f47() { 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(); }
284
287
  let peg$currPos = options.peg$currPos | 0;
285
288
  let peg$savedPos = peg$currPos;
286
289
  const peg$posDetailsCache = [{ line: 1, column: 1 }];
@@ -650,7 +653,7 @@ function peg$parse(input, options) {
650
653
  }
651
654
 
652
655
  function peg$parseelement() {
653
- let s0, s1, s2, s3, s4, s5, s6;
656
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
654
657
 
655
658
  s0 = peg$currPos;
656
659
  peg$savedPos = peg$currPos;
@@ -661,28 +664,41 @@ function peg$parse(input, options) {
661
664
  s1 = peg$FAILED;
662
665
  }
663
666
  if (s1 !== peg$FAILED) {
664
- s2 = peg$parseanyLink();
665
- if (s2 !== peg$FAILED) {
666
- s3 = peg$parseSAVE_INDENTATION();
667
- s4 = peg$currPos;
668
- s5 = peg$parsePUSH_INDENTATION();
669
- if (s5 !== peg$FAILED) {
670
- s6 = peg$parselinks();
671
- if (s6 !== peg$FAILED) {
672
- s4 = s6;
673
- } else {
674
- peg$currPos = s4;
675
- s4 = peg$FAILED;
676
- }
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;
677
674
  } else {
678
- peg$currPos = s4;
679
675
  s4 = peg$FAILED;
680
676
  }
681
- if (s4 === peg$FAILED) {
682
- s4 = null;
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
+ }
696
+ peg$savedPos = s0;
697
+ s0 = peg$f9(s2, s3, s5, s6);
698
+ } else {
699
+ peg$currPos = s0;
700
+ s0 = peg$FAILED;
683
701
  }
684
- peg$savedPos = s0;
685
- s0 = peg$f8(s2, s3, s4);
686
702
  } else {
687
703
  peg$currPos = s0;
688
704
  s0 = peg$FAILED;
@@ -694,7 +710,7 @@ function peg$parse(input, options) {
694
710
  if (s0 === peg$FAILED) {
695
711
  s0 = peg$currPos;
696
712
  peg$savedPos = peg$currPos;
697
- s1 = peg$f9();
713
+ s1 = peg$f10();
698
714
  if (s1) {
699
715
  s1 = undefined;
700
716
  } else {
@@ -731,7 +747,7 @@ function peg$parse(input, options) {
731
747
  s1 = peg$parsenestedGroup();
732
748
  if (s1 !== peg$FAILED) {
733
749
  peg$savedPos = s0;
734
- s1 = peg$f10(s1);
750
+ s1 = peg$f11(s1);
735
751
  }
736
752
  s0 = s1;
737
753
  if (s0 === peg$FAILED) {
@@ -739,7 +755,7 @@ function peg$parse(input, options) {
739
755
  s1 = peg$parsereference();
740
756
  if (s1 !== peg$FAILED) {
741
757
  peg$savedPos = s0;
742
- s1 = peg$f11(s1);
758
+ s1 = peg$f12(s1);
743
759
  }
744
760
  s0 = s1;
745
761
  }
@@ -826,7 +842,7 @@ function peg$parse(input, options) {
826
842
  s2 = peg$parsegroupLinkRest();
827
843
  if (s2 !== peg$FAILED) {
828
844
  peg$savedPos = s0;
829
- s0 = peg$f12(s1, s2);
845
+ s0 = peg$f13(s1, s2);
830
846
  } else {
831
847
  peg$currPos = s0;
832
848
  s0 = peg$FAILED;
@@ -846,7 +862,7 @@ function peg$parse(input, options) {
846
862
  s1 = peg$parseeol();
847
863
  if (s1 !== peg$FAILED) {
848
864
  peg$savedPos = s0;
849
- s1 = peg$f13();
865
+ s1 = peg$f14();
850
866
  }
851
867
  s0 = s1;
852
868
  if (s0 === peg$FAILED) {
@@ -878,7 +894,7 @@ function peg$parse(input, options) {
878
894
  s2 = peg$parseeol();
879
895
  if (s2 !== peg$FAILED) {
880
896
  peg$savedPos = s0;
881
- s0 = peg$f14(s1);
897
+ s0 = peg$f15(s1);
882
898
  } else {
883
899
  peg$currPos = s0;
884
900
  s0 = peg$FAILED;
@@ -894,7 +910,7 @@ function peg$parse(input, options) {
894
910
  s2 = peg$parseeol();
895
911
  if (s2 !== peg$FAILED) {
896
912
  peg$savedPos = s0;
897
- s0 = peg$f15(s1);
913
+ s0 = peg$f16(s1);
898
914
  } else {
899
915
  peg$currPos = s0;
900
916
  s0 = peg$FAILED;
@@ -909,23 +925,36 @@ function peg$parse(input, options) {
909
925
  }
910
926
 
911
927
  function peg$parsenestedGroup() {
912
- let s0, s1, s2, s3;
928
+ let s0, s1, s2, s3, s4, s5;
913
929
 
914
930
  s0 = peg$currPos;
931
+ s1 = peg$parseHERE();
915
932
  if (input.charCodeAt(peg$currPos) === 40) {
916
- s1 = peg$c0;
933
+ s2 = peg$c0;
917
934
  peg$currPos++;
918
935
  } else {
919
- s1 = peg$FAILED;
936
+ s2 = peg$FAILED;
920
937
  if (peg$silentFails === 0) { peg$fail(peg$e3); }
921
938
  }
922
- if (s1 !== peg$FAILED) {
923
- s2 = peg$parseENTER_NESTED_CONTEXT();
924
- if (s2 !== peg$FAILED) {
925
- s3 = peg$parsenestedGroupBody();
926
- if (s3 !== peg$FAILED) {
927
- peg$savedPos = s0;
928
- 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
+ }
929
958
  } else {
930
959
  peg$currPos = s0;
931
960
  s0 = peg$FAILED;
@@ -949,7 +978,7 @@ function peg$parse(input, options) {
949
978
  }
950
979
  if (s1 !== peg$FAILED) {
951
980
  peg$savedPos = peg$currPos;
952
- s2 = peg$f17();
981
+ s2 = peg$f19();
953
982
  if (s2) {
954
983
  s2 = undefined;
955
984
  } else {
@@ -988,7 +1017,7 @@ function peg$parse(input, options) {
988
1017
  }
989
1018
  if (s4 !== peg$FAILED) {
990
1019
  peg$savedPos = s0;
991
- s0 = peg$f18(s2);
1020
+ s0 = peg$f20(s2);
992
1021
  } else {
993
1022
  peg$currPos = s0;
994
1023
  s0 = peg$FAILED;
@@ -1009,7 +1038,7 @@ function peg$parse(input, options) {
1009
1038
  }
1010
1039
  if (s2 !== peg$FAILED) {
1011
1040
  peg$savedPos = s0;
1012
- s0 = peg$f19();
1041
+ s0 = peg$f21();
1013
1042
  } else {
1014
1043
  peg$currPos = s0;
1015
1044
  s0 = peg$FAILED;
@@ -1023,7 +1052,7 @@ function peg$parse(input, options) {
1023
1052
  let s0;
1024
1053
 
1025
1054
  peg$savedPos = peg$currPos;
1026
- s0 = peg$f20();
1055
+ s0 = peg$f22();
1027
1056
  if (s0) {
1028
1057
  s0 = undefined;
1029
1058
  } else {
@@ -1033,6 +1062,18 @@ function peg$parse(input, options) {
1033
1062
  return s0;
1034
1063
  }
1035
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
+
1036
1077
  function peg$parsesingleLineValueAndWhitespace() {
1037
1078
  let s0, s1, s2;
1038
1079
 
@@ -1041,7 +1082,7 @@ function peg$parse(input, options) {
1041
1082
  s2 = peg$parsereferenceOrLink();
1042
1083
  if (s2 !== peg$FAILED) {
1043
1084
  peg$savedPos = s0;
1044
- s0 = peg$f21(s2);
1085
+ s0 = peg$f24(s2);
1045
1086
  } else {
1046
1087
  peg$currPos = s0;
1047
1088
  s0 = peg$FAILED;
@@ -1066,7 +1107,7 @@ function peg$parse(input, options) {
1066
1107
  }
1067
1108
  if (s1 !== peg$FAILED) {
1068
1109
  peg$savedPos = s0;
1069
- s1 = peg$f22(s1);
1110
+ s1 = peg$f25(s1);
1070
1111
  }
1071
1112
  s0 = s1;
1072
1113
 
@@ -1092,7 +1133,7 @@ function peg$parse(input, options) {
1092
1133
  s5 = peg$parsesingleLineValues();
1093
1134
  if (s5 !== peg$FAILED) {
1094
1135
  peg$savedPos = s0;
1095
- s0 = peg$f23(s2, s5);
1136
+ s0 = peg$f26(s2, s5);
1096
1137
  } else {
1097
1138
  peg$currPos = s0;
1098
1139
  s0 = peg$FAILED;
@@ -1116,7 +1157,7 @@ function peg$parse(input, options) {
1116
1157
  s1 = peg$parsesingleLineValues();
1117
1158
  if (s1 !== peg$FAILED) {
1118
1159
  peg$savedPos = s0;
1119
- s1 = peg$f24(s1);
1160
+ s1 = peg$f27(s1);
1120
1161
  }
1121
1162
  s0 = s1;
1122
1163
 
@@ -1141,7 +1182,7 @@ function peg$parse(input, options) {
1141
1182
  s4 = peg$parseeol();
1142
1183
  if (s4 !== peg$FAILED) {
1143
1184
  peg$savedPos = s0;
1144
- s0 = peg$f25(s1);
1185
+ s0 = peg$f28(s1);
1145
1186
  } else {
1146
1187
  peg$currPos = s0;
1147
1188
  s0 = peg$FAILED;
@@ -1185,7 +1226,7 @@ function peg$parse(input, options) {
1185
1226
  }
1186
1227
  if (s1 !== peg$FAILED) {
1187
1228
  peg$savedPos = s0;
1188
- s1 = peg$f26(s1);
1229
+ s1 = peg$f29(s1);
1189
1230
  }
1190
1231
  s0 = s1;
1191
1232
 
@@ -1228,7 +1269,7 @@ function peg$parse(input, options) {
1228
1269
  }
1229
1270
  if (s1 !== peg$FAILED) {
1230
1271
  peg$savedPos = peg$currPos;
1231
- s2 = peg$f27();
1272
+ s2 = peg$f30();
1232
1273
  if (s2) {
1233
1274
  s2 = undefined;
1234
1275
  } else {
@@ -1238,7 +1279,7 @@ function peg$parse(input, options) {
1238
1279
  s3 = peg$parseconsumeDouble();
1239
1280
  if (s3 !== peg$FAILED) {
1240
1281
  peg$savedPos = s0;
1241
- s0 = peg$f28(s3);
1282
+ s0 = peg$f31(s3);
1242
1283
  } else {
1243
1284
  peg$currPos = s0;
1244
1285
  s0 = peg$FAILED;
@@ -1274,7 +1315,7 @@ function peg$parse(input, options) {
1274
1315
  s3 = peg$parseconsumeDoubleMore();
1275
1316
  }
1276
1317
  peg$savedPos = s0;
1277
- s0 = peg$f29(s1, s2);
1318
+ s0 = peg$f32(s1, s2);
1278
1319
  } else {
1279
1320
  peg$currPos = s0;
1280
1321
  s0 = peg$FAILED;
@@ -1288,7 +1329,7 @@ function peg$parse(input, options) {
1288
1329
 
1289
1330
  s0 = peg$currPos;
1290
1331
  peg$savedPos = peg$currPos;
1291
- s1 = peg$f30();
1332
+ s1 = peg$f33();
1292
1333
  if (s1) {
1293
1334
  s1 = undefined;
1294
1335
  } else {
@@ -1304,7 +1345,7 @@ function peg$parse(input, options) {
1304
1345
  }
1305
1346
  if (s2 !== peg$FAILED) {
1306
1347
  peg$savedPos = s0;
1307
- s0 = peg$f31(s2);
1348
+ s0 = peg$f34(s2);
1308
1349
  } else {
1309
1350
  peg$currPos = s0;
1310
1351
  s0 = peg$FAILED;
@@ -1339,7 +1380,7 @@ function peg$parse(input, options) {
1339
1380
  }
1340
1381
  if (s1 !== peg$FAILED) {
1341
1382
  peg$savedPos = peg$currPos;
1342
- s2 = peg$f32();
1383
+ s2 = peg$f35();
1343
1384
  if (s2) {
1344
1385
  s2 = undefined;
1345
1386
  } else {
@@ -1349,7 +1390,7 @@ function peg$parse(input, options) {
1349
1390
  s3 = peg$parseconsumeSingle();
1350
1391
  if (s3 !== peg$FAILED) {
1351
1392
  peg$savedPos = s0;
1352
- s0 = peg$f33(s3);
1393
+ s0 = peg$f36(s3);
1353
1394
  } else {
1354
1395
  peg$currPos = s0;
1355
1396
  s0 = peg$FAILED;
@@ -1385,7 +1426,7 @@ function peg$parse(input, options) {
1385
1426
  s3 = peg$parseconsumeSingleMore();
1386
1427
  }
1387
1428
  peg$savedPos = s0;
1388
- s0 = peg$f34(s1, s2);
1429
+ s0 = peg$f37(s1, s2);
1389
1430
  } else {
1390
1431
  peg$currPos = s0;
1391
1432
  s0 = peg$FAILED;
@@ -1399,7 +1440,7 @@ function peg$parse(input, options) {
1399
1440
 
1400
1441
  s0 = peg$currPos;
1401
1442
  peg$savedPos = peg$currPos;
1402
- s1 = peg$f35();
1443
+ s1 = peg$f38();
1403
1444
  if (s1) {
1404
1445
  s1 = undefined;
1405
1446
  } else {
@@ -1415,7 +1456,7 @@ function peg$parse(input, options) {
1415
1456
  }
1416
1457
  if (s2 !== peg$FAILED) {
1417
1458
  peg$savedPos = s0;
1418
- s0 = peg$f36(s2);
1459
+ s0 = peg$f39(s2);
1419
1460
  } else {
1420
1461
  peg$currPos = s0;
1421
1462
  s0 = peg$FAILED;
@@ -1450,7 +1491,7 @@ function peg$parse(input, options) {
1450
1491
  }
1451
1492
  if (s1 !== peg$FAILED) {
1452
1493
  peg$savedPos = peg$currPos;
1453
- s2 = peg$f37();
1494
+ s2 = peg$f40();
1454
1495
  if (s2) {
1455
1496
  s2 = undefined;
1456
1497
  } else {
@@ -1460,7 +1501,7 @@ function peg$parse(input, options) {
1460
1501
  s3 = peg$parseconsumeBacktick();
1461
1502
  if (s3 !== peg$FAILED) {
1462
1503
  peg$savedPos = s0;
1463
- s0 = peg$f38(s3);
1504
+ s0 = peg$f41(s3);
1464
1505
  } else {
1465
1506
  peg$currPos = s0;
1466
1507
  s0 = peg$FAILED;
@@ -1496,7 +1537,7 @@ function peg$parse(input, options) {
1496
1537
  s3 = peg$parseconsumeBacktickMore();
1497
1538
  }
1498
1539
  peg$savedPos = s0;
1499
- s0 = peg$f39(s1, s2);
1540
+ s0 = peg$f42(s1, s2);
1500
1541
  } else {
1501
1542
  peg$currPos = s0;
1502
1543
  s0 = peg$FAILED;
@@ -1510,7 +1551,7 @@ function peg$parse(input, options) {
1510
1551
 
1511
1552
  s0 = peg$currPos;
1512
1553
  peg$savedPos = peg$currPos;
1513
- s1 = peg$f40();
1554
+ s1 = peg$f43();
1514
1555
  if (s1) {
1515
1556
  s1 = undefined;
1516
1557
  } else {
@@ -1526,7 +1567,7 @@ function peg$parse(input, options) {
1526
1567
  }
1527
1568
  if (s2 !== peg$FAILED) {
1528
1569
  peg$savedPos = s0;
1529
- s0 = peg$f41(s2);
1570
+ s0 = peg$f44(s2);
1530
1571
  } else {
1531
1572
  peg$currPos = s0;
1532
1573
  s0 = peg$FAILED;
@@ -1545,7 +1586,7 @@ function peg$parse(input, options) {
1545
1586
  s0 = peg$currPos;
1546
1587
  s1 = '';
1547
1588
  peg$savedPos = s0;
1548
- s1 = peg$f42();
1589
+ s1 = peg$f45();
1549
1590
  s0 = s1;
1550
1591
 
1551
1592
  return s0;
@@ -1574,7 +1615,7 @@ function peg$parse(input, options) {
1574
1615
  }
1575
1616
  }
1576
1617
  peg$savedPos = s0;
1577
- s1 = peg$f43(s1);
1618
+ s1 = peg$f46(s1);
1578
1619
  s0 = s1;
1579
1620
 
1580
1621
  return s0;
@@ -1603,7 +1644,7 @@ function peg$parse(input, options) {
1603
1644
  }
1604
1645
  }
1605
1646
  peg$savedPos = peg$currPos;
1606
- s2 = peg$f44(s1);
1647
+ s2 = peg$f47(s1);
1607
1648
  if (s2) {
1608
1649
  s2 = undefined;
1609
1650
  } else {
@@ -1611,7 +1652,7 @@ function peg$parse(input, options) {
1611
1652
  }
1612
1653
  if (s2 !== peg$FAILED) {
1613
1654
  peg$savedPos = s0;
1614
- s0 = peg$f45(s1);
1655
+ s0 = peg$f48(s1);
1615
1656
  } else {
1616
1657
  peg$currPos = s0;
1617
1658
  s0 = peg$FAILED;
@@ -1643,7 +1684,7 @@ function peg$parse(input, options) {
1643
1684
  }
1644
1685
  }
1645
1686
  peg$savedPos = peg$currPos;
1646
- s2 = peg$f46(s1);
1687
+ s2 = peg$f49(s1);
1647
1688
  if (s2) {
1648
1689
  s2 = undefined;
1649
1690
  } else {
@@ -1843,7 +1884,7 @@ function peg$parse(input, options) {
1843
1884
 
1844
1885
  s0 = peg$currPos;
1845
1886
  peg$savedPos = peg$currPos;
1846
- s1 = peg$f47();
1887
+ s1 = peg$f50();
1847
1888
  if (s1) {
1848
1889
  s1 = undefined;
1849
1890
  } else {
@@ -1977,6 +2018,12 @@ function peg$parse(input, options) {
1977
2018
  // group opens a nested context that starts fresh at indentation level zero,
1978
2019
  // so line breaks and indentation mean the same thing at every depth.
1979
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;
1980
2027
  // Lines already found unreadable, keyed by where they start and whether they
1981
2028
  // are inside a parenthesised group. Reading a line depends on nothing else: a
1982
2029
  // group starts a fresh indentation context, and indentation only decides
@@ -1990,6 +2037,7 @@ function peg$parse(input, options) {
1990
2037
  indentationStack = [0];
1991
2038
  baseIndentation = null;
1992
2039
  contextStack = [];
2040
+ contextDepth = 0;
1993
2041
  unreadableLines = new Set();
1994
2042
  return true;
1995
2043
  }
@@ -1999,7 +2047,8 @@ function peg$parse(input, options) {
1999
2047
  }
2000
2048
 
2001
2049
  function enterNestedContext() {
2002
- contextStack.push({ indentationStack, baseIndentation });
2050
+ contextStack.push({ indentationStack, baseIndentation, contextDepth });
2051
+ contextDepth = depth() + 1;
2003
2052
  indentationStack = [0];
2004
2053
  baseIndentation = null;
2005
2054
  return true;
@@ -2010,10 +2059,32 @@ function peg$parse(input, options) {
2010
2059
  if (saved) {
2011
2060
  indentationStack = saved.indentationStack;
2012
2061
  baseIndentation = saved.baseIndentation;
2062
+ contextDepth = saved.contextDepth;
2013
2063
  }
2014
2064
  return true;
2015
2065
  }
2016
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
+
2017
2088
  function isInsideNestedContext() {
2018
2089
  return contextStack.length > 0;
2019
2090
  }