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