summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/esquery
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/esquery')
-rw-r--r--tools/node_modules/eslint/node_modules/esquery/README.md26
-rw-r--r--tools/node_modules/eslint/node_modules/esquery/esquery.js320
-rw-r--r--tools/node_modules/eslint/node_modules/esquery/license.txt24
-rw-r--r--tools/node_modules/eslint/node_modules/esquery/package.json72
-rw-r--r--tools/node_modules/eslint/node_modules/esquery/parser.js2595
5 files changed, 3037 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/esquery/README.md b/tools/node_modules/eslint/node_modules/esquery/README.md
new file mode 100644
index 0000000000..a3ee33479d
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/esquery/README.md
@@ -0,0 +1,26 @@
+ESQuery is a library for querying the AST output by Esprima for patterns of syntax using a CSS style selector system. Check out the demo:
+
+[demo](https://estools.github.io/esquery/)
+
+The following selectors are supported:
+* AST node type: `ForStatement`
+* [wildcard](http://dev.w3.org/csswg/selectors4/#universal-selector): `*`
+* [attribute existence](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr]`
+* [attribute value](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr="foo"]` or `[attr=123]`
+* attribute regex: `[attr=/foo.*/]`
+* attribute conditons: `[attr!="foo"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]`
+* nested attribute: `[attr.level2="foo"]`
+* field: `FunctionDeclaration > Identifier.id`
+* [First](http://dev.w3.org/csswg/selectors4/#the-first-child-pseudo) or [last](http://dev.w3.org/csswg/selectors4/#the-last-child-pseudo) child: `:first-child` or `:last-child`
+* [nth-child](http://dev.w3.org/csswg/selectors4/#the-nth-child-pseudo) (no ax+b support): `:nth-child(2)`
+* [nth-last-child](http://dev.w3.org/csswg/selectors4/#the-nth-last-child-pseudo) (no ax+b support): `:nth-last-child(1)`
+* [descendant](http://dev.w3.org/csswg/selectors4/#descendant-combinators): `ancestor descendant`
+* [child](http://dev.w3.org/csswg/selectors4/#child-combinators): `parent > child`
+* [following sibling](http://dev.w3.org/csswg/selectors4/#general-sibling-combinators): `node ~ sibling`
+* [adjacent sibling](http://dev.w3.org/csswg/selectors4/#adjacent-sibling-combinators): `node + adjacent`
+* [negation](http://dev.w3.org/csswg/selectors4/#negation-pseudo): `:not(ForStatement)`
+* [matches-any](http://dev.w3.org/csswg/selectors4/#matches): `:matches([attr] > :first-child, :last-child)`
+* [subject indicator](http://dev.w3.org/csswg/selectors4/#subject): `!IfStatement > [name="foo"]`
+* class of AST node: `:statement`, `:expression`, `:declaration`, `:function`, or `:pattern`
+
+[![Build Status](https://travis-ci.org/estools/esquery.png?branch=master)](https://travis-ci.org/estools/esquery)
diff --git a/tools/node_modules/eslint/node_modules/esquery/esquery.js b/tools/node_modules/eslint/node_modules/esquery/esquery.js
new file mode 100644
index 0000000000..5b67924a12
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/esquery/esquery.js
@@ -0,0 +1,320 @@
+/* vim: set sw=4 sts=4 : */
+(function () {
+
+ var estraverse = require('estraverse');
+ var parser = require('./parser');
+
+ var isArray = Array.isArray || function isArray(array) {
+ return {}.toString.call(array) === '[object Array]';
+ };
+
+ var LEFT_SIDE = {};
+ var RIGHT_SIDE = {};
+
+ function esqueryModule() {
+
+ /**
+ * Get the value of a property which may be multiple levels down in the object.
+ */
+ function getPath(obj, key) {
+ var i, keys = key.split(".");
+ for (i = 0; i < keys.length; i++) {
+ if (obj == null) { return obj; }
+ obj = obj[keys[i]];
+ }
+ return obj;
+ }
+
+ /**
+ * Determine whether `node` can be reached by following `path`, starting at `ancestor`.
+ */
+ function inPath(node, ancestor, path) {
+ var field, remainingPath, i;
+ if (path.length === 0) { return node === ancestor; }
+ if (ancestor == null) { return false; }
+ field = ancestor[path[0]];
+ remainingPath = path.slice(1);
+ if (isArray(field)) {
+ for (i = 0, l = field.length; i < l; ++i) {
+ if (inPath(node, field[i], remainingPath)) { return true; }
+ }
+ return false;
+ } else {
+ return inPath(node, field, remainingPath);
+ }
+ }
+
+ /**
+ * Given a `node` and its ancestors, determine if `node` is matched by `selector`.
+ */
+ function matches(node, selector, ancestry) {
+ var path, ancestor, i, l, p;
+ if (!selector) { return true; }
+ if (!node) { return false; }
+ if (!ancestry) { ancestry = []; }
+
+ switch(selector.type) {
+ case 'wildcard':
+ return true;
+
+ case 'identifier':
+ return selector.value.toLowerCase() === node.type.toLowerCase();
+
+ case 'field':
+ path = selector.name.split('.');
+ ancestor = ancestry[path.length - 1];
+ return inPath(node, ancestor, path);
+
+ case 'matches':
+ for (i = 0, l = selector.selectors.length; i < l; ++i) {
+ if (matches(node, selector.selectors[i], ancestry)) { return true; }
+ }
+ return false;
+
+ case 'compound':
+ for (i = 0, l = selector.selectors.length; i < l; ++i) {
+ if (!matches(node, selector.selectors[i], ancestry)) { return false; }
+ }
+ return true;
+
+ case 'not':
+ for (i = 0, l = selector.selectors.length; i < l; ++i) {
+ if (matches(node, selector.selectors[i], ancestry)) { return false; }
+ }
+ return true;
+
+ case 'child':
+ if (matches(node, selector.right, ancestry)) {
+ return matches(ancestry[0], selector.left, ancestry.slice(1));
+ }
+ return false;
+
+ case 'descendant':
+ if (matches(node, selector.right, ancestry)) {
+ for (i = 0, l = ancestry.length; i < l; ++i) {
+ if (matches(ancestry[i], selector.left, ancestry.slice(i + 1))) {
+ return true;
+ }
+ }
+ }
+ return false;
+
+ case 'attribute':
+ p = getPath(node, selector.name);
+ switch (selector.operator) {
+ case null:
+ case void 0:
+ return p != null;
+ case '=':
+ switch (selector.value.type) {
+ case 'regexp': return selector.value.value.test(p);
+ case 'literal': return '' + selector.value.value === '' + p;
+ case 'type': return selector.value.value === typeof p;
+ }
+ case '!=':
+ switch (selector.value.type) {
+ case 'regexp': return !selector.value.value.test(p);
+ case 'literal': return '' + selector.value.value !== '' + p;
+ case 'type': return selector.value.value !== typeof p;
+ }
+ case '<=': return p <= selector.value.value;
+ case '<': return p < selector.value.value;
+ case '>': return p > selector.value.value;
+ case '>=': return p >= selector.value.value;
+ }
+
+ case 'sibling':
+ return matches(node, selector.right, ancestry) &&
+ sibling(node, selector.left, ancestry, LEFT_SIDE) ||
+ selector.left.subject &&
+ matches(node, selector.left, ancestry) &&
+ sibling(node, selector.right, ancestry, RIGHT_SIDE);
+
+ case 'adjacent':
+ return matches(node, selector.right, ancestry) &&
+ adjacent(node, selector.left, ancestry, LEFT_SIDE) ||
+ selector.right.subject &&
+ matches(node, selector.left, ancestry) &&
+ adjacent(node, selector.right, ancestry, RIGHT_SIDE);
+
+ case 'nth-child':
+ return matches(node, selector.right, ancestry) &&
+ nthChild(node, ancestry, function (length) {
+ return selector.index.value - 1;
+ });
+
+ case 'nth-last-child':
+ return matches(node, selector.right, ancestry) &&
+ nthChild(node, ancestry, function (length) {
+ return length - selector.index.value;
+ });
+
+ case 'class':
+ if(!node.type) return false;
+ switch(selector.name.toLowerCase()){
+ case 'statement':
+ if(node.type.slice(-9) === 'Statement') return true;
+ // fallthrough: interface Declaration <: Statement { }
+ case 'declaration':
+ return node.type.slice(-11) === 'Declaration';
+ case 'pattern':
+ if(node.type.slice(-7) === 'Pattern') return true;
+ // fallthrough: interface Expression <: Node, Pattern { }
+ case 'expression':
+ return node.type.slice(-10) === 'Expression' ||
+ node.type === 'Literal' ||
+ node.type === 'Identifier';
+ case 'function':
+ return node.type.slice(0, 8) === 'Function' ||
+ node.type === 'ArrowFunctionExpression';
+ }
+ throw new Error('Unknown class name: ' + selector.name);
+ }
+
+ throw new Error('Unknown selector type: ' + selector.type);
+ }
+
+ /*
+ * Determines if the given node has a sibling that matches the given selector.
+ */
+ function sibling(node, selector, ancestry, side) {
+ var parent = ancestry[0], listProp, startIndex, keys, i, l, k, lowerBound, upperBound;
+ if (!parent) { return false; }
+ keys = estraverse.VisitorKeys[parent.type];
+ for (i = 0, l = keys.length; i < l; ++i) {
+ listProp = parent[keys[i]];
+ if (isArray(listProp)) {
+ startIndex = listProp.indexOf(node);
+ if (startIndex < 0) { continue; }
+ if (side === LEFT_SIDE) {
+ lowerBound = 0;
+ upperBound = startIndex;
+ } else {
+ lowerBound = startIndex + 1;
+ upperBound = listProp.length;
+ }
+ for (k = lowerBound; k < upperBound; ++k) {
+ if (matches(listProp[k], selector, ancestry)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /*
+ * Determines if the given node has an asjacent sibling that matches the given selector.
+ */
+ function adjacent(node, selector, ancestry, side) {
+ var parent = ancestry[0], listProp, keys, i, l, idx;
+ if (!parent) { return false; }
+ keys = estraverse.VisitorKeys[parent.type];
+ for (i = 0, l = keys.length; i < l; ++i) {
+ listProp = parent[keys[i]];
+ if (isArray(listProp)) {
+ idx = listProp.indexOf(node);
+ if (idx < 0) { continue; }
+ if (side === LEFT_SIDE && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
+ return true;
+ }
+ if (side === RIGHT_SIDE && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /*
+ * Determines if the given node is the nth child, determined by idxFn, which is given the containing list's length.
+ */
+ function nthChild(node, ancestry, idxFn) {
+ var parent = ancestry[0], listProp, keys, i, l, idx;
+ if (!parent) { return false; }
+ keys = estraverse.VisitorKeys[parent.type];
+ for (i = 0, l = keys.length; i < l; ++i) {
+ listProp = parent[keys[i]];
+ if (isArray(listProp)) {
+ idx = listProp.indexOf(node);
+ if (idx >= 0 && idx === idxFn(listProp.length)) { return true; }
+ }
+ }
+ return false;
+ }
+
+ /*
+ * For each selector node marked as a subject, find the portion of the selector that the subject must match.
+ */
+ function subjects(selector, ancestor) {
+ var results, p;
+ if (selector == null || typeof selector != 'object') { return []; }
+ if (ancestor == null) { ancestor = selector; }
+ results = selector.subject ? [ancestor] : [];
+ for(p in selector) {
+ if(!{}.hasOwnProperty.call(selector, p)) { continue; }
+ [].push.apply(results, subjects(selector[p], p === 'left' ? selector[p] : ancestor));
+ }
+ return results;
+ }
+
+ /**
+ * From a JS AST and a selector AST, collect all JS AST nodes that match the selector.
+ */
+ function match(ast, selector) {
+ var ancestry = [], results = [], altSubjects, i, l, k, m;
+ if (!selector) { return results; }
+ altSubjects = subjects(selector);
+ estraverse.traverse(ast, {
+ enter: function (node, parent) {
+ if (parent != null) { ancestry.unshift(parent); }
+ if (matches(node, selector, ancestry)) {
+ if (altSubjects.length) {
+ for (i = 0, l = altSubjects.length; i < l; ++i) {
+ if (matches(node, altSubjects[i], ancestry)) { results.push(node); }
+ for (k = 0, m = ancestry.length; k < m; ++k) {
+ if (matches(ancestry[k], altSubjects[i], ancestry.slice(k + 1))) {
+ results.push(ancestry[k]);
+ }
+ }
+ }
+ } else {
+ results.push(node);
+ }
+ }
+ },
+ leave: function () { ancestry.shift(); }
+ });
+ return results;
+ }
+
+ /**
+ * Parse a selector string and return its AST.
+ */
+ function parse(selector) {
+ return parser.parse(selector);
+ }
+
+ /**
+ * Query the code AST using the selector string.
+ */
+ function query(ast, selector) {
+ return match(ast, parse(selector));
+ }
+
+ query.parse = parse;
+ query.match = match;
+ query.matches = matches;
+ return query.query = query;
+ }
+
+
+ if (typeof define === "function" && define.amd) {
+ define(esqueryModule);
+ } else if (typeof module !== 'undefined' && module.exports) {
+ module.exports = esqueryModule();
+ } else {
+ this.esquery = esqueryModule();
+ }
+
+})();
diff --git a/tools/node_modules/eslint/node_modules/esquery/license.txt b/tools/node_modules/eslint/node_modules/esquery/license.txt
new file mode 100644
index 0000000000..52f915e268
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/esquery/license.txt
@@ -0,0 +1,24 @@
+Copyright (c) 2013, Joel Feenstra
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the ESQuery nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL JOEL FEENSTRA BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tools/node_modules/eslint/node_modules/esquery/package.json b/tools/node_modules/eslint/node_modules/esquery/package.json
new file mode 100644
index 0000000000..92af42d5ad
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/esquery/package.json
@@ -0,0 +1,72 @@
+{
+ "_from": "esquery@^1.0.0",
+ "_id": "esquery@1.0.0",
+ "_inBundle": false,
+ "_integrity": "sha1-z7qLV9f7qT8XKYqKAGoEzaE9gPo=",
+ "_location": "/eslint/esquery",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "esquery@^1.0.0",
+ "name": "esquery",
+ "escapedName": "esquery",
+ "rawSpec": "^1.0.0",
+ "saveSpec": null,
+ "fetchSpec": "^1.0.0"
+ },
+ "_requiredBy": [
+ "/eslint"
+ ],
+ "_resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.0.tgz",
+ "_shasum": "cfba8b57d7fba93f17298a8a006a04cda13d80fa",
+ "_spec": "esquery@^1.0.0",
+ "_where": "/Users/cjihrig/iojs/node/tools/eslint-tmp/node_modules/eslint",
+ "author": {
+ "name": "Joel Feenstra",
+ "email": "jrfeenst+esquery@gmail.com"
+ },
+ "bugs": {
+ "url": "https://github.com/jrfeenst/esquery/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "estraverse": "^4.0.0"
+ },
+ "deprecated": false,
+ "description": "A query library for ECMAScript AST using a CSS selector like query language.",
+ "devDependencies": {
+ "commonjs-everywhere": "~0.9.4",
+ "esprima": "~1.1.1",
+ "jstestr": ">=0.4",
+ "pegjs": "~0.7.0"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "files": [
+ "esquery.js",
+ "parser.js",
+ "license.txt",
+ "README.md"
+ ],
+ "homepage": "https://github.com/jrfeenst/esquery#readme",
+ "keywords": [
+ "ast",
+ "ecmascript",
+ "javascript",
+ "query"
+ ],
+ "license": "BSD",
+ "main": "esquery.js",
+ "name": "esquery",
+ "preferGlobal": false,
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/jrfeenst/esquery.git"
+ },
+ "scripts": {
+ "test": "node node_modules/jstestr/bin/jstestr.js path=tests"
+ },
+ "version": "1.0.0"
+}
diff --git a/tools/node_modules/eslint/node_modules/esquery/parser.js b/tools/node_modules/eslint/node_modules/esquery/parser.js
new file mode 100644
index 0000000000..2ce8134592
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/esquery/parser.js
@@ -0,0 +1,2595 @@
+var result = (function(){
+ /*
+ * Generated by PEG.js 0.7.0.
+ *
+ * http://pegjs.majda.cz/
+ */
+
+ function quote(s) {
+ /*
+ * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
+ * string literal except for the closing quote character, backslash,
+ * carriage return, line separator, paragraph separator, and line feed.
+ * Any character may appear in the form of an escape sequence.
+ *
+ * For portability, we also escape escape all control and non-ASCII
+ * characters. Note that "\0" and "\v" escape sequences are not used
+ * because JSHint does not like the first and IE the second.
+ */
+ return '"' + s
+ .replace(/\\/g, '\\\\') // backslash
+ .replace(/"/g, '\\"') // closing quote character
+ .replace(/\x08/g, '\\b') // backspace
+ .replace(/\t/g, '\\t') // horizontal tab
+ .replace(/\n/g, '\\n') // line feed
+ .replace(/\f/g, '\\f') // form feed
+ .replace(/\r/g, '\\r') // carriage return
+ .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape)
+ + '"';
+ }
+
+ var result = {
+ /*
+ * Parses the input with a generated parser. If the parsing is successfull,
+ * returns a value explicitly or implicitly specified by the grammar from
+ * which the parser was generated (see |PEG.buildParser|). If the parsing is
+ * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
+ */
+ parse: function(input, startRule) {
+ var parseFunctions = {
+ "start": parse_start,
+ "_": parse__,
+ "identifierName": parse_identifierName,
+ "binaryOp": parse_binaryOp,
+ "selectors": parse_selectors,
+ "selector": parse_selector,
+ "sequence": parse_sequence,
+ "atom": parse_atom,
+ "wildcard": parse_wildcard,
+ "identifier": parse_identifier,
+ "attr": parse_attr,
+ "attrOps": parse_attrOps,
+ "attrEqOps": parse_attrEqOps,
+ "attrName": parse_attrName,
+ "attrValue": parse_attrValue,
+ "string": parse_string,
+ "number": parse_number,
+ "path": parse_path,
+ "type": parse_type,
+ "regex": parse_regex,
+ "field": parse_field,
+ "negation": parse_negation,
+ "matches": parse_matches,
+ "firstChild": parse_firstChild,
+ "lastChild": parse_lastChild,
+ "nthChild": parse_nthChild,
+ "nthLastChild": parse_nthLastChild,
+ "class": parse_class
+ };
+
+ if (startRule !== undefined) {
+ if (parseFunctions[startRule] === undefined) {
+ throw new Error("Invalid rule name: " + quote(startRule) + ".");
+ }
+ } else {
+ startRule = "start";
+ }
+
+ var pos = 0;
+ var reportFailures = 0;
+ var rightmostFailuresPos = 0;
+ var rightmostFailuresExpected = [];
+ var cache = {};
+
+ function padLeft(input, padding, length) {
+ var result = input;
+
+ var padLength = length - input.length;
+ for (var i = 0; i < padLength; i++) {
+ result = padding + result;
+ }
+
+ return result;
+ }
+
+ function escape(ch) {
+ var charCode = ch.charCodeAt(0);
+ var escapeChar;
+ var length;
+
+ if (charCode <= 0xFF) {
+ escapeChar = 'x';
+ length = 2;
+ } else {
+ escapeChar = 'u';
+ length = 4;
+ }
+
+ return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
+ }
+
+ function matchFailed(failure) {
+ if (pos < rightmostFailuresPos) {
+ return;
+ }
+
+ if (pos > rightmostFailuresPos) {
+ rightmostFailuresPos = pos;
+ rightmostFailuresExpected = [];
+ }
+
+ rightmostFailuresExpected.push(failure);
+ }
+
+ function parse_start() {
+ var cacheKey = "start@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse__();
+ if (result0 !== null) {
+ result1 = parse_selectors();
+ if (result1 !== null) {
+ result2 = parse__();
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, ss) { return ss.length === 1 ? ss[0] : { type: 'matches', selectors: ss }; })(pos0, result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ result0 = parse__();
+ if (result0 !== null) {
+ result0 = (function(offset) { return void 0; })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse__() {
+ var cacheKey = "_@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+
+ result0 = [];
+ if (input.charCodeAt(pos) === 32) {
+ result1 = " ";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\" \"");
+ }
+ }
+ while (result1 !== null) {
+ result0.push(result1);
+ if (input.charCodeAt(pos) === 32) {
+ result1 = " ";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\" \"");
+ }
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_identifierName() {
+ var cacheKey = "identifierName@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+ var pos0;
+
+ pos0 = pos;
+ if (/^[^ [\],():#!=><~+.]/.test(input.charAt(pos))) {
+ result1 = input.charAt(pos);
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^ [\\],():#!=><~+.]");
+ }
+ }
+ if (result1 !== null) {
+ result0 = [];
+ while (result1 !== null) {
+ result0.push(result1);
+ if (/^[^ [\],():#!=><~+.]/.test(input.charAt(pos))) {
+ result1 = input.charAt(pos);
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^ [\\],():#!=><~+.]");
+ }
+ }
+ }
+ } else {
+ result0 = null;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, i) { return i.join(''); })(pos0, result0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_binaryOp() {
+ var cacheKey = "binaryOp@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse__();
+ if (result0 !== null) {
+ if (input.charCodeAt(pos) === 62) {
+ result1 = ">";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\">\"");
+ }
+ }
+ if (result1 !== null) {
+ result2 = parse__();
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset) { return 'child'; })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse__();
+ if (result0 !== null) {
+ if (input.charCodeAt(pos) === 126) {
+ result1 = "~";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"~\"");
+ }
+ }
+ if (result1 !== null) {
+ result2 = parse__();
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset) { return 'sibling'; })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse__();
+ if (result0 !== null) {
+ if (input.charCodeAt(pos) === 43) {
+ result1 = "+";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"+\"");
+ }
+ }
+ if (result1 !== null) {
+ result2 = parse__();
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset) { return 'adjacent'; })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 32) {
+ result0 = " ";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\" \"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset) { return 'descendant'; })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ }
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_selectors() {
+ var cacheKey = "selectors@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4, result5;
+ var pos0, pos1, pos2;
+
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse_selector();
+ if (result0 !== null) {
+ result1 = [];
+ pos2 = pos;
+ result2 = parse__();
+ if (result2 !== null) {
+ if (input.charCodeAt(pos) === 44) {
+ result3 = ",";
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("\",\"");
+ }
+ }
+ if (result3 !== null) {
+ result4 = parse__();
+ if (result4 !== null) {
+ result5 = parse_selector();
+ if (result5 !== null) {
+ result2 = [result2, result3, result4, result5];
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ while (result2 !== null) {
+ result1.push(result2);
+ pos2 = pos;
+ result2 = parse__();
+ if (result2 !== null) {
+ if (input.charCodeAt(pos) === 44) {
+ result3 = ",";
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("\",\"");
+ }
+ }
+ if (result3 !== null) {
+ result4 = parse__();
+ if (result4 !== null) {
+ result5 = parse_selector();
+ if (result5 !== null) {
+ result2 = [result2, result3, result4, result5];
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, s, ss) {
+ return [s].concat(ss.map(function (s) { return s[3]; }));
+ })(pos0, result0[0], result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_selector() {
+ var cacheKey = "selector@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3;
+ var pos0, pos1, pos2;
+
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse_sequence();
+ if (result0 !== null) {
+ result1 = [];
+ pos2 = pos;
+ result2 = parse_binaryOp();
+ if (result2 !== null) {
+ result3 = parse_sequence();
+ if (result3 !== null) {
+ result2 = [result2, result3];
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ while (result2 !== null) {
+ result1.push(result2);
+ pos2 = pos;
+ result2 = parse_binaryOp();
+ if (result2 !== null) {
+ result3 = parse_sequence();
+ if (result3 !== null) {
+ result2 = [result2, result3];
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ } else {
+ result2 = null;
+ pos = pos2;
+ }
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, a, ops) {
+ return ops.reduce(function (memo, rhs) {
+ return { type: rhs[0], left: memo, right: rhs[1] };
+ }, a);
+ })(pos0, result0[0], result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_sequence() {
+ var cacheKey = "sequence@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 33) {
+ result0 = "!";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"!\"");
+ }
+ }
+ result0 = result0 !== null ? result0 : "";
+ if (result0 !== null) {
+ result2 = parse_atom();
+ if (result2 !== null) {
+ result1 = [];
+ while (result2 !== null) {
+ result1.push(result2);
+ result2 = parse_atom();
+ }
+ } else {
+ result1 = null;
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, subject, as) {
+ var b = as.length === 1 ? as[0] : { type: 'compound', selectors: as };
+ if(subject) b.subject = true;
+ return b;
+ })(pos0, result0[0], result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_atom() {
+ var cacheKey = "atom@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0;
+
+ result0 = parse_wildcard();
+ if (result0 === null) {
+ result0 = parse_identifier();
+ if (result0 === null) {
+ result0 = parse_attr();
+ if (result0 === null) {
+ result0 = parse_field();
+ if (result0 === null) {
+ result0 = parse_negation();
+ if (result0 === null) {
+ result0 = parse_matches();
+ if (result0 === null) {
+ result0 = parse_firstChild();
+ if (result0 === null) {
+ result0 = parse_lastChild();
+ if (result0 === null) {
+ result0 = parse_nthChild();
+ if (result0 === null) {
+ result0 = parse_nthLastChild();
+ if (result0 === null) {
+ result0 = parse_class();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_wildcard() {
+ var cacheKey = "wildcard@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0;
+ var pos0;
+
+ pos0 = pos;
+ if (input.charCodeAt(pos) === 42) {
+ result0 = "*";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"*\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, a) { return { type: 'wildcard', value: a }; })(pos0, result0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_identifier() {
+ var cacheKey = "identifier@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 35) {
+ result0 = "#";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"#\"");
+ }
+ }
+ result0 = result0 !== null ? result0 : "";
+ if (result0 !== null) {
+ result1 = parse_identifierName();
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, i) { return { type: 'identifier', value: i }; })(pos0, result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_attr() {
+ var cacheKey = "attr@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 91) {
+ result0 = "[";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"[\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ result2 = parse_attrValue();
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ if (input.charCodeAt(pos) === 93) {
+ result4 = "]";
+ pos++;
+ } else {
+ result4 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"]\"");
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, v) { return v; })(pos0, result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_attrOps() {
+ var cacheKey = "attrOps@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (/^[><!]/.test(input.charAt(pos))) {
+ result0 = input.charAt(pos);
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("[><!]");
+ }
+ }
+ result0 = result0 !== null ? result0 : "";
+ if (result0 !== null) {
+ if (input.charCodeAt(pos) === 61) {
+ result1 = "=";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"=\"");
+ }
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, a) { return a + '='; })(pos0, result0[0]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ if (/^[><]/.test(input.charAt(pos))) {
+ result0 = input.charAt(pos);
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("[><]");
+ }
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_attrEqOps() {
+ var cacheKey = "attrEqOps@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 33) {
+ result0 = "!";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"!\"");
+ }
+ }
+ result0 = result0 !== null ? result0 : "";
+ if (result0 !== null) {
+ if (input.charCodeAt(pos) === 61) {
+ result1 = "=";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"=\"");
+ }
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, a) { return a + '='; })(pos0, result0[0]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_attrName() {
+ var cacheKey = "attrName@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+ var pos0;
+
+ pos0 = pos;
+ result1 = parse_identifierName();
+ if (result1 === null) {
+ if (input.charCodeAt(pos) === 46) {
+ result1 = ".";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\".\"");
+ }
+ }
+ }
+ if (result1 !== null) {
+ result0 = [];
+ while (result1 !== null) {
+ result0.push(result1);
+ result1 = parse_identifierName();
+ if (result1 === null) {
+ if (input.charCodeAt(pos) === 46) {
+ result1 = ".";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\".\"");
+ }
+ }
+ }
+ }
+ } else {
+ result0 = null;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, i) { return i.join(''); })(pos0, result0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_attrValue() {
+ var cacheKey = "attrValue@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse_attrName();
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ result2 = parse_attrEqOps();
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ result4 = parse_type();
+ if (result4 === null) {
+ result4 = parse_regex();
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, name, op, value) {
+ return { type: 'attribute', name: name, operator: op, value: value };
+ })(pos0, result0[0], result0[2], result0[4]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ pos1 = pos;
+ result0 = parse_attrName();
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ result2 = parse_attrOps();
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ result4 = parse_string();
+ if (result4 === null) {
+ result4 = parse_number();
+ if (result4 === null) {
+ result4 = parse_path();
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, name, op, value) {
+ return { type: 'attribute', name: name, operator: op, value: value };
+ })(pos0, result0[0], result0[2], result0[4]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ result0 = parse_attrName();
+ if (result0 !== null) {
+ result0 = (function(offset, name) { return { type: 'attribute', name: name }; })(pos0, result0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_string() {
+ var cacheKey = "string@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3;
+ var pos0, pos1, pos2, pos3;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 34) {
+ result0 = "\"";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\"\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = [];
+ if (/^[^\\"]/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^\\\\\"]");
+ }
+ }
+ if (result2 === null) {
+ pos2 = pos;
+ pos3 = pos;
+ if (input.charCodeAt(pos) === 92) {
+ result2 = "\\";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\\"");
+ }
+ }
+ if (result2 !== null) {
+ if (input.length > pos) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("any character");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [result2, result3];
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ if (result2 !== null) {
+ result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
+ }
+ if (result2 === null) {
+ pos = pos2;
+ }
+ }
+ while (result2 !== null) {
+ result1.push(result2);
+ if (/^[^\\"]/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^\\\\\"]");
+ }
+ }
+ if (result2 === null) {
+ pos2 = pos;
+ pos3 = pos;
+ if (input.charCodeAt(pos) === 92) {
+ result2 = "\\";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\\"");
+ }
+ }
+ if (result2 !== null) {
+ if (input.length > pos) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("any character");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [result2, result3];
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ if (result2 !== null) {
+ result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
+ }
+ if (result2 === null) {
+ pos = pos2;
+ }
+ }
+ }
+ if (result1 !== null) {
+ if (input.charCodeAt(pos) === 34) {
+ result2 = "\"";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\"\"");
+ }
+ }
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, d) {
+ return { type: 'literal', value: strUnescape(d.join('')) };
+ })(pos0, result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ if (result0 === null) {
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 39) {
+ result0 = "'";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"'\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = [];
+ if (/^[^\\']/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^\\\\']");
+ }
+ }
+ if (result2 === null) {
+ pos2 = pos;
+ pos3 = pos;
+ if (input.charCodeAt(pos) === 92) {
+ result2 = "\\";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\\"");
+ }
+ }
+ if (result2 !== null) {
+ if (input.length > pos) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("any character");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [result2, result3];
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ if (result2 !== null) {
+ result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
+ }
+ if (result2 === null) {
+ pos = pos2;
+ }
+ }
+ while (result2 !== null) {
+ result1.push(result2);
+ if (/^[^\\']/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^\\\\']");
+ }
+ }
+ if (result2 === null) {
+ pos2 = pos;
+ pos3 = pos;
+ if (input.charCodeAt(pos) === 92) {
+ result2 = "\\";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\\"");
+ }
+ }
+ if (result2 !== null) {
+ if (input.length > pos) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("any character");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [result2, result3];
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ } else {
+ result2 = null;
+ pos = pos3;
+ }
+ if (result2 !== null) {
+ result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]);
+ }
+ if (result2 === null) {
+ pos = pos2;
+ }
+ }
+ }
+ if (result1 !== null) {
+ if (input.charCodeAt(pos) === 39) {
+ result2 = "'";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"'\"");
+ }
+ }
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, d) {
+ return { type: 'literal', value: strUnescape(d.join('')) };
+ })(pos0, result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_number() {
+ var cacheKey = "number@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2;
+ var pos0, pos1, pos2;
+
+ pos0 = pos;
+ pos1 = pos;
+ pos2 = pos;
+ result0 = [];
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result1 = input.charAt(pos);
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ while (result1 !== null) {
+ result0.push(result1);
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result1 = input.charAt(pos);
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ }
+ if (result0 !== null) {
+ if (input.charCodeAt(pos) === 46) {
+ result1 = ".";
+ pos++;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\".\"");
+ }
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos2;
+ }
+ } else {
+ result0 = null;
+ pos = pos2;
+ }
+ result0 = result0 !== null ? result0 : "";
+ if (result0 !== null) {
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ if (result2 !== null) {
+ result1 = [];
+ while (result2 !== null) {
+ result1.push(result2);
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ }
+ } else {
+ result1 = null;
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, a, b) {
+ return { type: 'literal', value: parseFloat((a ? a.join('') : '') + b.join('')) };
+ })(pos0, result0[0], result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_path() {
+ var cacheKey = "path@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0;
+ var pos0;
+
+ pos0 = pos;
+ result0 = parse_identifierName();
+ if (result0 !== null) {
+ result0 = (function(offset, i) { return { type: 'literal', value: i }; })(pos0, result0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_type() {
+ var cacheKey = "type@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.substr(pos, 5) === "type(") {
+ result0 = "type(";
+ pos += 5;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"type(\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ if (/^[^ )]/.test(input.charAt(pos))) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^ )]");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [];
+ while (result3 !== null) {
+ result2.push(result3);
+ if (/^[^ )]/.test(input.charAt(pos))) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^ )]");
+ }
+ }
+ }
+ } else {
+ result2 = null;
+ }
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ if (input.charCodeAt(pos) === 41) {
+ result4 = ")";
+ pos++;
+ } else {
+ result4 = null;
+ if (reportFailures === 0) {
+ matchFailed("\")\"");
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, t) { return { type: 'type', value: t.join('') }; })(pos0, result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_regex() {
+ var cacheKey = "regex@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 47) {
+ result0 = "/";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"/\"");
+ }
+ }
+ if (result0 !== null) {
+ if (/^[^\/]/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^\\/]");
+ }
+ }
+ if (result2 !== null) {
+ result1 = [];
+ while (result2 !== null) {
+ result1.push(result2);
+ if (/^[^\/]/.test(input.charAt(pos))) {
+ result2 = input.charAt(pos);
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^\\/]");
+ }
+ }
+ }
+ } else {
+ result1 = null;
+ }
+ if (result1 !== null) {
+ if (input.charCodeAt(pos) === 47) {
+ result2 = "/";
+ pos++;
+ } else {
+ result2 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"/\"");
+ }
+ }
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, d) { return { type: 'regexp', value: new RegExp(d.join('')) }; })(pos0, result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_field() {
+ var cacheKey = "field@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1, pos2;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 46) {
+ result0 = ".";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\".\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse_identifierName();
+ if (result1 !== null) {
+ result2 = [];
+ pos2 = pos;
+ if (input.charCodeAt(pos) === 46) {
+ result3 = ".";
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("\".\"");
+ }
+ }
+ if (result3 !== null) {
+ result4 = parse_identifierName();
+ if (result4 !== null) {
+ result3 = [result3, result4];
+ } else {
+ result3 = null;
+ pos = pos2;
+ }
+ } else {
+ result3 = null;
+ pos = pos2;
+ }
+ while (result3 !== null) {
+ result2.push(result3);
+ pos2 = pos;
+ if (input.charCodeAt(pos) === 46) {
+ result3 = ".";
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("\".\"");
+ }
+ }
+ if (result3 !== null) {
+ result4 = parse_identifierName();
+ if (result4 !== null) {
+ result3 = [result3, result4];
+ } else {
+ result3 = null;
+ pos = pos2;
+ }
+ } else {
+ result3 = null;
+ pos = pos2;
+ }
+ }
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, i, is) {
+ return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)};
+ })(pos0, result0[1], result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_negation() {
+ var cacheKey = "negation@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.substr(pos, 5) === ":not(") {
+ result0 = ":not(";
+ pos += 5;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":not(\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ result2 = parse_selectors();
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ if (input.charCodeAt(pos) === 41) {
+ result4 = ")";
+ pos++;
+ } else {
+ result4 = null;
+ if (reportFailures === 0) {
+ matchFailed("\")\"");
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, ss) { return { type: 'not', selectors: ss }; })(pos0, result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_matches() {
+ var cacheKey = "matches@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.substr(pos, 9) === ":matches(") {
+ result0 = ":matches(";
+ pos += 9;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":matches(\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ result2 = parse_selectors();
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ if (input.charCodeAt(pos) === 41) {
+ result4 = ")";
+ pos++;
+ } else {
+ result4 = null;
+ if (reportFailures === 0) {
+ matchFailed("\")\"");
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, ss) { return { type: 'matches', selectors: ss }; })(pos0, result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_firstChild() {
+ var cacheKey = "firstChild@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0;
+ var pos0;
+
+ pos0 = pos;
+ if (input.substr(pos, 12) === ":first-child") {
+ result0 = ":first-child";
+ pos += 12;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":first-child\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset) { return nth(1); })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_lastChild() {
+ var cacheKey = "lastChild@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0;
+ var pos0;
+
+ pos0 = pos;
+ if (input.substr(pos, 11) === ":last-child") {
+ result0 = ":last-child";
+ pos += 11;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":last-child\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset) { return nthLast(1); })(pos0);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_nthChild() {
+ var cacheKey = "nthChild@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.substr(pos, 11) === ":nth-child(") {
+ result0 = ":nth-child(";
+ pos += 11;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":nth-child(\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [];
+ while (result3 !== null) {
+ result2.push(result3);
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ }
+ } else {
+ result2 = null;
+ }
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ if (input.charCodeAt(pos) === 41) {
+ result4 = ")";
+ pos++;
+ } else {
+ result4 = null;
+ if (reportFailures === 0) {
+ matchFailed("\")\"");
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, n) { return nth(parseInt(n.join(''), 10)); })(pos0, result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_nthLastChild() {
+ var cacheKey = "nthLastChild@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.substr(pos, 16) === ":nth-last-child(") {
+ result0 = ":nth-last-child(";
+ pos += 16;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":nth-last-child(\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse__();
+ if (result1 !== null) {
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ if (result3 !== null) {
+ result2 = [];
+ while (result3 !== null) {
+ result2.push(result3);
+ if (/^[0-9]/.test(input.charAt(pos))) {
+ result3 = input.charAt(pos);
+ pos++;
+ } else {
+ result3 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9]");
+ }
+ }
+ }
+ } else {
+ result2 = null;
+ }
+ if (result2 !== null) {
+ result3 = parse__();
+ if (result3 !== null) {
+ if (input.charCodeAt(pos) === 41) {
+ result4 = ")";
+ pos++;
+ } else {
+ result4 = null;
+ if (reportFailures === 0) {
+ matchFailed("\")\"");
+ }
+ }
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, n) { return nthLast(parseInt(n.join(''), 10)); })(pos0, result0[2]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+ function parse_class() {
+ var cacheKey = "class@" + pos;
+ var cachedResult = cache[cacheKey];
+ if (cachedResult) {
+ pos = cachedResult.nextPos;
+ return cachedResult.result;
+ }
+
+ var result0, result1;
+ var pos0, pos1;
+
+ pos0 = pos;
+ pos1 = pos;
+ if (input.charCodeAt(pos) === 58) {
+ result0 = ":";
+ pos++;
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\":\"");
+ }
+ }
+ if (result0 !== null) {
+ if (input.substr(pos, 9).toLowerCase() === "statement") {
+ result1 = input.substr(pos, 9);
+ pos += 9;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"statement\"");
+ }
+ }
+ if (result1 === null) {
+ if (input.substr(pos, 10).toLowerCase() === "expression") {
+ result1 = input.substr(pos, 10);
+ pos += 10;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"expression\"");
+ }
+ }
+ if (result1 === null) {
+ if (input.substr(pos, 11).toLowerCase() === "declaration") {
+ result1 = input.substr(pos, 11);
+ pos += 11;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"declaration\"");
+ }
+ }
+ if (result1 === null) {
+ if (input.substr(pos, 8).toLowerCase() === "function") {
+ result1 = input.substr(pos, 8);
+ pos += 8;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"function\"");
+ }
+ }
+ if (result1 === null) {
+ if (input.substr(pos, 7).toLowerCase() === "pattern") {
+ result1 = input.substr(pos, 7);
+ pos += 7;
+ } else {
+ result1 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"pattern\"");
+ }
+ }
+ }
+ }
+ }
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ } else {
+ result0 = null;
+ pos = pos1;
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, c) {
+ return { type: 'class', name: c };
+ })(pos0, result0[1]);
+ }
+ if (result0 === null) {
+ pos = pos0;
+ }
+
+ cache[cacheKey] = {
+ nextPos: pos,
+ result: result0
+ };
+ return result0;
+ }
+
+
+ function cleanupExpected(expected) {
+ expected.sort();
+
+ var lastExpected = null;
+ var cleanExpected = [];
+ for (var i = 0; i < expected.length; i++) {
+ if (expected[i] !== lastExpected) {
+ cleanExpected.push(expected[i]);
+ lastExpected = expected[i];
+ }
+ }
+ return cleanExpected;
+ }
+
+ function computeErrorPosition() {
+ /*
+ * The first idea was to use |String.split| to break the input up to the
+ * error position along newlines and derive the line and column from
+ * there. However IE's |split| implementation is so broken that it was
+ * enough to prevent it.
+ */
+
+ var line = 1;
+ var column = 1;
+ var seenCR = false;
+
+ for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
+ var ch = input.charAt(i);
+ if (ch === "\n") {
+ if (!seenCR) { line++; }
+ column = 1;
+ seenCR = false;
+ } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
+ line++;
+ column = 1;
+ seenCR = true;
+ } else {
+ column++;
+ seenCR = false;
+ }
+ }
+
+ return { line: line, column: column };
+ }
+
+
+ function nth(n) { return { type: 'nth-child', index: { type: 'literal', value: n } }; }
+ function nthLast(n) { return { type: 'nth-last-child', index: { type: 'literal', value: n } }; }
+ function strUnescape(s) {
+ return s.replace(/\\(.)/g, function(match, ch) {
+ switch(ch) {
+ case 'a': return '\a';
+ case 'b': return '\b';
+ case 'f': return '\f';
+ case 'n': return '\n';
+ case 'r': return '\r';
+ case 't': return '\t';
+ case 'v': return '\v';
+ default: return ch;
+ }
+ });
+ }
+
+
+ var result = parseFunctions[startRule]();
+
+ /*
+ * The parser is now in one of the following three states:
+ *
+ * 1. The parser successfully parsed the whole input.
+ *
+ * - |result !== null|
+ * - |pos === input.length|
+ * - |rightmostFailuresExpected| may or may not contain something
+ *
+ * 2. The parser successfully parsed only a part of the input.
+ *
+ * - |result !== null|
+ * - |pos < input.length|
+ * - |rightmostFailuresExpected| may or may not contain something
+ *
+ * 3. The parser did not successfully parse any part of the input.
+ *
+ * - |result === null|
+ * - |pos === 0|
+ * - |rightmostFailuresExpected| contains at least one failure
+ *
+ * All code following this comment (including called functions) must
+ * handle these states.
+ */
+ if (result === null || pos !== input.length) {
+ var offset = Math.max(pos, rightmostFailuresPos);
+ var found = offset < input.length ? input.charAt(offset) : null;
+ var errorPosition = computeErrorPosition();
+
+ throw new this.SyntaxError(
+ cleanupExpected(rightmostFailuresExpected),
+ found,
+ offset,
+ errorPosition.line,
+ errorPosition.column
+ );
+ }
+
+ return result;
+ },
+
+ /* Returns the parser source code. */
+ toSource: function() { return this._source; }
+ };
+
+ /* Thrown when a parser encounters a syntax error. */
+
+ result.SyntaxError = function(expected, found, offset, line, column) {
+ function buildMessage(expected, found) {
+ var expectedHumanized, foundHumanized;
+
+ switch (expected.length) {
+ case 0:
+ expectedHumanized = "end of input";
+ break;
+ case 1:
+ expectedHumanized = expected[0];
+ break;
+ default:
+ expectedHumanized = expected.slice(0, expected.length - 1).join(", ")
+ + " or "
+ + expected[expected.length - 1];
+ }
+
+ foundHumanized = found ? quote(found) : "end of input";
+
+ return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
+ }
+
+ this.name = "SyntaxError";
+ this.expected = expected;
+ this.found = found;
+ this.message = buildMessage(expected, found);
+ this.offset = offset;
+ this.line = line;
+ this.column = column;
+ };
+
+ result.SyntaxError.prototype = Error.prototype;
+
+ return result;
+})();
+if (typeof define === "function" && define.amd) { define(function(){ return result; }); } else if (typeof module !== "undefined" && module.exports) { module.exports = result; } else { this.esquery = result; }