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