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