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