UNPKG

@neuralegion/nextemplate

Version:

Template parser library used for dynamic values interpolation in [Bright DAST app](https://app.brightsec.com).

1,312 lines (1,308 loc) 186 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); // based on https://github.com/marak/Faker.js/ // eslint-disable-next-line max-classes-per-file const rand = (min, max, precision = 0) => { const value = Math.random() < 0.5 ? (1 - Math.random()) * (max - min) + min : Math.random() * (max - min) + min; const power = Math.pow(10, precision); return Math.floor(value * power) / power; }; // eslint-disable-next-line @typescript-eslint/no-namespace,max-classes-per-file,@typescript-eslint/naming-convention class faker { static datatype = class { static uuid() { const RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; return RFC4122_TEMPLATE.replace(/[xy]/g, (placeholder) => { const random = faker.datatype.number({ min: 0, max: 15 }); const value = // eslint-disable-next-line no-bitwise placeholder === 'x' ? random : (random & 0x3) | 0x8; return value.toString(16); }); } static number(options = {}) { if (typeof options === 'number') { options = { max: options }; } if (typeof options.min === 'undefined') { options.min = 0; } if (typeof options.max === 'undefined') { options.max = 99999; } if (typeof options.precision === 'undefined') { options.precision = 1; } // Make the range inclusive of the max value let { max } = options; if (max >= 0) { max += options.precision; } let randomNumber = Math.floor(rand(max / options.precision, options.min / options.precision)); // Workaround problem in Float point arithmetics for e.g. 6681493 / 0.01 randomNumber = randomNumber / (1 / options.precision); return randomNumber; } }; } /* eslint-disable */ function peg$padEnd(str, targetLength, padString) { padString = padString || ' '; if (str.length > targetLength) { return str; } targetLength -= str.length; padString += padString.repeat(targetLength); return str + padString.slice(0, targetLength); } class PeggySyntaxError extends Error { static buildMessage(expected, found) { function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } function literalEscape(s) { return s .replace(/\\/g, "\\\\") .replace(/"/g, "\\\"") .replace(/\0/g, "\\0") .replace(/\t/g, "\\t") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") .replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)) .replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch)); } function classEscape(s) { return s .replace(/\\/g, "\\\\") .replace(/\]/g, "\\]") .replace(/\^/g, "\\^") .replace(/-/g, "\\-") .replace(/\0/g, "\\0") .replace(/\t/g, "\\t") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") .replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)) .replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch)); } function describeExpectation(expectation) { switch (expectation.type) { case "literal": return "\"" + literalEscape(expectation.text) + "\""; case "class": const escapedParts = expectation.parts.map((part) => { return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part); }); return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; case "any": return "any character"; case "end": return "end of input"; case "other": return expectation.description; } } function describeExpected(expected1) { const descriptions = expected1.map(describeExpectation); let i; let j; descriptions.sort(); if (descriptions.length > 0) { for (i = 1, j = 1; i < descriptions.length; i++) { if (descriptions[i - 1] !== descriptions[i]) { descriptions[j] = descriptions[i]; j++; } } descriptions.length = j; } switch (descriptions.length) { case 1: return descriptions[0]; case 2: return descriptions[0] + " or " + descriptions[1]; default: return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1]; } } function describeFound(found1) { return found1 ? "\"" + literalEscape(found1) + "\"" : "end of input"; } return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; } message; expected; found; location; name; constructor(message, expected, found, location) { super(); this.message = message; this.expected = expected; this.found = found; this.location = location; this.name = "PeggySyntaxError"; if (typeof Object.setPrototypeOf === "function") { Object.setPrototypeOf(this, PeggySyntaxError.prototype); } else { this.__proto__ = PeggySyntaxError.prototype; } if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, PeggySyntaxError); } } format(sources) { let str = 'Error: ' + this.message; if (this.location) { let src = null; let k; for (k = 0; k < sources.length; k++) { if (sources[k].grammarSource === this.location.source) { src = sources[k].text.split(/\r\n|\n|\r/g); break; } } let s = this.location.start; let loc = this.location.source + ':' + s.line + ':' + s.column; if (src) { let e = this.location.end; let filler = peg$padEnd('', s.line.toString().length, ' '); let line = src[s.line - 1]; let last = s.line === e.line ? e.column : line.length + 1; str += '\n --> ' + loc + '\n' + filler + ' |\n' + s.line + ' | ' + line + '\n' + filler + ' | ' + peg$padEnd('', s.column - 1, ' ') + peg$padEnd('', last - s.column, '^'); } else { str += '\n at ' + loc; } } return str; } } function peg$parse(input, options) { options = options !== undefined ? options : {}; const peg$FAILED = {}; const peg$source = options.grammarSource; const peg$startRuleFunctions = { TEMPLATE: peg$parseTEMPLATE }; let peg$startRuleFunction = peg$parseTEMPLATE; const peg$c0 = function (x) { return { ...x, raw: text() }; }; const peg$c1 = function (x) { return x.join(''); }; const peg$c2 = "{{"; const peg$c3 = peg$literalExpectation("{{", false); const peg$c4 = "}}"; const peg$c5 = peg$literalExpectation("}}", false); const peg$c6 = function (x) { return x; }; const peg$c7 = peg$anyExpectation(); const peg$c8 = "auth_object"; const peg$c9 = peg$literalExpectation("auth_object", false); const peg$c10 = "."; const peg$c11 = peg$literalExpectation(".", false); const peg$c12 = "|"; const peg$c13 = peg$literalExpectation("|", false); const peg$c14 = function (context, source, x) { return x; }; const peg$c15 = function (context, source, pipes) { return { type: 'variable', source, pipes }; }; const peg$c16 = "$"; const peg$c17 = peg$literalExpectation("$", false); const peg$c18 = function (context, source, x) { return { type: 'variable', source: x }; }; const peg$c19 = function (context, expr) { return { context, ...expr }; }; const peg$c20 = "entrypoint"; const peg$c21 = peg$literalExpectation("entrypoint", false); const peg$c22 = "params"; const peg$c23 = peg$literalExpectation("params", false); const peg$c24 = /^[a-zA-Z]/; const peg$c25 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false); const peg$c26 = /^[a-zA-Z0-9_]/; const peg$c27 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_"], false, false); const peg$c28 = function (context, source, name) { return { type: 'variable', source, name }; }; const peg$c29 = function (x) { return { type: 'yield', ...x }; }; const peg$c30 = "stages"; const peg$c31 = peg$literalExpectation("stages", false); const peg$c32 = "any"; const peg$c33 = peg$literalExpectation("any", false); const peg$c34 = "response"; const peg$c35 = peg$literalExpectation("response", false); const peg$c36 = "request"; const peg$c37 = peg$literalExpectation("request", false); const peg$c38 = "headers"; const peg$c39 = peg$literalExpectation("headers", false); const peg$c40 = "body"; const peg$c41 = peg$literalExpectation("body", false); const peg$c42 = "url"; const peg$c43 = peg$literalExpectation("url", false); const peg$c44 = "otps"; const peg$c45 = peg$literalExpectation("otps", false); const peg$c46 = "faker."; const peg$c47 = peg$literalExpectation("faker.", false); const peg$c48 = "datatype"; const peg$c49 = peg$literalExpectation("datatype", false); const peg$c50 = "uuid"; const peg$c51 = peg$literalExpectation("uuid", false); const peg$c52 = "number"; const peg$c53 = peg$literalExpectation("number", false); const peg$c54 = function (x, y) { try { return { source: `faker.${x}.${y}`, value: fakerFn(x, y) }; } catch (e) { error(e.message); } }; const peg$c55 = "get"; const peg$c56 = peg$literalExpectation("get", false); const peg$c57 = ":"; const peg$c58 = peg$literalExpectation(":", false); const peg$c59 = function (x) { return { name: 'get', args: [x] }; }; const peg$c60 = "match"; const peg$c61 = peg$literalExpectation("match", false); const peg$c62 = function (x, z) { return +z; }; const peg$c63 = function (x, y) { return { name: 'match', args: [x, y ?? 1] }; }; const peg$c64 = "encode"; const peg$c65 = peg$literalExpectation("encode", false); const peg$c66 = "decode"; const peg$c67 = peg$literalExpectation("decode", false); const peg$c68 = function (op, y) { return y; }; const peg$c69 = function (op, x) { return { name: op, args: [x || 'none'] }; }; const peg$c70 = "'"; const peg$c71 = peg$literalExpectation("'", false); const peg$c72 = function (y) { return y; }; const peg$c73 = "\""; const peg$c74 = peg$literalExpectation("\"", false); const peg$c75 = "base64"; const peg$c76 = peg$literalExpectation("base64", false); const peg$c77 = "html"; const peg$c78 = peg$literalExpectation("html", false); const peg$c79 = "none"; const peg$c80 = peg$literalExpectation("none", false); const peg$c81 = /^[0-9]/; const peg$c82 = peg$classExpectation([["0", "9"]], false, false); const peg$c83 = /^[ \t\n\r]/; const peg$c84 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false); const peg$c85 = function () { return ''; }; const peg$c86 = peg$otherExpectation("regular expression"); const peg$c87 = "/"; const peg$c88 = peg$literalExpectation("/", false); const peg$c89 = function (pattern, flags) { try { new RegExp(pattern, flags); } catch (e) { error(e.message); } return pattern + flags; }; const peg$c90 = /^[*\\\/[]/; const peg$c91 = peg$classExpectation(["*", "\\", "/", "["], false, false); const peg$c92 = /^[\\\/[]/; const peg$c93 = peg$classExpectation(["\\", "/", "["], false, false); const peg$c94 = "\\"; const peg$c95 = peg$literalExpectation("\\", false); const peg$c96 = "["; const peg$c97 = peg$literalExpectation("[", false); const peg$c98 = "]"; const peg$c99 = peg$literalExpectation("]", false); const peg$c100 = /^[\]\\]/; const peg$c101 = peg$classExpectation(["]", "\\"], false, false); const peg$c102 = /^[gimsuy]/; const peg$c103 = peg$classExpectation(["g", "i", "m", "s", "u", "y"], false, false); const peg$c104 = /^[\n\r\u2028\u2029]/; const peg$c105 = peg$classExpectation(["\n", "\r", "\u2028", "\u2029"], false, false); const peg$c106 = peg$otherExpectation("XPath LocationPath"); const peg$c107 = peg$otherExpectation("XPath AbsoluteLocationPath"); const peg$c108 = peg$otherExpectation("XPath RelativeLocationPath"); const peg$c109 = "//"; const peg$c110 = peg$literalExpectation("//", false); const peg$c111 = peg$otherExpectation("XPath Step"); const peg$c112 = peg$otherExpectation("XPath AxisSpecifier"); const peg$c113 = "::"; const peg$c114 = peg$literalExpectation("::", false); const peg$c115 = peg$otherExpectation("XPath AxisName"); const peg$c116 = "ancestor-or-self"; const peg$c117 = peg$literalExpectation("ancestor-or-self", false); const peg$c118 = "ancestor"; const peg$c119 = peg$literalExpectation("ancestor", false); const peg$c120 = "attribute"; const peg$c121 = peg$literalExpectation("attribute", false); const peg$c122 = "child"; const peg$c123 = peg$literalExpectation("child", false); const peg$c124 = "descendant-or-self"; const peg$c125 = peg$literalExpectation("descendant-or-self", false); const peg$c126 = "descendant"; const peg$c127 = peg$literalExpectation("descendant", false); const peg$c128 = "following-sibling"; const peg$c129 = peg$literalExpectation("following-sibling", false); const peg$c130 = "following"; const peg$c131 = peg$literalExpectation("following", false); const peg$c132 = "namespace"; const peg$c133 = peg$literalExpectation("namespace", false); const peg$c134 = "parent"; const peg$c135 = peg$literalExpectation("parent", false); const peg$c136 = "preceding-sibling"; const peg$c137 = peg$literalExpectation("preceding-sibling", false); const peg$c138 = "preceding"; const peg$c139 = peg$literalExpectation("preceding", false); const peg$c140 = "self"; const peg$c141 = peg$literalExpectation("self", false); const peg$c142 = peg$otherExpectation("XPath NodeTest"); const peg$c143 = "("; const peg$c144 = peg$literalExpectation("(", false); const peg$c145 = ")"; const peg$c146 = peg$literalExpectation(")", false); const peg$c147 = "processing-instruction"; const peg$c148 = peg$literalExpectation("processing-instruction", false); const peg$c149 = peg$otherExpectation("XPath Predicate"); const peg$c150 = peg$otherExpectation("XPath PredicateExpr"); const peg$c151 = peg$otherExpectation("XPath AbbreviatedAbsoluteLocationPath"); const peg$c152 = peg$otherExpectation("XPath AbbreviatedStep"); const peg$c153 = ".."; const peg$c154 = peg$literalExpectation("..", false); const peg$c155 = peg$otherExpectation("XPath AbbreviatedAxisSpecifier"); const peg$c156 = "@"; const peg$c157 = peg$literalExpectation("@", false); const peg$c158 = peg$otherExpectation("XPath Expr"); const peg$c159 = peg$otherExpectation("XPath PrimaryExpr"); const peg$c160 = peg$otherExpectation("XPath FunctionCall"); const peg$c161 = ","; const peg$c162 = peg$literalExpectation(",", false); const peg$c163 = peg$otherExpectation("XPath Argument"); const peg$c164 = peg$otherExpectation("XPath UnionExpr"); const peg$c165 = peg$otherExpectation("XPath PathExpr"); const peg$c166 = peg$otherExpectation("XPath FilterExpr"); const peg$c167 = peg$otherExpectation("XPath OrExpr"); const peg$c168 = "or"; const peg$c169 = peg$literalExpectation("or", false); const peg$c170 = peg$otherExpectation("XPath AndExpr"); const peg$c171 = "and"; const peg$c172 = peg$literalExpectation("and", false); const peg$c173 = peg$otherExpectation("XPath EqualityExpr"); const peg$c174 = "!="; const peg$c175 = peg$literalExpectation("!=", false); const peg$c176 = "="; const peg$c177 = peg$literalExpectation("=", false); const peg$c178 = peg$otherExpectation("XPath RelationalExpr"); const peg$c179 = "<="; const peg$c180 = peg$literalExpectation("<=", false); const peg$c181 = "<"; const peg$c182 = peg$literalExpectation("<", false); const peg$c183 = ">="; const peg$c184 = peg$literalExpectation(">=", false); const peg$c185 = ">"; const peg$c186 = peg$literalExpectation(">", false); const peg$c187 = peg$otherExpectation("XPath AdditiveExpr"); const peg$c188 = "+"; const peg$c189 = peg$literalExpectation("+", false); const peg$c190 = "-"; const peg$c191 = peg$literalExpectation("-", false); const peg$c192 = peg$otherExpectation("XPath MultiplicativeExpr"); const peg$c193 = "div"; const peg$c194 = peg$literalExpectation("div", false); const peg$c195 = "mod"; const peg$c196 = peg$literalExpectation("mod", false); const peg$c198 = peg$otherExpectation("XPath Literal"); const peg$c199 = /^[^"]/; const peg$c200 = peg$classExpectation(["\""], true, false); const peg$c201 = /^[^']/; const peg$c202 = peg$classExpectation(["'"], true, false); const peg$c203 = peg$otherExpectation("XPath Number"); const peg$c204 = peg$otherExpectation("XPath Digits"); const peg$c207 = "*"; const peg$c208 = peg$literalExpectation("*", false); const peg$c209 = peg$otherExpectation("XPath FunctionName"); const peg$c210 = peg$otherExpectation("XPath VariableReference"); const peg$c211 = peg$otherExpectation("XPath NameTest"); const peg$c212 = peg$otherExpectation("XPath NodeType"); const peg$c213 = "comment"; const peg$c214 = peg$literalExpectation("comment", false); const peg$c215 = "text"; const peg$c216 = peg$literalExpectation("text", false); const peg$c217 = "node"; const peg$c218 = peg$literalExpectation("node", false); const peg$c219 = peg$otherExpectation("XPath QName"); const peg$c220 = peg$otherExpectation("XPath PrefixedName"); const peg$c221 = peg$otherExpectation("XPath UnprefixedName"); const peg$c222 = peg$otherExpectation("XPath Prefix"); const peg$c223 = peg$otherExpectation("XPath LocalPart"); const peg$c224 = peg$otherExpectation("XPath NCName"); const peg$c225 = peg$otherExpectation("XPath Name"); const peg$c226 = peg$otherExpectation("XPath NameStartChar"); const peg$c227 = /^[A-Z]/; const peg$c228 = peg$classExpectation([["A", "Z"]], false, false); const peg$c229 = "_"; const peg$c230 = peg$literalExpectation("_", false); const peg$c231 = /^[a-z]/; const peg$c232 = peg$classExpectation([["a", "z"]], false, false); const peg$c233 = peg$otherExpectation("XPath NameChar"); let peg$currPos = 0; let peg$savedPos = 0; const peg$posDetailsCache = [{ line: 1, column: 1 }]; let peg$maxFailPos = 0; let peg$maxFailExpected = []; let peg$silentFails = 0; let peg$result; if (options.startRule !== undefined) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; } function text() { return input.substring(peg$savedPos, peg$currPos); } function error(message, location1) { location1 = location1 !== undefined ? location1 : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildSimpleError(message, location1); } function peg$literalExpectation(text1, ignoreCase) { return { type: "literal", text: text1, ignoreCase: ignoreCase }; } function peg$classExpectation(parts, inverted, ignoreCase) { return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; } function peg$anyExpectation() { return { type: "any" }; } function peg$endExpectation() { return { type: "end" }; } function peg$otherExpectation(description) { return { type: "other", description: description }; } function peg$computePosDetails(pos) { let details = peg$posDetailsCache[pos]; let p; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { line: details.line, column: details.column }; while (p < pos) { if (input.charCodeAt(p) === 10) { details.line++; details.column = 1; } else { details.column++; } p++; } peg$posDetailsCache[pos] = details; return details; } } function peg$computeLocation(startPos, endPos) { const startPosDetails = peg$computePosDetails(startPos); const endPosDetails = peg$computePosDetails(endPos); return { source: peg$source, start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column } }; } function peg$fail(expected1) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected1); } function peg$buildSimpleError(message, location1) { return new PeggySyntaxError(message, [], "", location1); } function peg$buildStructuredError(expected1, found, location1) { return new PeggySyntaxError(PeggySyntaxError.buildMessage(expected1, found), expected1, found, location1); } function peg$parseTEMPLATE() { let s0, s1, s2, s3, s4, s5, s6; s0 = []; s1 = peg$currPos; s2 = peg$parseINTERPOLATION_OPEN(); if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s4 = peg$parseINTERPOLATION_INNER(); if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parseINTERPOLATION_CLOSE(); if (s6 !== peg$FAILED) { peg$savedPos = s1; s2 = peg$c0(s4); s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 === peg$FAILED) { s1 = peg$currPos; s2 = []; s3 = peg$parseOTHER(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseOTHER(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { peg$savedPos = s1; s2 = peg$c1(s2); } s1 = s2; } while (s1 !== peg$FAILED) { s0.push(s1); s1 = peg$currPos; s2 = peg$parseINTERPOLATION_OPEN(); if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s4 = peg$parseINTERPOLATION_INNER(); if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parseINTERPOLATION_CLOSE(); if (s6 !== peg$FAILED) { peg$savedPos = s1; s2 = peg$c0(s4); s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 === peg$FAILED) { s1 = peg$currPos; s2 = []; s3 = peg$parseOTHER(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseOTHER(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { peg$savedPos = s1; s2 = peg$c1(s2); } s1 = s2; } } return s0; } function peg$parseINTERPOLATION_OPEN() { let s0; if (input.substr(peg$currPos, 2) === peg$c2) { s0 = peg$c2; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c3); } } return s0; } function peg$parseINTERPOLATION_CLOSE() { let s0; if (input.substr(peg$currPos, 2) === peg$c4) { s0 = peg$c4; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c5); } } return s0; } function peg$parseINTERPOLATION_INNER() { let s0, s1, s2; s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; s2 = peg$parseINTERPOLATION_CLOSE(); peg$silentFails--; if (s2 === peg$FAILED) { s1 = undefined; } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s2 = peg$parseEXPRESSION(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c6(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseOTHER() { let s0, s1, s2; s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; s2 = peg$parseINTERPOLATION_OPEN(); peg$silentFails--; if (s2 === peg$FAILED) { s1 = undefined; } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { if (input.length > peg$currPos) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c6(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseEXPRESSION() { let s0; s0 = peg$parseVARIABLE_EXPRESSION(); if (s0 === peg$FAILED) { s0 = peg$parseYIELD_EXPRESSION(); } return s0; } function peg$parseVARIABLE_EXPRESSION() { let s0; s0 = peg$parseAO_VARIABLE_EXPRESSION(); if (s0 === peg$FAILED) { s0 = peg$parseEP_VARIABLE_EXPRESSION(); } return s0; } function peg$parseAO_VARIABLE_EXPRESSION() { let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; s0 = peg$currPos; if (input.substr(peg$currPos, 11) === peg$c8) { s1 = peg$c8; peg$currPos += 11; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { s2 = peg$c10; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = peg$parseSTAGE_EXPRESSION(); if (s4 !== peg$FAILED) { s5 = []; s6 = peg$currPos; s7 = peg$parse_(); if (s7 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 124) { s8 = peg$c12; peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s8 !== peg$FAILED) { s9 = peg$parse_(); if (s9 !== peg$FAILED) { s10 = peg$parsePIPE(); if (s10 !== peg$FAILED) { peg$savedPos = s6; s7 = peg$c14(s1, s4, s10); s6 = s7; } else { peg$currPos = s6; s6 = peg$FAILED; } } else { peg$currPos = s6; s6 = peg$FAILED; } } else { peg$currPos = s6; s6 = peg$FAILED; } } else { peg$currPos = s6; s6 = peg$FAILED; } while (s6 !== peg$FAILED) { s5.push(s6); s6 = peg$currPos; s7 = peg$parse_(); if (s7 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 124) { s8 = peg$c12; peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s8 !== peg$FAILED) { s9 = peg$parse_(); if (s9 !== peg$FAILED) { s10 = peg$parsePIPE(); if (s10 !== peg$FAILED) { peg$savedPos = s6; s7 = peg$c14(s1, s4, s10); s6 = s7; } else { peg$currPos = s6; s6 = peg$FAILED; } } else { peg$currPos = s6; s6 = peg$FAILED; } } else { peg$currPos = s6; s6 = peg$FAILED; } } else { peg$currPos = s6; s6 = peg$FAILED; } } if (s5 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c15(s1, s4, s5); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 === peg$FAILED) { s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 36) { s5 = peg$c16; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c17); } } peg$silentFails--; if (s5 === peg$FAILED) { s4 = undefined; } else { peg$currPos = s4; s4 = peg$FAILED; } if (s4 !== peg$FAILED) { s5 = peg$parseOTPTOKEN_EXPRESSION(); if (s5 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c18(s1, s4, s5); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c19(s1, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseEP_VARIABLE_EXPRESSION() { let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; s0 = peg$currPos; if (input.substr(peg$currPos, 10) === peg$c20) { s1 = peg$c20; peg$currPos += 10; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { s2 = peg$c10; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s2 !== peg$FAILED) { s3 = peg$currPos; if (input.substr(peg$currPos, 6) === peg$c22) { s4 = peg$c22; peg$currPos += 6; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s5 !== peg$FAILED) { s6 = peg$currPos; s7 = peg$currPos; if (peg$c24.test(input.charAt(peg$currPos))) { s8 = input.charAt(peg$currPos); peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c25); } } if (s8 !== peg$FAILED) { s9 = []; if (peg$c26.test(input.charAt(peg$currPos))) { s10 = input.charAt(peg$currPos); peg$currPos++; } else { s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c27); } } while (s10 !== peg$FAILED) { s9.push(s10); if (peg$c26.test(input.charAt(peg$currPos))) { s10 = input.charAt(peg$currPos); peg$currPos++; } else { s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c27); } } } if (s9 !== peg$FAILED) { s8 = [s8, s9]; s7 = s8; } else { peg$currPos = s7; s7 = peg$FAILED; } } else { peg$currPos = s7; s7 = peg$FAILED; } if (s7 !== peg$FAILED) { s6 = input.substring(s6, peg$currPos); } else { s6 = s7; } if (s6 !== peg$FAILED) { peg$savedPos = s3; s4 = peg$c28(s1, s4, s6); s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c19(s1, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseYIELD_EXPRESSION() { let s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 36) { s1 = peg$c16; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c17); } } if (s1 !== peg$FAILED) { s2 = peg$parseFAKER_LITERAL(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c29(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseSTAGE_EXPRESSION() { let s0, s1, s2, s3, s4, s5, s6, s7, s8; s0 = peg$currPos; s1 = peg$currPos; if (input.substr(peg$currPos, 6) === peg$c30) { s2 = peg$c30; peg$currPos += 6; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { s3 = peg$c10; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s3 !== peg$FAILED) { s4 = peg$currPos; s5 = []; if (peg$c26.test(input.charAt(peg$currPos))) { s6 = input.charAt(peg$currPos); peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c27); } } if (s6 !== peg$FAILED) { while (s6 !== peg$FAILED) { s5.push(s6); if (peg$c26.test(input.charAt(peg$currPos))) { s6 = input.charAt(peg$currPos); peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c27); } } } } else { s5 = peg$FAILED; } if (s5 !== peg$FAILED) { s4 = input.substring(s4, peg$currPos); } else { s4 = s5; } if (s4 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c32) { s4 = peg$c32; peg$currPos += 3; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c33); } } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { s5 = peg$c10; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s5 !== peg$FAILED) { if (input.substr(peg$currPos, 8) === peg$c34) { s6 = peg$c34; peg$currPos += 8; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c35); } } if (s6 === peg$FAILED) { if (input.substr(peg$currPos, 7) === peg$c36) { s6 = peg$c36; peg$currPos += 7; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c37); } } } if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { s7 = peg$c10; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } if (s7 !== peg$FAILED) { if (input.substr(peg$currPos, 7) === peg$c38) { s8 = peg$c38; peg$currPos += 7; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s8 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c40) { s8 = peg$c40; peg$currPos += 4; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s8 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c42) { s8 = peg$c42; peg$currPos += 3; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c43); } } } } if (s8 !== peg$FAILED) { s2 = [s2, s3, s4, s5, s6, s7, s8]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; }