UNPKG

@daiyam/regexp

Version:

RegExp parser/formatter/visitor/transformer

1,873 lines (1,694 loc) 73.2 kB
/* * Generated by PEG.js 0.10.0. * * http://pegjs.org/ */ "use strict"; function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function peg$SyntaxError(message, expected, found, location) { this.message = message; this.expected = expected; this.found = found; this.location = location; this.name = "SyntaxError"; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, peg$SyntaxError); } } peg$subclass(peg$SyntaxError, Error); peg$SyntaxError.buildMessage = function(expected, found) { var DESCRIBE_EXPECTATION_FNS = { literal: function(expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, "class": function(expectation) { var escapedParts = "", i; for (i = 0; i < expectation.parts.length; i++) { escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]); } return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; }, any: function(expectation) { return "any character"; }, end: function(expectation) { return "end of input"; }, other: function(expectation) { return expectation.description; } }; 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, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\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, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function describeExpectation(expectation) { return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); } function describeExpected(expected) { var descriptions = new Array(expected.length), i, j; for (i = 0; i < expected.length; i++) { descriptions[i] = describeExpectation(expected[i]); } 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(found) { return found ? "\"" + literalEscape(found) + "\"" : "end of input"; } return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; }; function peg$parse(input, options) { options = options !== void 0 ? options : {}; var peg$FAILED = {}, peg$startRuleFunctions = { regexp: peg$parseregexp }, peg$startRuleFunction = peg$parseregexp, peg$c0 = "|", peg$c1 = peg$literalExpectation("|", false), peg$c2 = function(match, alternate) { if(alternate) { const body = alternate[1].type === TokenType.ALTERNATE ? [match, ...alternate[1].body] : [match, alternate[1]] return { type: TokenType.ALTERNATE, body: body } } else { return match } }, peg$c3 = "/", peg$c4 = peg$literalExpectation("/", false), peg$c5 = function(body, modifiers) { if(modifiers) { return { type: TokenType.PATTERN, body: body, modifiers: modifiers } } else { return { type: TokenType.PATTERN, body: body } } }, peg$c6 = "(", peg$c7 = peg$literalExpectation("(", false), peg$c8 = ")", peg$c9 = peg$literalExpectation(")", false), peg$c10 = function(modifier, begin, matches, end) { const body = [] if(modifier) { body.push(modifier[1]) } if(begin) { body.push(begin) } body.push(...matches.flat()) if(end) { body.push(end) } return { type: TokenType.MATCH, body: body } }, peg$c11 = "^", peg$c12 = peg$literalExpectation("^", false), peg$c13 = function() { return { type: TokenType.BEGIN } }, peg$c14 = "$", peg$c15 = peg$literalExpectation("$", false), peg$c16 = function() { return { type: TokenType.END } }, peg$c17 = "?", peg$c18 = peg$literalExpectation("?", false), peg$c19 = function(modifiers) { return { type: TokenType.MODIFIER, ...modifiers } }, peg$c20 = /^[gimsuxyUJX]/, peg$c21 = peg$classExpectation(["g", "i", "m", "s", "u", "x", "y", "U", "J", "X"], false, false), peg$c22 = "-", peg$c23 = peg$literalExpectation("-", false), peg$c24 = function(positive, negative) { return { positive: positive, negative: negative } }, peg$c25 = function(positive) { return { positive: positive, negative: [] } }, peg$c26 = function(negative) { return { positive: [], negative: negative } }, peg$c27 = function(submatch, quantifier) { if(submatch.type === TokenType.LITERAL && submatch.text.length > 1) { return [ { type: TokenType.LITERAL, text: submatch.text.substr(0, submatch.text.length - 1) }, { type: TokenType.QUANTIFIED, body: { type: TokenType.LITERAL, text: submatch.text.substr(-1) }, quantifier: quantifier } ] } else { return { type: TokenType.QUANTIFIED, body: submatch, quantifier: quantifier } } }, peg$c28 = peg$otherExpectation("Quantifier"), peg$c29 = function(quantity, notgreedy) { quantity.greedy = !notgreedy; return quantity }, peg$c30 = "{", peg$c31 = peg$literalExpectation("{", false), peg$c32 = ",", peg$c33 = peg$literalExpectation(",", false), peg$c34 = "}", peg$c35 = peg$literalExpectation("}", false), peg$c36 = function(min, max) { return { type: TokenType.QUANTIFIER, min: min, max: max } }, peg$c37 = ",}", peg$c38 = peg$literalExpectation(",}", false), peg$c39 = function(min) { return { type: TokenType.QUANTIFIER, min: min, max: Infinity } }, peg$c40 = function(value) { return { type: TokenType.QUANTIFIER, min: value, max: value } }, peg$c41 = "+", peg$c42 = peg$literalExpectation("+", false), peg$c43 = function() { return { type: TokenType.QUANTIFIER, min: 1, max: Infinity } }, peg$c44 = "*", peg$c45 = peg$literalExpectation("*", false), peg$c46 = function() { return { type: TokenType.QUANTIFIER, min: 0, max: Infinity } }, peg$c47 = function() { return { type: TokenType.QUANTIFIER, min: 0, max: 1 } }, peg$c48 = /^[0-9]/, peg$c49 = peg$classExpectation([["0", "9"]], false, false), peg$c50 = function(num) { return +num.join('') }, peg$c51 = function(body) { return body }, peg$c52 = function(regexp) { return { type: TokenType.CAPTURE_GROUP, body: regexp } }, peg$c53 = "?:", peg$c54 = peg$literalExpectation("?:", false), peg$c55 = function(regexp) { return { type: TokenType.NON_CAPTURE_GROUP, body: regexp } }, peg$c56 = "?<", peg$c57 = peg$literalExpectation("?<", false), peg$c58 = /^[0-9a-zA-Z_]/, peg$c59 = peg$classExpectation([["0", "9"], ["a", "z"], ["A", "Z"], "_"], false, false), peg$c60 = ">", peg$c61 = peg$literalExpectation(">", false), peg$c62 = function(name, regexp) { return { type: TokenType.NAMED_GROUP, name: name.join(''), body: regexp } }, peg$c63 = "?<=", peg$c64 = peg$literalExpectation("?<=", false), peg$c65 = function(regexp) { return { type: TokenType.POSITIVE_LOOKBEHIND, body: regexp } }, peg$c66 = "?<!", peg$c67 = peg$literalExpectation("?<!", false), peg$c68 = function(regexp) { return { type: TokenType.NEGATIVE_LOOKBEHIND, body: regexp } }, peg$c69 = "?=", peg$c70 = peg$literalExpectation("?=", false), peg$c71 = function(regexp) { return { type: TokenType.POSITIVE_LOOKAHEAD, body: regexp } }, peg$c72 = "?!", peg$c73 = peg$literalExpectation("?!", false), peg$c74 = function(regexp) { return { type: TokenType.NEGATIVE_LOOKAHEAD, body: regexp } }, peg$c75 = ":", peg$c76 = peg$literalExpectation(":", false), peg$c77 = function(modifiers, regexp) { return { type: TokenType.MODIFIED_GROUP, modifiers: modifiers, body: regexp } }, peg$c78 = peg$otherExpectation("CharacterSet"), peg$c79 = "[", peg$c80 = peg$literalExpectation("[", false), peg$c81 = "]", peg$c82 = peg$literalExpectation("]", false), peg$c83 = function(negated, body) { return { type: TokenType.CHARSET, body: body, negated: !!negated} }, peg$c84 = peg$otherExpectation("CharacterRange"), peg$c85 = function(begin, end) { return { type: TokenType.RANGE, begin: begin, end: end } }, peg$c86 = peg$otherExpectation("Character"), peg$c87 = /^[^\\\]]/, peg$c88 = peg$classExpectation(["\\", "]"], true, false), peg$c89 = function(value) { return { type: TokenType.LITERAL, text: value } }, peg$c90 = ".", peg$c91 = peg$literalExpectation(".", false), peg$c92 = function() { return { type: TokenType.ANY } }, peg$c93 = peg$otherExpectation("Literal"), peg$c94 = /^[^|\\\/.[()?+*$\^]/, peg$c95 = peg$classExpectation(["|", "\\", "/", ".", "[", "(", ")", "?", "+", "*", "$", "^"], true, false), peg$c96 = function(value) { return { type: TokenType.LITERAL, text: value.join('') } }, peg$c97 = "\\", peg$c98 = peg$literalExpectation("\\", false), peg$c99 = /^[1-9]/, peg$c100 = peg$classExpectation([["1", "9"]], false, false), peg$c101 = function(code) { return { type: TokenType.BACK_REFERENCE, code: code } }, peg$c102 = "\\b", peg$c103 = peg$literalExpectation("\\b", false), peg$c104 = function() { return { type: TokenType.BACKSPACE } }, peg$c105 = "\\r", peg$c106 = peg$literalExpectation("\\r", false), peg$c107 = function() { return { type: TokenType.CARRIAGE_RETURN } }, peg$c108 = "\\c", peg$c109 = peg$literalExpectation("\\c", false), peg$c110 = peg$anyExpectation(), peg$c111 = function(code) { return { type: TokenType.CONTROL, code: code } }, peg$c112 = "\\d", peg$c113 = peg$literalExpectation("\\d", false), peg$c114 = function() { return { type: TokenType.DIGIT } }, peg$c115 = "\\D", peg$c116 = peg$literalExpectation("\\D", false), peg$c117 = function() { return { type: TokenType.NON_DIGIT } }, peg$c118 = "\\f", peg$c119 = peg$literalExpectation("\\f", false), peg$c120 = function() { return { type: TokenType.FORM_FEED } }, peg$c121 = "\\x", peg$c122 = peg$literalExpectation("\\x", false), peg$c123 = /^[0-9a-fA-F]/, peg$c124 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false), peg$c125 = function(code) { return { type: TokenType.HEX, code: code.join('') } }, peg$c126 = "\\n", peg$c127 = peg$literalExpectation("\\n", false), peg$c128 = function() { return { type: TokenType.LINE_FEED } }, peg$c129 = "\\k<", peg$c130 = peg$literalExpectation("\\k<", false), peg$c131 = function(name) { return { type: TokenType.NAMED_BACK_REFERENCE, name: name } }, peg$c132 = "\\0", peg$c133 = peg$literalExpectation("\\0", false), peg$c134 = function() { return { type: TokenType.NUL } }, peg$c135 = /^[0-7]/, peg$c136 = peg$classExpectation([["0", "7"]], false, false), peg$c137 = function(code) { return { type: TokenType.OCTAL, code: code.join('') } }, peg$c138 = "\\t", peg$c139 = peg$literalExpectation("\\t", false), peg$c140 = function() { return { type: TokenType.TAB } }, peg$c141 = "\\u{", peg$c142 = peg$literalExpectation("\\u{", false), peg$c143 = function(code) { return { type: TokenType.UNICODE, code: code.join('') } }, peg$c144 = "\\p{", peg$c145 = peg$literalExpectation("\\p{", false), peg$c146 = /^[0-9a-zA-Z_=]/, peg$c147 = peg$classExpectation([["0", "9"], ["a", "z"], ["A", "Z"], "_", "="], false, false), peg$c148 = function(property) { return { type: TokenType.UNICODE_PROPERTY, property: property.join('') } }, peg$c149 = "\\P{", peg$c150 = peg$literalExpectation("\\P{", false), peg$c151 = function(property) { return { type: TokenType.NON_UNICODE_PROPERTY, property: property.join('') } }, peg$c152 = "\\u", peg$c153 = peg$literalExpectation("\\u", false), peg$c154 = function(code) { return { type: TokenType.UTF16, code: code.join('') } }, peg$c155 = "\\v", peg$c156 = peg$literalExpectation("\\v", false), peg$c157 = function() { return { type: TokenType.VERTICAL_TAB } }, peg$c158 = "\\s", peg$c159 = peg$literalExpectation("\\s", false), peg$c160 = function() { return { type: TokenType.WHITE_SPACE } }, peg$c161 = "\\S", peg$c162 = peg$literalExpectation("\\S", false), peg$c163 = function() { return { type: TokenType.NON_WHITE_SPACE } }, peg$c164 = function() { return { type: TokenType.WORD_BOUNDARY } }, peg$c165 = "\\B", peg$c166 = peg$literalExpectation("\\B", false), peg$c167 = function() { return { type: TokenType.NON_WORD_BOUNDARY } }, peg$c168 = "\\w", peg$c169 = peg$literalExpectation("\\w", false), peg$c170 = function() { return { type: TokenType.WORD } }, peg$c171 = "\\W", peg$c172 = peg$literalExpectation("\\W", false), peg$c173 = function() { return { type: TokenType.NON_WORD } }, peg$c174 = function(code) { return { type: TokenType.ESCAPE, code: code } }, peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result; if ("startRule" in options) { 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 location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildStructuredError( [peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location ); } function error(message, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildSimpleError(message, location); } function peg$literalExpectation(text, ignoreCase) { return { type: "literal", text: text, 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) { var details = peg$posDetailsCache[pos], 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) { var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos); return { start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column } }; } function peg$fail(expected) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected); } function peg$buildSimpleError(message, location) { return new peg$SyntaxError(message, null, null, location); } function peg$buildStructuredError(expected, found, location) { return new peg$SyntaxError( peg$SyntaxError.buildMessage(expected, found), expected, found, location ); } function peg$parseregexp() { var s0; s0 = peg$parsepatternMod(); if (s0 === peg$FAILED) { s0 = peg$parsepattern(); } return s0; } function peg$parsepattern() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$parsematch(); if (s1 !== peg$FAILED) { s2 = peg$currPos; if (input.charCodeAt(peg$currPos) === 124) { s3 = peg$c0; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s3 !== peg$FAILED) { s4 = peg$parsepattern(); if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c2(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsepatternMod() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 47) { s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s1 !== peg$FAILED) { s2 = peg$parsepattern(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 47) { s3 = peg$c3; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s3 !== peg$FAILED) { s4 = peg$parsemodifierPositive(); if (s4 === peg$FAILED) { s4 = null; } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c5(s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } 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$parsematch() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s2 = peg$c6; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s2 !== peg$FAILED) { s3 = peg$parsemodifier(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s4 = peg$c8; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } if (s4 !== peg$FAILED) { s2 = [s2, s3, s4]; s1 = s2; } 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 = null; } if (s1 !== peg$FAILED) { s2 = peg$parsebegin(); if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { s3 = peg$currPos; peg$silentFails++; s4 = peg$parsequantifier(); peg$silentFails--; if (s4 === peg$FAILED) { s3 = void 0; } else { peg$currPos = s3; s3 = peg$FAILED; } if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsequantified(); if (s5 === peg$FAILED) { s5 = peg$parsesubmatch(); } while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsequantified(); if (s5 === peg$FAILED) { s5 = peg$parsesubmatch(); } } if (s4 !== peg$FAILED) { s5 = peg$parseend(); if (s5 === peg$FAILED) { s5 = null; } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c10(s1, s2, s4, s5); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } 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$parsesubmatch() { var s0; s0 = peg$parsesubexp(); if (s0 === peg$FAILED) { s0 = peg$parsecharset(); if (s0 === peg$FAILED) { s0 = peg$parseterminal(); } } return s0; } function peg$parsebegin() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 94) { s1 = peg$c11; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c13(); } s0 = s1; return s0; } function peg$parseend() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 36) { s1 = peg$c14; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c15); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c16(); } s0 = s1; return s0; } function peg$parsemodifier() { var s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 63) { s1 = peg$c17; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s1 !== peg$FAILED) { s2 = peg$parsemodifierSpec(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c19(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsemodifierSpec() { var s0; s0 = peg$parsemodifierPositiveNegative(); if (s0 === peg$FAILED) { s0 = peg$parsemodifierPositive(); if (s0 === peg$FAILED) { s0 = peg$parsemodifierNegative(); } } return s0; } function peg$parsemodifierPositiveNegative() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = []; if (peg$c20.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c20.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s2 = peg$c22; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s2 !== peg$FAILED) { s3 = []; if (peg$c20.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) { s3.push(s4); if (peg$c20.test(input.charAt(peg$currPos))) { s4 = input.charAt(peg$currPos); peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } } } else { s3 = peg$FAILED; } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c24(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$parsemodifierPositive() { var s0, s1, s2; s0 = peg$currPos; s1 = []; if (peg$c20.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c20.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c25(s1); } s0 = s1; return s0; } function peg$parsemodifierNegative() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s1 = peg$c22; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s1 !== peg$FAILED) { s2 = []; if (peg$c20.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c20.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c26(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsequantified() { var s0, s1, s2; s0 = peg$currPos; s1 = peg$parsesubmatch(); if (s1 !== peg$FAILED) { s2 = peg$parsequantifier(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c27(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsequantifier() { var s0, s1, s2; peg$silentFails++; s0 = peg$currPos; s1 = peg$parsequantifierSpec(); if (s1 !== peg$FAILED) { s2 = peg$parsegreedyFlag(); if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c29(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } return s0; } function peg$parsequantifierSpec() { var s0; s0 = peg$parsequantifierSpecFull(); if (s0 === peg$FAILED) { s0 = peg$parsequantifierSpecAtLeast(); if (s0 === peg$FAILED) { s0 = peg$parsequantifierSpecExact(); if (s0 === peg$FAILED) { s0 = peg$parsequantifierRequired(); if (s0 === peg$FAILED) { s0 = peg$parsequantifierAny(); if (s0 === peg$FAILED) { s0 = peg$parsequantifierOptional(); } } } } } return s0; } function peg$parsequantifierSpecFull() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 123) { s1 = peg$c30; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s1 !== peg$FAILED) { s2 = peg$parseinteger(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s3 = peg$c32; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c33); } } if (s3 !== peg$FAILED) { s4 = peg$parseinteger(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s5 = peg$c34; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c35); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c36(s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } 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$parsequantifierSpecAtLeast() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 123) { s1 = peg$c30; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s1 !== peg$FAILED) { s2 = peg$parseinteger(); if (s2 !== peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c37) { s3 = peg$c37; peg$currPos += 2; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c39(s2); 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$parsequantifierSpecExact() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 123) { s1 = peg$c30; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } if (s1 !== peg$FAILED) { s2 = peg$parseinteger(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s3 = peg$c34; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c35); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c40(s2); 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$parsequantifierRequired() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 43) { s1 = peg$c41; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c43(); } s0 = s1; return s0; } function peg$parsequantifierAny() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 42) { s1 = peg$c44; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c46(); } s0 = s1; return s0; } function peg$parsequantifierOptional() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 63) { s1 = peg$c17; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c47(); } s0 = s1; return s0; } function peg$parsegreedyFlag() { var s0; if (input.charCodeAt(peg$currPos) === 63) { s0 = peg$c17; peg$currPos++; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } return s0; } function peg$parseinteger() { var s0, s1, s2; s0 = peg$currPos; s1 = []; if (peg$c48.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c49); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); if (peg$c48.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c49); } } } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c50(s1); } s0 = s1; return s0; } function peg$parsesubexp() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s1 = peg$c6; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s1 !== peg$FAILED) { s2 = peg$parsepositiveLookbehind(); if (s2 === peg$FAILED) { s2 = peg$parsenegativeLookbehind(); if (s2 === peg$FAILED) { s2 = peg$parsepositiveLookahead(); if (s2 === peg$FAILED) { s2 = peg$parsenegativeLookahead(); if (s2 === peg$FAILED) { s2 = peg$parsegroupNamed(); if (s2 === peg$FAILED) { s2 = peg$parsegroupNoCapture(); if (s2 === peg$FAILED) { s2 = peg$parsegroupModifiers(); if (s2 === peg$FAILED) { s2 = peg$parsemodifier(); if (s2 === peg$FAILED) { s2 = peg$parsegroupCapture(); } } } } } } } } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s3 = peg$c8; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c9); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c51(s2); 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$parsegroupCapture() { var s0, s1; s0 = peg$currPos; s1 = peg$parseregexp(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c52(s1); } s0 = s1; return s0; } function peg$parsegroupNoCapture() { var s0, s1, s2; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c53) { s1 = peg$c53; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s1 !== peg$FAILED) { s2 = peg$parseregexp(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c55(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsegroupNamed() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c56) { s1 = peg$c56; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c57); } } if (s1 !== peg$FAILED) { s2 = []; if (peg$c58.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c59); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); if (peg$c58.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c59); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { s3 = peg$c60; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s3 !== peg$FAILED) { s4 = peg$parseregexp(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c62(s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } 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$parsepositiveLookbehind() { var s0, s1, s2; s0 = peg$currPos; if (input.substr(peg$currPos, 3) === peg$c63) { s1 = peg$c63; peg$currPos += 3; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c64); } } if (s1 !== peg$FAILED) { s2 = peg$parseregexp(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c65(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsenegativeLookbehind() { var s0, s1, s2; s0 = peg$currPos; if (input.substr(peg$currPos, 3) === peg$c66) { s1 = peg$c66; peg$currPos += 3; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c67); } } if (s1 !== peg$FAILED) { s2 = peg$parseregexp(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c68(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsepositiveLookahead() { var s0, s1, s2; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c69) { s1 = peg$c69; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s1 !== peg$FAILED) { s2 = peg$parseregexp(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c71(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsenegativeLookahead() { var s0, s1, s2; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c72) { s1 = peg$c72; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s1 !== peg$FAILED) { s2 = peg$parseregexp(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c74(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsegroupModifiers() { var s0, s1, s2, s3, s4; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 63) { s1 = peg$c17; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s1 !== peg$FAILED) { s2 = peg$parsemodifierSpec(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 58) { s3 = peg$c75; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c76); } } if (s3 !== peg$FAILED) { s4 = peg$parseregexp(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c77(s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } 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$parsecharset() { var s0, s1, s2, s3, s4; peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s1 = peg$c79; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c80); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 94) { s2 = peg$c11; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s2 === peg$FAILED) { s2 = null; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsecharsetRange(); if (s4 === peg$FAILED) { s4 = peg$parsecharsetTerminal(); } while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsecharsetRange(); if (s4 === peg$FAILED) { s4 = peg$parsecharsetTerminal(); } } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s4 = peg$c81; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c82); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c83(s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c78); } } return s0; } function peg$parsecharsetRange() { var s0, s1, s2, s3; peg$silentFails++; s0 = peg$currPos; s1 = peg$parsecharsetTerminal(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { s2 = peg$c22; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s2 !== peg$FAILED) { s3 = peg$parsecharsetTerminal(); if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c85(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; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c84); } } return s0; } function peg$parsecharsetTerminal() { var s0, s1; peg$silentFails++; s0 = peg$parsecharsetEscapedCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsecharsetLiteral(); } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c86); } } return s0; } function peg$parsecharsetLiteral() { var s0, s1; s0 = peg$currPos; if (peg$c87.test(input.charAt(peg$currPos))) { s1 = input.charAt(peg$currPos); peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c88); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c89(s1); } s0 = s1; return s0; } function peg$parsecharsetEscapedCharacter() { var s0; s0 = peg$parsebackspaceCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsecontrolCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsedigitCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsenonDigitCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseformFeedCharacter(); if (s0 === peg$FAILED) { s0 = peg$parselineFeedCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsecarriageReturnCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsewhiteSpaceCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsenonWhiteSpaceCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsetabCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseverticalTabCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsewordCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsenonWordCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseoctalCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsehexCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseutf16Character(); if (s0 === peg$FAILED) { s0 = peg$parseunicodeCharacter(); if (s0 === peg$FAILED) { s0 = peg$parsenullCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseotherEscaped(); } } } } } } } } } } } } } } } } } } return s0; } function peg$parseterminal() { var s0; s0 = peg$parseanyCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseescapedCharacter(); if (s0 === peg$FAILED) { s0 = peg$parseliteral(); } } return s0; } function peg$parseanyCharacter() { var s0, s1; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { s1 = peg$c90; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s1 !