1.0.9
[squeep-web-linking] / lib / rfc8288-web-linking.js
1 // @generated by Peggy 4.0.2.
2 //
3 // https://peggyjs.org/
4
5 "use strict";
6
7
8
9 /* Generated code is not pretty, ignore a lot of this horrorstyle. */
10 /* eslint-disable no-control-regex */
11 /* eslint-disable no-empty */
12 /* eslint-disable security/detect-object-injection */
13 /* eslint-disable brace-style */
14 /* eslint-disable comma-dangle */
15 /* eslint-disable vars-on-top */
16 /* eslint-disable no-unused-vars */
17 /* eslint-disable camelcase */
18 /* eslint-disable indent */
19 /* eslint-disable semi */
20 /* eslint-disable jsdoc/require-jsdoc */
21 /* eslint-disable sonarjs/cognitive-complexity */
22 /* eslint-disable sonarjs/no-identical-functions */
23
24 function makeString(o) {
25 return o.join('');
26 }
27
28 const onlyFirstAttributes = [
29 'media',
30 'rel',
31 'title',
32 'title*',
33 'type',
34 ];
35
36
37 function peg$subclass(child, parent) {
38 function C() { this.constructor = child; }
39 C.prototype = parent.prototype;
40 child.prototype = new C();
41 }
42
43 function peg$SyntaxError(message, expected, found, location) {
44 var self = Error.call(this, message);
45 // istanbul ignore next Check is a necessary evil to support older environments
46 if (Object.setPrototypeOf) {
47 Object.setPrototypeOf(self, peg$SyntaxError.prototype);
48 }
49 self.expected = expected;
50 self.found = found;
51 self.location = location;
52 self.name = "SyntaxError";
53 return self;
54 }
55
56 peg$subclass(peg$SyntaxError, Error);
57
58 function peg$padEnd(str, targetLength, padString) {
59 padString = padString || " ";
60 if (str.length > targetLength) { return str; }
61 targetLength -= str.length;
62 padString += padString.repeat(targetLength);
63 return str + padString.slice(0, targetLength);
64 }
65
66 peg$SyntaxError.prototype.format = function(sources) {
67 var str = "Error: " + this.message;
68 if (this.location) {
69 var src = null;
70 var k;
71 for (k = 0; k < sources.length; k++) {
72 if (sources[k].source === this.location.source) {
73 src = sources[k].text.split(/\r\n|\n|\r/g);
74 break;
75 }
76 }
77 var s = this.location.start;
78 var offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
79 ? this.location.source.offset(s)
80 : s;
81 var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
82 if (src) {
83 var e = this.location.end;
84 var filler = peg$padEnd("", offset_s.line.toString().length, ' ');
85 var line = src[s.line - 1];
86 var last = s.line === e.line ? e.column : line.length + 1;
87 var hatLen = (last - s.column) || 1;
88 str += "\n --> " + loc + "\n"
89 + filler + " |\n"
90 + offset_s.line + " | " + line + "\n"
91 + filler + " | " + peg$padEnd("", s.column - 1, ' ')
92 + peg$padEnd("", hatLen, "^");
93 } else {
94 str += "\n at " + loc;
95 }
96 }
97 return str;
98 };
99
100 peg$SyntaxError.buildMessage = function(expected, found) {
101 var DESCRIBE_EXPECTATION_FNS = {
102 literal: function(expectation) {
103 return "\"" + literalEscape(expectation.text) + "\"";
104 },
105
106 class: function(expectation) {
107 var escapedParts = expectation.parts.map(function(part) {
108 return Array.isArray(part)
109 ? classEscape(part[0]) + "-" + classEscape(part[1])
110 : classEscape(part);
111 });
112
113 return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
114 },
115
116 any: function() {
117 return "any character";
118 },
119
120 end: function() {
121 return "end of input";
122 },
123
124 other: function(expectation) {
125 return expectation.description;
126 }
127 };
128
129 function hex(ch) {
130 return ch.charCodeAt(0).toString(16).toUpperCase();
131 }
132
133 function literalEscape(s) {
134 return s
135 .replace(/\\/g, "\\\\")
136 .replace(/"/g, "\\\"")
137 .replace(/\0/g, "\\0")
138 .replace(/\t/g, "\\t")
139 .replace(/\n/g, "\\n")
140 .replace(/\r/g, "\\r")
141 .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
142 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
143 }
144
145 function classEscape(s) {
146 return s
147 .replace(/\\/g, "\\\\")
148 .replace(/\]/g, "\\]")
149 .replace(/\^/g, "\\^")
150 .replace(/-/g, "\\-")
151 .replace(/\0/g, "\\0")
152 .replace(/\t/g, "\\t")
153 .replace(/\n/g, "\\n")
154 .replace(/\r/g, "\\r")
155 .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
156 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
157 }
158
159 function describeExpectation(expectation) {
160 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
161 }
162
163 function describeExpected(expected) {
164 var descriptions = expected.map(describeExpectation);
165 var i, j;
166
167 descriptions.sort();
168
169 if (descriptions.length > 0) {
170 for (i = 1, j = 1; i < descriptions.length; i++) {
171 if (descriptions[i - 1] !== descriptions[i]) {
172 descriptions[j] = descriptions[i];
173 j++;
174 }
175 }
176 descriptions.length = j;
177 }
178
179 switch (descriptions.length) {
180 case 1:
181 return descriptions[0];
182
183 case 2:
184 return descriptions[0] + " or " + descriptions[1];
185
186 default:
187 return descriptions.slice(0, -1).join(", ")
188 + ", or "
189 + descriptions[descriptions.length - 1];
190 }
191 }
192
193 function describeFound(found) {
194 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
195 }
196
197 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
198 };
199
200 function peg$parse(input, options) {
201 options = options !== undefined ? options : {};
202
203 var peg$FAILED = {};
204 var peg$source = options.grammarSource;
205
206 var peg$startRuleFunctions = { links: peg$parselinks, extendedValue: peg$parseextendedValue };
207 var peg$startRuleFunction = peg$parselinks;
208
209 var peg$c0 = ",";
210 var peg$c1 = "<";
211 var peg$c2 = ">";
212 var peg$c3 = ";";
213 var peg$c4 = "=";
214 var peg$c5 = "*";
215
216 var peg$r0 = /^[^>]/;
217 var peg$r1 = /^[a-zA-Z]/;
218 var peg$r2 = /^["]/;
219 var peg$r3 = /^[^"]/;
220 var peg$r4 = /^[^";,]/;
221 var peg$r5 = /^[ ]/;
222 var peg$r6 = /^[^']/;
223 var peg$r7 = /^[']/;
224
225 var peg$e0 = peg$otherExpectation("links");
226 var peg$e1 = peg$otherExpectation("link-value");
227 var peg$e2 = peg$literalExpectation(",", false);
228 var peg$e3 = peg$otherExpectation("uri-reference");
229 var peg$e4 = peg$literalExpectation("<", false);
230 var peg$e5 = peg$literalExpectation(">", false);
231 var peg$e6 = peg$literalExpectation(";", false);
232 var peg$e7 = peg$otherExpectation("uri");
233 var peg$e8 = peg$classExpectation([">"], true, false);
234 var peg$e9 = peg$otherExpectation("attributes");
235 var peg$e10 = peg$otherExpectation("link-param");
236 var peg$e11 = peg$literalExpectation("=", false);
237 var peg$e12 = peg$otherExpectation("name");
238 var peg$e13 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false);
239 var peg$e14 = peg$literalExpectation("*", false);
240 var peg$e15 = peg$otherExpectation("value");
241 var peg$e16 = peg$classExpectation(["\""], false, false);
242 var peg$e17 = peg$classExpectation(["\""], true, false);
243 var peg$e18 = peg$classExpectation(["\"", ";", ","], true, false);
244 var peg$e19 = peg$otherExpectation("whitespace");
245 var peg$e20 = peg$classExpectation([" "], false, false);
246 var peg$e21 = peg$otherExpectation("bad whitespace");
247 var peg$e22 = peg$otherExpectation("extended-value");
248 var peg$e23 = peg$classExpectation(["'"], true, false);
249 var peg$e24 = peg$classExpectation(["'"], false, false);
250 var peg$e25 = peg$anyExpectation();
251
252 var peg$f0 = function(links) {
253 return links;
254 };
255 var peg$f1 = function(uriReference, attributes) {
256 seenAttributes = [];
257 return {
258 target: uriReference,
259 attributes,
260 };
261 };
262 var peg$f2 = function(uri) {
263 return uri;
264 };
265 var peg$f3 = function(uri) {
266 return makeString(uri);
267 };
268 var peg$f4 = function(attrs) {
269 return attrs.filter((a) => a);
270 };
271 var peg$f5 = function(name, value) {
272 if (onlyFirstAttributes.includes(name.name)) {
273 if (seenAttributes.includes(name.name)) {
274 // Repeat of singleton attribute, ignore it.
275 return;
276 }
277 seenAttributes.push(name.name);
278 }
279 return {
280 ...name,
281 ...value,
282 };
283 };
284 var peg$f6 = function(name) {
285 return {
286 ...name,
287 value: null,
288 }
289 };
290 var peg$f7 = function(name, extended) {
291 return {
292 name: makeString(name.concat(extended)).toLowerCase(),
293 extended: !!extended,
294 };
295 };
296 var peg$f8 = function(value) {
297 return {
298 value: makeString(value),
299 };
300 };
301 var peg$f9 = function(value) {
302 return {
303 value: makeString(value),
304 };
305 };
306 var peg$f10 = function(encoding, language, value) {
307 return {
308 encoding: encoding.length ? makeString(encoding) : 'UTF-8',
309 language: language.length ? makeString(language) : null,
310 value: decodeURIComponent(makeString(value)),
311 };
312 };
313 var peg$f11 = function(value) {
314 return {
315 encoding: null,
316 language: null,
317 value: makeString(value),
318 };
319 };
320 var peg$currPos = options.peg$currPos | 0;
321 var peg$savedPos = peg$currPos;
322 var peg$posDetailsCache = [{ line: 1, column: 1 }];
323 var peg$maxFailPos = peg$currPos;
324 var peg$maxFailExpected = options.peg$maxFailExpected || [];
325 var peg$silentFails = options.peg$silentFails | 0;
326
327 var peg$result;
328
329 if (options.startRule) {
330 if (!(options.startRule in peg$startRuleFunctions)) {
331 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
332 }
333
334 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
335 }
336
337 function text() {
338 return input.substring(peg$savedPos, peg$currPos);
339 }
340
341 function offset() {
342 return peg$savedPos;
343 }
344
345 function range() {
346 return {
347 source: peg$source,
348 start: peg$savedPos,
349 end: peg$currPos
350 };
351 }
352
353 function location() {
354 return peg$computeLocation(peg$savedPos, peg$currPos);
355 }
356
357 function expected(description, location) {
358 location = location !== undefined
359 ? location
360 : peg$computeLocation(peg$savedPos, peg$currPos);
361
362 throw peg$buildStructuredError(
363 [peg$otherExpectation(description)],
364 input.substring(peg$savedPos, peg$currPos),
365 location
366 );
367 }
368
369 function error(message, location) {
370 location = location !== undefined
371 ? location
372 : peg$computeLocation(peg$savedPos, peg$currPos);
373
374 throw peg$buildSimpleError(message, location);
375 }
376
377 function peg$literalExpectation(text, ignoreCase) {
378 return { type: "literal", text: text, ignoreCase: ignoreCase };
379 }
380
381 function peg$classExpectation(parts, inverted, ignoreCase) {
382 return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
383 }
384
385 function peg$anyExpectation() {
386 return { type: "any" };
387 }
388
389 function peg$endExpectation() {
390 return { type: "end" };
391 }
392
393 function peg$otherExpectation(description) {
394 return { type: "other", description: description };
395 }
396
397 function peg$computePosDetails(pos) {
398 var details = peg$posDetailsCache[pos];
399 var p;
400
401 if (details) {
402 return details;
403 } else {
404 if (pos >= peg$posDetailsCache.length) {
405 p = peg$posDetailsCache.length - 1;
406 } else {
407 p = pos;
408 while (!peg$posDetailsCache[--p]) {}
409 }
410
411 details = peg$posDetailsCache[p];
412 details = {
413 line: details.line,
414 column: details.column
415 };
416
417 while (p < pos) {
418 if (input.charCodeAt(p) === 10) {
419 details.line++;
420 details.column = 1;
421 } else {
422 details.column++;
423 }
424
425 p++;
426 }
427
428 peg$posDetailsCache[pos] = details;
429
430 return details;
431 }
432 }
433
434 function peg$computeLocation(startPos, endPos, offset) {
435 var startPosDetails = peg$computePosDetails(startPos);
436 var endPosDetails = peg$computePosDetails(endPos);
437
438 var res = {
439 source: peg$source,
440 start: {
441 offset: startPos,
442 line: startPosDetails.line,
443 column: startPosDetails.column
444 },
445 end: {
446 offset: endPos,
447 line: endPosDetails.line,
448 column: endPosDetails.column
449 }
450 };
451 if (offset && peg$source && (typeof peg$source.offset === "function")) {
452 res.start = peg$source.offset(res.start);
453 res.end = peg$source.offset(res.end);
454 }
455 return res;
456 }
457
458 function peg$fail(expected) {
459 if (peg$currPos < peg$maxFailPos) { return; }
460
461 if (peg$currPos > peg$maxFailPos) {
462 peg$maxFailPos = peg$currPos;
463 peg$maxFailExpected = [];
464 }
465
466 peg$maxFailExpected.push(expected);
467 }
468
469 function peg$buildSimpleError(message, location) {
470 return new peg$SyntaxError(message, null, null, location);
471 }
472
473 function peg$buildStructuredError(expected, found, location) {
474 return new peg$SyntaxError(
475 peg$SyntaxError.buildMessage(expected, found),
476 expected,
477 found,
478 location
479 );
480 }
481
482 function peg$parselinks() {
483 var s0, s1, s2;
484
485 peg$silentFails++;
486 s0 = peg$currPos;
487 s1 = [];
488 s2 = peg$parselinkValue();
489 if (s2 !== peg$FAILED) {
490 while (s2 !== peg$FAILED) {
491 s1.push(s2);
492 s2 = peg$parselinkValue();
493 }
494 } else {
495 s1 = peg$FAILED;
496 }
497 if (s1 !== peg$FAILED) {
498 peg$savedPos = s0;
499 s1 = peg$f0(s1);
500 }
501 s0 = s1;
502 peg$silentFails--;
503 if (s0 === peg$FAILED) {
504 s1 = peg$FAILED;
505 if (peg$silentFails === 0) { peg$fail(peg$e0); }
506 }
507
508 return s0;
509 }
510
511 function peg$parselinkValue() {
512 var s0, s1, s2, s3, s4, s5;
513
514 peg$silentFails++;
515 s0 = peg$currPos;
516 s1 = peg$parseuriReference();
517 if (s1 !== peg$FAILED) {
518 s2 = peg$parseOWS();
519 s3 = peg$parseattributes();
520 if (s3 !== peg$FAILED) {
521 if (input.charCodeAt(peg$currPos) === 44) {
522 s4 = peg$c0;
523 peg$currPos++;
524 } else {
525 s4 = peg$FAILED;
526 if (peg$silentFails === 0) { peg$fail(peg$e2); }
527 }
528 if (s4 === peg$FAILED) {
529 s4 = null;
530 }
531 s5 = peg$parseOWS();
532 peg$savedPos = s0;
533 s0 = peg$f1(s1, s3);
534 } else {
535 peg$currPos = s0;
536 s0 = peg$FAILED;
537 }
538 } else {
539 peg$currPos = s0;
540 s0 = peg$FAILED;
541 }
542 peg$silentFails--;
543 if (s0 === peg$FAILED) {
544 s1 = peg$FAILED;
545 if (peg$silentFails === 0) { peg$fail(peg$e1); }
546 }
547
548 return s0;
549 }
550
551 function peg$parseuriReference() {
552 var s0, s1, s2, s3, s4;
553
554 peg$silentFails++;
555 s0 = peg$currPos;
556 if (input.charCodeAt(peg$currPos) === 60) {
557 s1 = peg$c1;
558 peg$currPos++;
559 } else {
560 s1 = peg$FAILED;
561 if (peg$silentFails === 0) { peg$fail(peg$e4); }
562 }
563 if (s1 !== peg$FAILED) {
564 s2 = peg$parseuri();
565 if (s2 !== peg$FAILED) {
566 if (input.charCodeAt(peg$currPos) === 62) {
567 s3 = peg$c2;
568 peg$currPos++;
569 } else {
570 s3 = peg$FAILED;
571 if (peg$silentFails === 0) { peg$fail(peg$e5); }
572 }
573 if (s3 !== peg$FAILED) {
574 if (input.charCodeAt(peg$currPos) === 59) {
575 s4 = peg$c3;
576 peg$currPos++;
577 } else {
578 s4 = peg$FAILED;
579 if (peg$silentFails === 0) { peg$fail(peg$e6); }
580 }
581 if (s4 !== peg$FAILED) {
582 peg$savedPos = s0;
583 s0 = peg$f2(s2);
584 } else {
585 peg$currPos = s0;
586 s0 = peg$FAILED;
587 }
588 } else {
589 peg$currPos = s0;
590 s0 = peg$FAILED;
591 }
592 } else {
593 peg$currPos = s0;
594 s0 = peg$FAILED;
595 }
596 } else {
597 peg$currPos = s0;
598 s0 = peg$FAILED;
599 }
600 peg$silentFails--;
601 if (s0 === peg$FAILED) {
602 s1 = peg$FAILED;
603 if (peg$silentFails === 0) { peg$fail(peg$e3); }
604 }
605
606 return s0;
607 }
608
609 function peg$parseuri() {
610 var s0, s1, s2;
611
612 peg$silentFails++;
613 s0 = peg$currPos;
614 s1 = [];
615 s2 = input.charAt(peg$currPos);
616 if (peg$r0.test(s2)) {
617 peg$currPos++;
618 } else {
619 s2 = peg$FAILED;
620 if (peg$silentFails === 0) { peg$fail(peg$e8); }
621 }
622 if (s2 !== peg$FAILED) {
623 while (s2 !== peg$FAILED) {
624 s1.push(s2);
625 s2 = input.charAt(peg$currPos);
626 if (peg$r0.test(s2)) {
627 peg$currPos++;
628 } else {
629 s2 = peg$FAILED;
630 if (peg$silentFails === 0) { peg$fail(peg$e8); }
631 }
632 }
633 } else {
634 s1 = peg$FAILED;
635 }
636 if (s1 !== peg$FAILED) {
637 peg$savedPos = s0;
638 s1 = peg$f3(s1);
639 }
640 s0 = s1;
641 peg$silentFails--;
642 if (s0 === peg$FAILED) {
643 s1 = peg$FAILED;
644 if (peg$silentFails === 0) { peg$fail(peg$e7); }
645 }
646
647 return s0;
648 }
649
650 function peg$parseattributes() {
651 var s0, s1, s2;
652
653 peg$silentFails++;
654 s0 = peg$currPos;
655 s1 = [];
656 s2 = peg$parselinkParam();
657 if (s2 !== peg$FAILED) {
658 while (s2 !== peg$FAILED) {
659 s1.push(s2);
660 s2 = peg$parselinkParam();
661 }
662 } else {
663 s1 = peg$FAILED;
664 }
665 if (s1 !== peg$FAILED) {
666 peg$savedPos = s0;
667 s1 = peg$f4(s1);
668 }
669 s0 = s1;
670 peg$silentFails--;
671 if (s0 === peg$FAILED) {
672 s1 = peg$FAILED;
673 if (peg$silentFails === 0) { peg$fail(peg$e9); }
674 }
675
676 return s0;
677 }
678
679 function peg$parselinkParam() {
680 var s0, s1, s2, s3, s4, s5, s6, s7;
681
682 peg$silentFails++;
683 s0 = peg$currPos;
684 s1 = peg$parsename();
685 if (s1 !== peg$FAILED) {
686 s2 = peg$parseBWS();
687 if (input.charCodeAt(peg$currPos) === 61) {
688 s3 = peg$c4;
689 peg$currPos++;
690 } else {
691 s3 = peg$FAILED;
692 if (peg$silentFails === 0) { peg$fail(peg$e11); }
693 }
694 if (s3 !== peg$FAILED) {
695 s4 = peg$parseBWS();
696 s5 = peg$parsevalue();
697 if (s5 !== peg$FAILED) {
698 if (input.charCodeAt(peg$currPos) === 59) {
699 s6 = peg$c3;
700 peg$currPos++;
701 } else {
702 s6 = peg$FAILED;
703 if (peg$silentFails === 0) { peg$fail(peg$e6); }
704 }
705 if (s6 === peg$FAILED) {
706 s6 = null;
707 }
708 s7 = peg$parseOWS();
709 peg$savedPos = s0;
710 s0 = peg$f5(s1, s5);
711 } else {
712 peg$currPos = s0;
713 s0 = peg$FAILED;
714 }
715 } else {
716 peg$currPos = s0;
717 s0 = peg$FAILED;
718 }
719 } else {
720 peg$currPos = s0;
721 s0 = peg$FAILED;
722 }
723 if (s0 === peg$FAILED) {
724 s0 = peg$currPos;
725 s1 = peg$parsename();
726 if (s1 !== peg$FAILED) {
727 s2 = peg$parseBWS();
728 if (input.charCodeAt(peg$currPos) === 59) {
729 s3 = peg$c3;
730 peg$currPos++;
731 } else {
732 s3 = peg$FAILED;
733 if (peg$silentFails === 0) { peg$fail(peg$e6); }
734 }
735 if (s3 === peg$FAILED) {
736 s3 = null;
737 }
738 s4 = peg$parseOWS();
739 peg$savedPos = s0;
740 s0 = peg$f6(s1);
741 } else {
742 peg$currPos = s0;
743 s0 = peg$FAILED;
744 }
745 }
746 peg$silentFails--;
747 if (s0 === peg$FAILED) {
748 s1 = peg$FAILED;
749 if (peg$silentFails === 0) { peg$fail(peg$e10); }
750 }
751
752 return s0;
753 }
754
755 function peg$parsename() {
756 var s0, s1, s2;
757
758 peg$silentFails++;
759 s0 = peg$currPos;
760 s1 = [];
761 s2 = input.charAt(peg$currPos);
762 if (peg$r1.test(s2)) {
763 peg$currPos++;
764 } else {
765 s2 = peg$FAILED;
766 if (peg$silentFails === 0) { peg$fail(peg$e13); }
767 }
768 if (s2 !== peg$FAILED) {
769 while (s2 !== peg$FAILED) {
770 s1.push(s2);
771 s2 = input.charAt(peg$currPos);
772 if (peg$r1.test(s2)) {
773 peg$currPos++;
774 } else {
775 s2 = peg$FAILED;
776 if (peg$silentFails === 0) { peg$fail(peg$e13); }
777 }
778 }
779 } else {
780 s1 = peg$FAILED;
781 }
782 if (s1 !== peg$FAILED) {
783 if (input.charCodeAt(peg$currPos) === 42) {
784 s2 = peg$c5;
785 peg$currPos++;
786 } else {
787 s2 = peg$FAILED;
788 if (peg$silentFails === 0) { peg$fail(peg$e14); }
789 }
790 if (s2 === peg$FAILED) {
791 s2 = null;
792 }
793 peg$savedPos = s0;
794 s0 = peg$f7(s1, s2);
795 } else {
796 peg$currPos = s0;
797 s0 = peg$FAILED;
798 }
799 peg$silentFails--;
800 if (s0 === peg$FAILED) {
801 s1 = peg$FAILED;
802 if (peg$silentFails === 0) { peg$fail(peg$e12); }
803 }
804
805 return s0;
806 }
807
808 function peg$parsevalue() {
809 var s0, s1, s2, s3;
810
811 peg$silentFails++;
812 s0 = peg$currPos;
813 s1 = input.charAt(peg$currPos);
814 if (peg$r2.test(s1)) {
815 peg$currPos++;
816 } else {
817 s1 = peg$FAILED;
818 if (peg$silentFails === 0) { peg$fail(peg$e16); }
819 }
820 if (s1 !== peg$FAILED) {
821 s2 = [];
822 s3 = input.charAt(peg$currPos);
823 if (peg$r3.test(s3)) {
824 peg$currPos++;
825 } else {
826 s3 = peg$FAILED;
827 if (peg$silentFails === 0) { peg$fail(peg$e17); }
828 }
829 if (s3 !== peg$FAILED) {
830 while (s3 !== peg$FAILED) {
831 s2.push(s3);
832 s3 = input.charAt(peg$currPos);
833 if (peg$r3.test(s3)) {
834 peg$currPos++;
835 } else {
836 s3 = peg$FAILED;
837 if (peg$silentFails === 0) { peg$fail(peg$e17); }
838 }
839 }
840 } else {
841 s2 = peg$FAILED;
842 }
843 if (s2 !== peg$FAILED) {
844 s3 = input.charAt(peg$currPos);
845 if (peg$r2.test(s3)) {
846 peg$currPos++;
847 } else {
848 s3 = peg$FAILED;
849 if (peg$silentFails === 0) { peg$fail(peg$e16); }
850 }
851 if (s3 !== peg$FAILED) {
852 peg$savedPos = s0;
853 s0 = peg$f8(s2);
854 } else {
855 peg$currPos = s0;
856 s0 = peg$FAILED;
857 }
858 } else {
859 peg$currPos = s0;
860 s0 = peg$FAILED;
861 }
862 } else {
863 peg$currPos = s0;
864 s0 = peg$FAILED;
865 }
866 if (s0 === peg$FAILED) {
867 s0 = peg$currPos;
868 s1 = [];
869 s2 = input.charAt(peg$currPos);
870 if (peg$r4.test(s2)) {
871 peg$currPos++;
872 } else {
873 s2 = peg$FAILED;
874 if (peg$silentFails === 0) { peg$fail(peg$e18); }
875 }
876 if (s2 !== peg$FAILED) {
877 while (s2 !== peg$FAILED) {
878 s1.push(s2);
879 s2 = input.charAt(peg$currPos);
880 if (peg$r4.test(s2)) {
881 peg$currPos++;
882 } else {
883 s2 = peg$FAILED;
884 if (peg$silentFails === 0) { peg$fail(peg$e18); }
885 }
886 }
887 } else {
888 s1 = peg$FAILED;
889 }
890 if (s1 !== peg$FAILED) {
891 peg$savedPos = s0;
892 s1 = peg$f9(s1);
893 }
894 s0 = s1;
895 }
896 peg$silentFails--;
897 if (s0 === peg$FAILED) {
898 s1 = peg$FAILED;
899 if (peg$silentFails === 0) { peg$fail(peg$e15); }
900 }
901
902 return s0;
903 }
904
905 function peg$parseOWS() {
906 var s0, s1;
907
908 peg$silentFails++;
909 s0 = [];
910 s1 = input.charAt(peg$currPos);
911 if (peg$r5.test(s1)) {
912 peg$currPos++;
913 } else {
914 s1 = peg$FAILED;
915 if (peg$silentFails === 0) { peg$fail(peg$e20); }
916 }
917 while (s1 !== peg$FAILED) {
918 s0.push(s1);
919 s1 = input.charAt(peg$currPos);
920 if (peg$r5.test(s1)) {
921 peg$currPos++;
922 } else {
923 s1 = peg$FAILED;
924 if (peg$silentFails === 0) { peg$fail(peg$e20); }
925 }
926 }
927 peg$silentFails--;
928 s1 = peg$FAILED;
929 if (peg$silentFails === 0) { peg$fail(peg$e19); }
930
931 return s0;
932 }
933
934 function peg$parseBWS() {
935 var s0, s1;
936
937 peg$silentFails++;
938 s0 = peg$parseOWS();
939 peg$silentFails--;
940 s1 = peg$FAILED;
941 if (peg$silentFails === 0) { peg$fail(peg$e21); }
942
943 return s0;
944 }
945
946 function peg$parseextendedValue() {
947 var s0, s1, s2, s3, s4, s5, s6;
948
949 peg$silentFails++;
950 s0 = peg$currPos;
951 s1 = [];
952 s2 = input.charAt(peg$currPos);
953 if (peg$r6.test(s2)) {
954 peg$currPos++;
955 } else {
956 s2 = peg$FAILED;
957 if (peg$silentFails === 0) { peg$fail(peg$e23); }
958 }
959 while (s2 !== peg$FAILED) {
960 s1.push(s2);
961 s2 = input.charAt(peg$currPos);
962 if (peg$r6.test(s2)) {
963 peg$currPos++;
964 } else {
965 s2 = peg$FAILED;
966 if (peg$silentFails === 0) { peg$fail(peg$e23); }
967 }
968 }
969 s2 = input.charAt(peg$currPos);
970 if (peg$r7.test(s2)) {
971 peg$currPos++;
972 } else {
973 s2 = peg$FAILED;
974 if (peg$silentFails === 0) { peg$fail(peg$e24); }
975 }
976 if (s2 !== peg$FAILED) {
977 s3 = [];
978 s4 = input.charAt(peg$currPos);
979 if (peg$r6.test(s4)) {
980 peg$currPos++;
981 } else {
982 s4 = peg$FAILED;
983 if (peg$silentFails === 0) { peg$fail(peg$e23); }
984 }
985 while (s4 !== peg$FAILED) {
986 s3.push(s4);
987 s4 = input.charAt(peg$currPos);
988 if (peg$r6.test(s4)) {
989 peg$currPos++;
990 } else {
991 s4 = peg$FAILED;
992 if (peg$silentFails === 0) { peg$fail(peg$e23); }
993 }
994 }
995 s4 = input.charAt(peg$currPos);
996 if (peg$r7.test(s4)) {
997 peg$currPos++;
998 } else {
999 s4 = peg$FAILED;
1000 if (peg$silentFails === 0) { peg$fail(peg$e24); }
1001 }
1002 if (s4 !== peg$FAILED) {
1003 s5 = [];
1004 if (input.length > peg$currPos) {
1005 s6 = input.charAt(peg$currPos);
1006 peg$currPos++;
1007 } else {
1008 s6 = peg$FAILED;
1009 if (peg$silentFails === 0) { peg$fail(peg$e25); }
1010 }
1011 while (s6 !== peg$FAILED) {
1012 s5.push(s6);
1013 if (input.length > peg$currPos) {
1014 s6 = input.charAt(peg$currPos);
1015 peg$currPos++;
1016 } else {
1017 s6 = peg$FAILED;
1018 if (peg$silentFails === 0) { peg$fail(peg$e25); }
1019 }
1020 }
1021 peg$savedPos = s0;
1022 s0 = peg$f10(s1, s3, s5);
1023 } else {
1024 peg$currPos = s0;
1025 s0 = peg$FAILED;
1026 }
1027 } else {
1028 peg$currPos = s0;
1029 s0 = peg$FAILED;
1030 }
1031 if (s0 === peg$FAILED) {
1032 s0 = peg$currPos;
1033 s1 = [];
1034 if (input.length > peg$currPos) {
1035 s2 = input.charAt(peg$currPos);
1036 peg$currPos++;
1037 } else {
1038 s2 = peg$FAILED;
1039 if (peg$silentFails === 0) { peg$fail(peg$e25); }
1040 }
1041 while (s2 !== peg$FAILED) {
1042 s1.push(s2);
1043 if (input.length > peg$currPos) {
1044 s2 = input.charAt(peg$currPos);
1045 peg$currPos++;
1046 } else {
1047 s2 = peg$FAILED;
1048 if (peg$silentFails === 0) { peg$fail(peg$e25); }
1049 }
1050 }
1051 peg$savedPos = s0;
1052 s1 = peg$f11(s1);
1053 s0 = s1;
1054 }
1055 peg$silentFails--;
1056 if (s0 === peg$FAILED) {
1057 s1 = peg$FAILED;
1058 if (peg$silentFails === 0) { peg$fail(peg$e22); }
1059 }
1060
1061 return s0;
1062 }
1063
1064
1065 // Per-parsing tracking of attributes which should be ignored after first occurrence.
1066 let seenAttributes = [];
1067
1068 peg$result = peg$startRuleFunction();
1069
1070 if (options.peg$library) {
1071 return /** @type {any} */ ({
1072 peg$result,
1073 peg$currPos,
1074 peg$FAILED,
1075 peg$maxFailExpected,
1076 peg$maxFailPos
1077 });
1078 }
1079 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
1080 return peg$result;
1081 } else {
1082 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1083 peg$fail(peg$endExpectation());
1084 }
1085
1086 throw peg$buildStructuredError(
1087 peg$maxFailExpected,
1088 peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
1089 peg$maxFailPos < input.length
1090 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
1091 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
1092 );
1093 }
1094 }
1095
1096 module.exports = {
1097 StartRules: ["links", "extendedValue"],
1098 SyntaxError: peg$SyntaxError,
1099 parse: peg$parse
1100 };