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; }