X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Frfc8288-web-linking.js;h=6bdc1884cf5f5f1ab1a93b049b530b5fce1d23d9;hb=HEAD;hp=3c41f32180e81a35a7ff0bed74f787d29336af33;hpb=3436c07c25324507228f3d538d345ea35751c623;p=squeep-web-linking diff --git a/lib/rfc8288-web-linking.js b/lib/rfc8288-web-linking.js index 3c41f32..e3b988f 100644 --- a/lib/rfc8288-web-linking.js +++ b/lib/rfc8288-web-linking.js @@ -1,19 +1,25 @@ -// Generated by Peggy 1.2.0. +// @generated by Peggy 4.0.2. // // https://peggyjs.org/ "use strict"; + /* Generated code is not pretty, ignore a lot of this horrorstyle. */ -/* eslint-disable quotes */ -/* eslint-disable vars-on-top */ /* eslint-disable no-control-regex */ +/* eslint-disable no-empty */ /* eslint-disable security/detect-object-injection */ -/* eslint-disable vars-on-top */ /* eslint-disable brace-style */ /* eslint-disable comma-dangle */ +/* eslint-disable vars-on-top */ /* eslint-disable no-unused-vars */ +/* eslint-disable camelcase */ +/* eslint-disable indent */ +/* eslint-disable semi */ +/* eslint-disable jsdoc/require-jsdoc */ +/* eslint-disable sonarjs/cognitive-complexity */ +/* eslint-disable sonarjs/no-identical-functions */ function makeString(o) { return o.join(''); @@ -28,7 +34,6 @@ const onlyFirstAttributes = [ ]; - function peg$subclass(child, parent) { function C() { this.constructor = child; } C.prototype = parent.prototype; @@ -37,6 +42,7 @@ function peg$subclass(child, parent) { function peg$SyntaxError(message, expected, found, location) { var self = Error.call(this, message); + // istanbul ignore next Check is a necessary evil to support older environments if (Object.setPrototypeOf) { Object.setPrototypeOf(self, peg$SyntaxError.prototype); } @@ -69,17 +75,21 @@ peg$SyntaxError.prototype.format = function(sources) { } } var s = this.location.start; - var loc = this.location.source + ":" + s.line + ":" + s.column; + var offset_s = (this.location.source && (typeof this.location.source.offset === "function")) + ? this.location.source.offset(s) + : s; + var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column; if (src) { var e = this.location.end; - var filler = peg$padEnd("", s.line.toString().length); + var filler = peg$padEnd("", offset_s.line.toString().length, ' '); var line = src[s.line - 1]; var last = s.line === e.line ? e.column : line.length + 1; + var hatLen = (last - s.column) || 1; str += "\n --> " + loc + "\n" + filler + " |\n" - + s.line + " | " + line + "\n" - + filler + " | " + peg$padEnd("", s.column - 1) - + peg$padEnd("", last - s.column, "^"); + + offset_s.line + " | " + line + "\n" + + filler + " | " + peg$padEnd("", s.column - 1, ' ') + + peg$padEnd("", hatLen, "^"); } else { str += "\n at " + loc; } @@ -100,7 +110,7 @@ peg$SyntaxError.buildMessage = function(expected, found) { : classEscape(part); }); - return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; + return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"; }, any: function() { @@ -240,79 +250,83 @@ function peg$parse(input, options) { var peg$e25 = peg$anyExpectation(); var peg$f0 = function(links) { - return links; - }; + return links; + }; var peg$f1 = function(uriReference, attributes) { - seenAttributes = []; - return { - target: uriReference, - attributes, - }; + seenAttributes = []; + return { + target: uriReference, + attributes, }; + }; var peg$f2 = function(uri) { - return uri; - }; + return uri; + }; var peg$f3 = function(uri) { - return makeString(uri); - }; + return makeString(uri); + }; var peg$f4 = function(attrs) { - return attrs.filter((a) => a); - }; + return attrs.filter((a) => a); + }; var peg$f5 = function(name, value) { - if (onlyFirstAttributes.includes(name.name)) { - if (seenAttributes.includes(name.name)) { - // Repeat of singleton attribute, ignore it. - return; - } - seenAttributes.push(name.name); + if (onlyFirstAttributes.includes(name.name)) { + if (seenAttributes.includes(name.name)) { + // Repeat of singleton attribute, ignore it. + return; } - return { - ...name, - ...value, - }; + seenAttributes.push(name.name); + } + return { + ...name, + ...value, }; + }; var peg$f6 = function(name) { - return { - ...name, - value: null, - } - }; + return { + ...name, + value: null, + } + }; var peg$f7 = function(name, extended) { - return { - name: makeString(name.concat(extended)).toLowerCase(), - extended: !!extended, - }; + return { + name: makeString(name.concat(extended)).toLowerCase(), + extended: !!extended, }; + }; var peg$f8 = function(value) { - return { - value: makeString(value), - }; + return { + value: makeString(value), }; - var peg$f9 = function(encoding, language, value) { - return { - encoding: encoding.length ? makeString(encoding) : 'UTF-8', - language: language.length ? makeString(language) : null, - value: decodeURIComponent(makeString(value)), - }; + }; + var peg$f9 = function(value) { + return { + value: makeString(value), }; - var peg$f10 = function(value) { - return { - encoding: null, - language: null, - value: makeString(value), - }; + }; + var peg$f10 = function(encoding, language, value) { + return { + encoding: encoding.length ? makeString(encoding) : 'UTF-8', + language: language.length ? makeString(language) : null, + value: decodeURIComponent(makeString(value)), }; - - var peg$currPos = 0; - var peg$savedPos = 0; + }; + var peg$f11 = function(value) { + return { + encoding: null, + language: null, + value: makeString(value), + }; + }; + var peg$currPos = options.peg$currPos | 0; + var peg$savedPos = peg$currPos; var peg$posDetailsCache = [{ line: 1, column: 1 }]; - var peg$maxFailPos = 0; - var peg$maxFailExpected = []; - var peg$silentFails = 0; + var peg$maxFailPos = peg$currPos; + var peg$maxFailExpected = options.peg$maxFailExpected || []; + var peg$silentFails = options.peg$silentFails | 0; var peg$result; - if ("startRule" in options) { + if (options.startRule) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } @@ -387,9 +401,11 @@ function peg$parse(input, options) { if (details) { return details; } else { - p = pos - 1; - while (!peg$posDetailsCache[p]) { - p--; + if (pos >= peg$posDetailsCache.length) { + p = peg$posDetailsCache.length - 1; + } else { + p = pos; + while (!peg$posDetailsCache[--p]) {} } details = peg$posDetailsCache[p]; @@ -415,11 +431,11 @@ function peg$parse(input, options) { } } - function peg$computeLocation(startPos, endPos) { + function peg$computeLocation(startPos, endPos, offset) { var startPosDetails = peg$computePosDetails(startPos); var endPosDetails = peg$computePosDetails(endPos); - return { + var res = { source: peg$source, start: { offset: startPos, @@ -432,6 +448,11 @@ function peg$parse(input, options) { column: endPosDetails.column } }; + if (offset && peg$source && (typeof peg$source.offset === "function")) { + res.start = peg$source.offset(res.start); + res.end = peg$source.offset(res.end); + } + return res; } function peg$fail(expected) { @@ -591,8 +612,8 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; s1 = []; - if (peg$r0.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r0.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -601,8 +622,8 @@ function peg$parse(input, options) { if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$r0.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r0.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -737,8 +758,8 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; s1 = []; - if (peg$r1.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r1.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -747,8 +768,8 @@ function peg$parse(input, options) { if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$r1.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r1.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -789,8 +810,8 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (peg$r2.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); + s1 = input.charAt(peg$currPos); + if (peg$r2.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; @@ -798,8 +819,8 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { s2 = []; - if (peg$r3.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); + s3 = input.charAt(peg$currPos); + if (peg$r3.test(s3)) { peg$currPos++; } else { s3 = peg$FAILED; @@ -808,8 +829,8 @@ function peg$parse(input, options) { if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); - if (peg$r3.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); + s3 = input.charAt(peg$currPos); + if (peg$r3.test(s3)) { peg$currPos++; } else { s3 = peg$FAILED; @@ -820,8 +841,8 @@ function peg$parse(input, options) { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { - if (peg$r2.test(input.charAt(peg$currPos))) { - s3 = input.charAt(peg$currPos); + s3 = input.charAt(peg$currPos); + if (peg$r2.test(s3)) { peg$currPos++; } else { s3 = peg$FAILED; @@ -845,8 +866,8 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; - if (peg$r4.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r4.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -855,8 +876,8 @@ function peg$parse(input, options) { if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$r4.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r4.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -868,7 +889,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f8(s1); + s1 = peg$f9(s1); } s0 = s1; } @@ -886,8 +907,8 @@ function peg$parse(input, options) { peg$silentFails++; s0 = []; - if (peg$r5.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); + s1 = input.charAt(peg$currPos); + if (peg$r5.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; @@ -895,8 +916,8 @@ function peg$parse(input, options) { } while (s1 !== peg$FAILED) { s0.push(s1); - if (peg$r5.test(input.charAt(peg$currPos))) { - s1 = input.charAt(peg$currPos); + s1 = input.charAt(peg$currPos); + if (peg$r5.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; @@ -928,8 +949,8 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; s1 = []; - if (peg$r6.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r6.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -937,16 +958,16 @@ function peg$parse(input, options) { } while (s2 !== peg$FAILED) { s1.push(s2); - if (peg$r6.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r6.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e23); } } } - if (peg$r7.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); + s2 = input.charAt(peg$currPos); + if (peg$r7.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; @@ -954,8 +975,8 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { s3 = []; - if (peg$r6.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); + s4 = input.charAt(peg$currPos); + if (peg$r6.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; @@ -963,16 +984,16 @@ function peg$parse(input, options) { } while (s4 !== peg$FAILED) { s3.push(s4); - if (peg$r6.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); + s4 = input.charAt(peg$currPos); + if (peg$r6.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e23); } } } - if (peg$r7.test(input.charAt(peg$currPos))) { - s4 = input.charAt(peg$currPos); + s4 = input.charAt(peg$currPos); + if (peg$r7.test(s4)) { peg$currPos++; } else { s4 = peg$FAILED; @@ -998,7 +1019,7 @@ function peg$parse(input, options) { } } peg$savedPos = s0; - s0 = peg$f9(s1, s3, s5); + s0 = peg$f10(s1, s3, s5); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1028,7 +1049,7 @@ function peg$parse(input, options) { } } peg$savedPos = s0; - s1 = peg$f10(s1); + s1 = peg$f11(s1); s0 = s1; } peg$silentFails--; @@ -1041,12 +1062,20 @@ function peg$parse(input, options) { } - // Per-parsing tracking of attributes which should be ignored after first occurrence. - let seenAttributes = []; - +// Per-parsing tracking of attributes which should be ignored after first occurrence. +let seenAttributes = []; peg$result = peg$startRuleFunction(); + if (options.peg$library) { + return /** @type {any} */ ({ + peg$result, + peg$currPos, + peg$FAILED, + peg$maxFailExpected, + peg$maxFailPos + }); + } if (peg$result !== peg$FAILED && peg$currPos === input.length) { return peg$result; } else { @@ -1065,6 +1094,7 @@ function peg$parse(input, options) { } module.exports = { + StartRules: ["links", "extendedValue"], SyntaxError: peg$SyntaxError, parse: peg$parse };