2 * Generated by PEG.js 0.10.0.
6 (function(root, factory) {
7 if (typeof define === "function" && define.amd) {
9 } else if (typeof module === "object" && module.exports) {
10 module.exports = factory();
15 function peg$subclass(child, parent) {
16 function ctor() { this.constructor = child; }
17 ctor.prototype = parent.prototype;
18 child.prototype = new ctor();
21 function peg$SyntaxError(message, expected, found, location) {
22 this.message = message;
23 this.expected = expected;
25 this.location = location;
26 this.name = "SyntaxError";
28 if (typeof Error.captureStackTrace === "function") {
29 Error.captureStackTrace(this, peg$SyntaxError);
33 peg$subclass(peg$SyntaxError, Error);
35 peg$SyntaxError.buildMessage = function(expected, found) {
36 var DESCRIBE_EXPECTATION_FNS = {
37 literal: function(expectation) {
38 return "\"" + literalEscape(expectation.text) + "\"";
41 "class": function(expectation) {
42 var escapedParts = "",
45 for (i = 0; i < expectation.parts.length; i++) {
46 escapedParts += expectation.parts[i] instanceof Array
47 ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
48 : classEscape(expectation.parts[i]);
51 return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
54 any: function(expectation) {
55 return "any character";
58 end: function(expectation) {
59 return "end of input";
62 other: function(expectation) {
63 return expectation.description;
68 return ch.charCodeAt(0).toString(16).toUpperCase();
71 function literalEscape(s) {
73 .replace(/\\/g, '\\\\')
75 .replace(/\0/g, '\\0')
76 .replace(/\t/g, '\\t')
77 .replace(/\n/g, '\\n')
78 .replace(/\r/g, '\\r')
79 .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
80 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
83 function classEscape(s) {
85 .replace(/\\/g, '\\\\')
86 .replace(/\]/g, '\\]')
87 .replace(/\^/g, '\\^')
89 .replace(/\0/g, '\\0')
90 .replace(/\t/g, '\\t')
91 .replace(/\n/g, '\\n')
92 .replace(/\r/g, '\\r')
93 .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
94 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
97 function describeExpectation(expectation) {
98 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
101 function describeExpected(expected) {
102 var descriptions = new Array(expected.length),
105 for (i = 0; i < expected.length; i++) {
106 descriptions[i] = describeExpectation(expected[i]);
111 if (descriptions.length > 0) {
112 for (i = 1, j = 1; i < descriptions.length; i++) {
113 if (descriptions[i - 1] !== descriptions[i]) {
114 descriptions[j] = descriptions[i];
118 descriptions.length = j;
121 switch (descriptions.length) {
123 return descriptions[0];
126 return descriptions[0] + " or " + descriptions[1];
129 return descriptions.slice(0, -1).join(", ")
131 + descriptions[descriptions.length - 1];
135 function describeFound(found) {
136 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
139 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
142 function peg$parse(input, options) {
143 options = options !== void 0 ? options : {};
147 peg$startRuleFunctions = { start: peg$parsestart },
148 peg$startRuleFunction = peg$parsestart,
150 peg$c0 = function(ss) {
151 return ss.length === 1 ? ss[0] : { type: 'matches', selectors: ss };
153 peg$c1 = function() { return void 0; },
155 peg$c3 = peg$literalExpectation(" ", false),
156 peg$c4 = /^[^ [\],():#!=><~+.]/,
157 peg$c5 = peg$classExpectation([" ", "[", "]", ",", "(", ")", ":", "#", "!", "=", ">", "<", "~", "+", "."], true, false),
158 peg$c6 = function(i) { return i.join(''); },
160 peg$c8 = peg$literalExpectation(">", false),
161 peg$c9 = function() { return 'child'; },
163 peg$c11 = peg$literalExpectation("~", false),
164 peg$c12 = function() { return 'sibling'; },
166 peg$c14 = peg$literalExpectation("+", false),
167 peg$c15 = function() { return 'adjacent'; },
168 peg$c16 = function() { return 'descendant'; },
170 peg$c18 = peg$literalExpectation(",", false),
171 peg$c19 = function(s, ss) {
172 return [s].concat(ss.map(function (s) { return s[3]; }));
174 peg$c20 = function(a, ops) {
175 return ops.reduce(function (memo, rhs) {
176 return { type: rhs[0], left: memo, right: rhs[1] };
180 peg$c22 = peg$literalExpectation("!", false),
181 peg$c23 = function(subject, as) {
182 const b = as.length === 1 ? as[0] : { type: 'compound', selectors: as };
183 if(subject) b.subject = true;
187 peg$c25 = peg$literalExpectation("*", false),
188 peg$c26 = function(a) { return { type: 'wildcard', value: a }; },
190 peg$c28 = peg$literalExpectation("#", false),
191 peg$c29 = function(i) { return { type: 'identifier', value: i }; },
193 peg$c31 = peg$literalExpectation("[", false),
195 peg$c33 = peg$literalExpectation("]", false),
196 peg$c34 = function(v) { return v; },
198 peg$c36 = peg$classExpectation([">", "<", "!"], false, false),
200 peg$c38 = peg$literalExpectation("=", false),
201 peg$c39 = function(a) { return (a || '') + '='; },
203 peg$c41 = peg$classExpectation([">", "<"], false, false),
205 peg$c43 = peg$literalExpectation(".", false),
206 peg$c44 = function(name, op, value) {
207 return { type: 'attribute', name: name, operator: op, value: value };
209 peg$c45 = function(name) { return { type: 'attribute', name: name }; },
211 peg$c47 = peg$literalExpectation("\"", false),
213 peg$c49 = peg$classExpectation(["\\", "\""], true, false),
215 peg$c51 = peg$literalExpectation("\\", false),
216 peg$c52 = peg$anyExpectation(),
217 peg$c53 = function(a, b) { return a + b; },
218 peg$c54 = function(d) {
219 return { type: 'literal', value: strUnescape(d.join('')) };
222 peg$c56 = peg$literalExpectation("'", false),
224 peg$c58 = peg$classExpectation(["\\", "'"], true, false),
226 peg$c60 = peg$classExpectation([["0", "9"]], false, false),
227 peg$c61 = function(a, b) {
228 // Can use `a.flat().join('')` once supported
229 const leadingDecimals = a ? [].concat.apply([], a).join('') : '';
230 return { type: 'literal', value: parseFloat(leadingDecimals + b.join('')) };
232 peg$c62 = function(i) { return { type: 'literal', value: i }; },
234 peg$c64 = peg$literalExpectation("type(", false),
236 peg$c66 = peg$classExpectation([" ", ")"], true, false),
238 peg$c68 = peg$literalExpectation(")", false),
239 peg$c69 = function(t) { return { type: 'type', value: t.join('') }; },
241 peg$c71 = peg$classExpectation(["i", "m", "s", "u"], false, false),
243 peg$c73 = peg$literalExpectation("/", false),
245 peg$c75 = peg$classExpectation(["/"], true, false),
246 peg$c76 = function(d, flgs) { return {
247 type: 'regexp', value: new RegExp(d.join(''), flgs ? flgs.join('') : '') };
249 peg$c77 = function(i, is) {
250 return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)};
253 peg$c79 = peg$literalExpectation(":not(", false),
254 peg$c80 = function(ss) { return { type: 'not', selectors: ss }; },
255 peg$c81 = ":matches(",
256 peg$c82 = peg$literalExpectation(":matches(", false),
257 peg$c83 = function(ss) { return { type: 'matches', selectors: ss }; },
259 peg$c85 = peg$literalExpectation(":has(", false),
260 peg$c86 = function(ss) { return { type: 'has', selectors: ss }; },
261 peg$c87 = ":first-child",
262 peg$c88 = peg$literalExpectation(":first-child", false),
263 peg$c89 = function() { return nth(1); },
264 peg$c90 = ":last-child",
265 peg$c91 = peg$literalExpectation(":last-child", false),
266 peg$c92 = function() { return nthLast(1); },
267 peg$c93 = ":nth-child(",
268 peg$c94 = peg$literalExpectation(":nth-child(", false),
269 peg$c95 = function(n) { return nth(parseInt(n.join(''), 10)); },
270 peg$c96 = ":nth-last-child(",
271 peg$c97 = peg$literalExpectation(":nth-last-child(", false),
272 peg$c98 = function(n) { return nthLast(parseInt(n.join(''), 10)); },
274 peg$c100 = peg$literalExpectation(":", false),
275 peg$c101 = "statement",
276 peg$c102 = peg$literalExpectation("statement", true),
277 peg$c103 = "expression",
278 peg$c104 = peg$literalExpectation("expression", true),
279 peg$c105 = "declaration",
280 peg$c106 = peg$literalExpectation("declaration", true),
281 peg$c107 = "function",
282 peg$c108 = peg$literalExpectation("function", true),
283 peg$c109 = "pattern",
284 peg$c110 = peg$literalExpectation("pattern", true),
285 peg$c111 = function(c) {
286 return { type: 'class', name: c };
291 peg$posDetailsCache = [{ line: 1, column: 1 }],
293 peg$maxFailExpected = [],
296 peg$resultsCache = {},
300 if ("startRule" in options) {
301 if (!(options.startRule in peg$startRuleFunctions)) {
302 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
305 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
309 return input.substring(peg$savedPos, peg$currPos);
312 function location() {
313 return peg$computeLocation(peg$savedPos, peg$currPos);
316 function expected(description, location) {
317 location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
319 throw peg$buildStructuredError(
320 [peg$otherExpectation(description)],
321 input.substring(peg$savedPos, peg$currPos),
326 function error(message, location) {
327 location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
329 throw peg$buildSimpleError(message, location);
332 function peg$literalExpectation(text, ignoreCase) {
333 return { type: "literal", text: text, ignoreCase: ignoreCase };
336 function peg$classExpectation(parts, inverted, ignoreCase) {
337 return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
340 function peg$anyExpectation() {
341 return { type: "any" };
344 function peg$endExpectation() {
345 return { type: "end" };
348 function peg$otherExpectation(description) {
349 return { type: "other", description: description };
352 function peg$computePosDetails(pos) {
353 var details = peg$posDetailsCache[pos], p;
359 while (!peg$posDetailsCache[p]) {
363 details = peg$posDetailsCache[p];
366 column: details.column
370 if (input.charCodeAt(p) === 10) {
380 peg$posDetailsCache[pos] = details;
385 function peg$computeLocation(startPos, endPos) {
386 var startPosDetails = peg$computePosDetails(startPos),
387 endPosDetails = peg$computePosDetails(endPos);
392 line: startPosDetails.line,
393 column: startPosDetails.column
397 line: endPosDetails.line,
398 column: endPosDetails.column
403 function peg$fail(expected) {
404 if (peg$currPos < peg$maxFailPos) { return; }
406 if (peg$currPos > peg$maxFailPos) {
407 peg$maxFailPos = peg$currPos;
408 peg$maxFailExpected = [];
411 peg$maxFailExpected.push(expected);
414 function peg$buildSimpleError(message, location) {
415 return new peg$SyntaxError(message, null, null, location);
418 function peg$buildStructuredError(expected, found, location) {
419 return new peg$SyntaxError(
420 peg$SyntaxError.buildMessage(expected, found),
427 function peg$parsestart() {
430 var key = peg$currPos * 30 + 0,
431 cached = peg$resultsCache[key];
434 peg$currPos = cached.nextPos;
436 return cached.result;
441 if (s1 !== peg$FAILED) {
442 s2 = peg$parseselectors();
443 if (s2 !== peg$FAILED) {
445 if (s3 !== peg$FAILED) {
461 if (s0 === peg$FAILED) {
464 if (s1 !== peg$FAILED) {
471 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
476 function peg$parse_() {
479 var key = peg$currPos * 30 + 1,
480 cached = peg$resultsCache[key];
483 peg$currPos = cached.nextPos;
485 return cached.result;
489 if (input.charCodeAt(peg$currPos) === 32) {
494 if (peg$silentFails === 0) { peg$fail(peg$c3); }
496 while (s1 !== peg$FAILED) {
498 if (input.charCodeAt(peg$currPos) === 32) {
503 if (peg$silentFails === 0) { peg$fail(peg$c3); }
507 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
512 function peg$parseidentifierName() {
515 var key = peg$currPos * 30 + 2,
516 cached = peg$resultsCache[key];
519 peg$currPos = cached.nextPos;
521 return cached.result;
526 if (peg$c4.test(input.charAt(peg$currPos))) {
527 s2 = input.charAt(peg$currPos);
531 if (peg$silentFails === 0) { peg$fail(peg$c5); }
533 if (s2 !== peg$FAILED) {
534 while (s2 !== peg$FAILED) {
536 if (peg$c4.test(input.charAt(peg$currPos))) {
537 s2 = input.charAt(peg$currPos);
541 if (peg$silentFails === 0) { peg$fail(peg$c5); }
547 if (s1 !== peg$FAILED) {
553 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
558 function peg$parsebinaryOp() {
561 var key = peg$currPos * 30 + 3,
562 cached = peg$resultsCache[key];
565 peg$currPos = cached.nextPos;
567 return cached.result;
572 if (s1 !== peg$FAILED) {
573 if (input.charCodeAt(peg$currPos) === 62) {
578 if (peg$silentFails === 0) { peg$fail(peg$c8); }
580 if (s2 !== peg$FAILED) {
582 if (s3 !== peg$FAILED) {
598 if (s0 === peg$FAILED) {
601 if (s1 !== peg$FAILED) {
602 if (input.charCodeAt(peg$currPos) === 126) {
607 if (peg$silentFails === 0) { peg$fail(peg$c11); }
609 if (s2 !== peg$FAILED) {
611 if (s3 !== peg$FAILED) {
627 if (s0 === peg$FAILED) {
630 if (s1 !== peg$FAILED) {
631 if (input.charCodeAt(peg$currPos) === 43) {
636 if (peg$silentFails === 0) { peg$fail(peg$c14); }
638 if (s2 !== peg$FAILED) {
640 if (s3 !== peg$FAILED) {
656 if (s0 === peg$FAILED) {
658 if (input.charCodeAt(peg$currPos) === 32) {
663 if (peg$silentFails === 0) { peg$fail(peg$c3); }
665 if (s1 !== peg$FAILED) {
667 if (s2 !== peg$FAILED) {
683 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
688 function peg$parseselectors() {
689 var s0, s1, s2, s3, s4, s5, s6, s7;
691 var key = peg$currPos * 30 + 4,
692 cached = peg$resultsCache[key];
695 peg$currPos = cached.nextPos;
697 return cached.result;
701 s1 = peg$parseselector();
702 if (s1 !== peg$FAILED) {
706 if (s4 !== peg$FAILED) {
707 if (input.charCodeAt(peg$currPos) === 44) {
712 if (peg$silentFails === 0) { peg$fail(peg$c18); }
714 if (s5 !== peg$FAILED) {
716 if (s6 !== peg$FAILED) {
717 s7 = peg$parseselector();
718 if (s7 !== peg$FAILED) {
719 s4 = [s4, s5, s6, s7];
737 while (s3 !== peg$FAILED) {
741 if (s4 !== peg$FAILED) {
742 if (input.charCodeAt(peg$currPos) === 44) {
747 if (peg$silentFails === 0) { peg$fail(peg$c18); }
749 if (s5 !== peg$FAILED) {
751 if (s6 !== peg$FAILED) {
752 s7 = peg$parseselector();
753 if (s7 !== peg$FAILED) {
754 s4 = [s4, s5, s6, s7];
773 if (s2 !== peg$FAILED) {
775 s1 = peg$c19(s1, s2);
786 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
791 function peg$parseselector() {
792 var s0, s1, s2, s3, s4, s5;
794 var key = peg$currPos * 30 + 5,
795 cached = peg$resultsCache[key];
798 peg$currPos = cached.nextPos;
800 return cached.result;
804 s1 = peg$parsesequence();
805 if (s1 !== peg$FAILED) {
808 s4 = peg$parsebinaryOp();
809 if (s4 !== peg$FAILED) {
810 s5 = peg$parsesequence();
811 if (s5 !== peg$FAILED) {
822 while (s3 !== peg$FAILED) {
825 s4 = peg$parsebinaryOp();
826 if (s4 !== peg$FAILED) {
827 s5 = peg$parsesequence();
828 if (s5 !== peg$FAILED) {
840 if (s2 !== peg$FAILED) {
842 s1 = peg$c20(s1, s2);
853 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
858 function peg$parsesequence() {
861 var key = peg$currPos * 30 + 6,
862 cached = peg$resultsCache[key];
865 peg$currPos = cached.nextPos;
867 return cached.result;
871 if (input.charCodeAt(peg$currPos) === 33) {
876 if (peg$silentFails === 0) { peg$fail(peg$c22); }
878 if (s1 === peg$FAILED) {
881 if (s1 !== peg$FAILED) {
883 s3 = peg$parseatom();
884 if (s3 !== peg$FAILED) {
885 while (s3 !== peg$FAILED) {
887 s3 = peg$parseatom();
892 if (s2 !== peg$FAILED) {
894 s1 = peg$c23(s1, s2);
905 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
910 function peg$parseatom() {
913 var key = peg$currPos * 30 + 7,
914 cached = peg$resultsCache[key];
917 peg$currPos = cached.nextPos;
919 return cached.result;
922 s0 = peg$parsewildcard();
923 if (s0 === peg$FAILED) {
924 s0 = peg$parseidentifier();
925 if (s0 === peg$FAILED) {
926 s0 = peg$parseattr();
927 if (s0 === peg$FAILED) {
928 s0 = peg$parsefield();
929 if (s0 === peg$FAILED) {
930 s0 = peg$parsenegation();
931 if (s0 === peg$FAILED) {
932 s0 = peg$parsematches();
933 if (s0 === peg$FAILED) {
935 if (s0 === peg$FAILED) {
936 s0 = peg$parsefirstChild();
937 if (s0 === peg$FAILED) {
938 s0 = peg$parselastChild();
939 if (s0 === peg$FAILED) {
940 s0 = peg$parsenthChild();
941 if (s0 === peg$FAILED) {
942 s0 = peg$parsenthLastChild();
943 if (s0 === peg$FAILED) {
944 s0 = peg$parseclass();
957 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
962 function peg$parsewildcard() {
965 var key = peg$currPos * 30 + 8,
966 cached = peg$resultsCache[key];
969 peg$currPos = cached.nextPos;
971 return cached.result;
975 if (input.charCodeAt(peg$currPos) === 42) {
980 if (peg$silentFails === 0) { peg$fail(peg$c25); }
982 if (s1 !== peg$FAILED) {
988 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
993 function peg$parseidentifier() {
996 var key = peg$currPos * 30 + 9,
997 cached = peg$resultsCache[key];
1000 peg$currPos = cached.nextPos;
1002 return cached.result;
1006 if (input.charCodeAt(peg$currPos) === 35) {
1011 if (peg$silentFails === 0) { peg$fail(peg$c28); }
1013 if (s1 === peg$FAILED) {
1016 if (s1 !== peg$FAILED) {
1017 s2 = peg$parseidentifierName();
1018 if (s2 !== peg$FAILED) {
1031 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1036 function peg$parseattr() {
1037 var s0, s1, s2, s3, s4, s5;
1039 var key = peg$currPos * 30 + 10,
1040 cached = peg$resultsCache[key];
1043 peg$currPos = cached.nextPos;
1045 return cached.result;
1049 if (input.charCodeAt(peg$currPos) === 91) {
1054 if (peg$silentFails === 0) { peg$fail(peg$c31); }
1056 if (s1 !== peg$FAILED) {
1058 if (s2 !== peg$FAILED) {
1059 s3 = peg$parseattrValue();
1060 if (s3 !== peg$FAILED) {
1062 if (s4 !== peg$FAILED) {
1063 if (input.charCodeAt(peg$currPos) === 93) {
1068 if (peg$silentFails === 0) { peg$fail(peg$c33); }
1070 if (s5 !== peg$FAILED) {
1095 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1100 function peg$parseattrOps() {
1103 var key = peg$currPos * 30 + 11,
1104 cached = peg$resultsCache[key];
1107 peg$currPos = cached.nextPos;
1109 return cached.result;
1113 if (peg$c35.test(input.charAt(peg$currPos))) {
1114 s1 = input.charAt(peg$currPos);
1118 if (peg$silentFails === 0) { peg$fail(peg$c36); }
1120 if (s1 === peg$FAILED) {
1123 if (s1 !== peg$FAILED) {
1124 if (input.charCodeAt(peg$currPos) === 61) {
1129 if (peg$silentFails === 0) { peg$fail(peg$c38); }
1131 if (s2 !== peg$FAILED) {
1143 if (s0 === peg$FAILED) {
1144 if (peg$c40.test(input.charAt(peg$currPos))) {
1145 s0 = input.charAt(peg$currPos);
1149 if (peg$silentFails === 0) { peg$fail(peg$c41); }
1153 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1158 function peg$parseattrEqOps() {
1161 var key = peg$currPos * 30 + 12,
1162 cached = peg$resultsCache[key];
1165 peg$currPos = cached.nextPos;
1167 return cached.result;
1171 if (input.charCodeAt(peg$currPos) === 33) {
1176 if (peg$silentFails === 0) { peg$fail(peg$c22); }
1178 if (s1 === peg$FAILED) {
1181 if (s1 !== peg$FAILED) {
1182 if (input.charCodeAt(peg$currPos) === 61) {
1187 if (peg$silentFails === 0) { peg$fail(peg$c38); }
1189 if (s2 !== peg$FAILED) {
1202 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1207 function peg$parseattrName() {
1210 var key = peg$currPos * 30 + 13,
1211 cached = peg$resultsCache[key];
1214 peg$currPos = cached.nextPos;
1216 return cached.result;
1221 s2 = peg$parseidentifierName();
1222 if (s2 === peg$FAILED) {
1223 if (input.charCodeAt(peg$currPos) === 46) {
1228 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1231 if (s2 !== peg$FAILED) {
1232 while (s2 !== peg$FAILED) {
1234 s2 = peg$parseidentifierName();
1235 if (s2 === peg$FAILED) {
1236 if (input.charCodeAt(peg$currPos) === 46) {
1241 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1248 if (s1 !== peg$FAILED) {
1254 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1259 function peg$parseattrValue() {
1260 var s0, s1, s2, s3, s4, s5;
1262 var key = peg$currPos * 30 + 14,
1263 cached = peg$resultsCache[key];
1266 peg$currPos = cached.nextPos;
1268 return cached.result;
1272 s1 = peg$parseattrName();
1273 if (s1 !== peg$FAILED) {
1275 if (s2 !== peg$FAILED) {
1276 s3 = peg$parseattrEqOps();
1277 if (s3 !== peg$FAILED) {
1279 if (s4 !== peg$FAILED) {
1280 s5 = peg$parsetype();
1281 if (s5 === peg$FAILED) {
1282 s5 = peg$parseregex();
1284 if (s5 !== peg$FAILED) {
1286 s1 = peg$c44(s1, s3, s5);
1308 if (s0 === peg$FAILED) {
1310 s1 = peg$parseattrName();
1311 if (s1 !== peg$FAILED) {
1313 if (s2 !== peg$FAILED) {
1314 s3 = peg$parseattrOps();
1315 if (s3 !== peg$FAILED) {
1317 if (s4 !== peg$FAILED) {
1318 s5 = peg$parsestring();
1319 if (s5 === peg$FAILED) {
1320 s5 = peg$parsenumber();
1321 if (s5 === peg$FAILED) {
1322 s5 = peg$parsepath();
1325 if (s5 !== peg$FAILED) {
1327 s1 = peg$c44(s1, s3, s5);
1349 if (s0 === peg$FAILED) {
1351 s1 = peg$parseattrName();
1352 if (s1 !== peg$FAILED) {
1360 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1365 function peg$parsestring() {
1366 var s0, s1, s2, s3, s4, s5;
1368 var key = peg$currPos * 30 + 15,
1369 cached = peg$resultsCache[key];
1372 peg$currPos = cached.nextPos;
1374 return cached.result;
1378 if (input.charCodeAt(peg$currPos) === 34) {
1383 if (peg$silentFails === 0) { peg$fail(peg$c47); }
1385 if (s1 !== peg$FAILED) {
1387 if (peg$c48.test(input.charAt(peg$currPos))) {
1388 s3 = input.charAt(peg$currPos);
1392 if (peg$silentFails === 0) { peg$fail(peg$c49); }
1394 if (s3 === peg$FAILED) {
1396 if (input.charCodeAt(peg$currPos) === 92) {
1401 if (peg$silentFails === 0) { peg$fail(peg$c51); }
1403 if (s4 !== peg$FAILED) {
1404 if (input.length > peg$currPos) {
1405 s5 = input.charAt(peg$currPos);
1409 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1411 if (s5 !== peg$FAILED) {
1413 s4 = peg$c53(s4, s5);
1424 while (s3 !== peg$FAILED) {
1426 if (peg$c48.test(input.charAt(peg$currPos))) {
1427 s3 = input.charAt(peg$currPos);
1431 if (peg$silentFails === 0) { peg$fail(peg$c49); }
1433 if (s3 === peg$FAILED) {
1435 if (input.charCodeAt(peg$currPos) === 92) {
1440 if (peg$silentFails === 0) { peg$fail(peg$c51); }
1442 if (s4 !== peg$FAILED) {
1443 if (input.length > peg$currPos) {
1444 s5 = input.charAt(peg$currPos);
1448 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1450 if (s5 !== peg$FAILED) {
1452 s4 = peg$c53(s4, s5);
1464 if (s2 !== peg$FAILED) {
1465 if (input.charCodeAt(peg$currPos) === 34) {
1470 if (peg$silentFails === 0) { peg$fail(peg$c47); }
1472 if (s3 !== peg$FAILED) {
1488 if (s0 === peg$FAILED) {
1490 if (input.charCodeAt(peg$currPos) === 39) {
1495 if (peg$silentFails === 0) { peg$fail(peg$c56); }
1497 if (s1 !== peg$FAILED) {
1499 if (peg$c57.test(input.charAt(peg$currPos))) {
1500 s3 = input.charAt(peg$currPos);
1504 if (peg$silentFails === 0) { peg$fail(peg$c58); }
1506 if (s3 === peg$FAILED) {
1508 if (input.charCodeAt(peg$currPos) === 92) {
1513 if (peg$silentFails === 0) { peg$fail(peg$c51); }
1515 if (s4 !== peg$FAILED) {
1516 if (input.length > peg$currPos) {
1517 s5 = input.charAt(peg$currPos);
1521 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1523 if (s5 !== peg$FAILED) {
1525 s4 = peg$c53(s4, s5);
1536 while (s3 !== peg$FAILED) {
1538 if (peg$c57.test(input.charAt(peg$currPos))) {
1539 s3 = input.charAt(peg$currPos);
1543 if (peg$silentFails === 0) { peg$fail(peg$c58); }
1545 if (s3 === peg$FAILED) {
1547 if (input.charCodeAt(peg$currPos) === 92) {
1552 if (peg$silentFails === 0) { peg$fail(peg$c51); }
1554 if (s4 !== peg$FAILED) {
1555 if (input.length > peg$currPos) {
1556 s5 = input.charAt(peg$currPos);
1560 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1562 if (s5 !== peg$FAILED) {
1564 s4 = peg$c53(s4, s5);
1576 if (s2 !== peg$FAILED) {
1577 if (input.charCodeAt(peg$currPos) === 39) {
1582 if (peg$silentFails === 0) { peg$fail(peg$c56); }
1584 if (s3 !== peg$FAILED) {
1602 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1607 function peg$parsenumber() {
1610 var key = peg$currPos * 30 + 16,
1611 cached = peg$resultsCache[key];
1614 peg$currPos = cached.nextPos;
1616 return cached.result;
1622 if (peg$c59.test(input.charAt(peg$currPos))) {
1623 s3 = input.charAt(peg$currPos);
1627 if (peg$silentFails === 0) { peg$fail(peg$c60); }
1629 while (s3 !== peg$FAILED) {
1631 if (peg$c59.test(input.charAt(peg$currPos))) {
1632 s3 = input.charAt(peg$currPos);
1636 if (peg$silentFails === 0) { peg$fail(peg$c60); }
1639 if (s2 !== peg$FAILED) {
1640 if (input.charCodeAt(peg$currPos) === 46) {
1645 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1647 if (s3 !== peg$FAILED) {
1658 if (s1 === peg$FAILED) {
1661 if (s1 !== peg$FAILED) {
1663 if (peg$c59.test(input.charAt(peg$currPos))) {
1664 s3 = input.charAt(peg$currPos);
1668 if (peg$silentFails === 0) { peg$fail(peg$c60); }
1670 if (s3 !== peg$FAILED) {
1671 while (s3 !== peg$FAILED) {
1673 if (peg$c59.test(input.charAt(peg$currPos))) {
1674 s3 = input.charAt(peg$currPos);
1678 if (peg$silentFails === 0) { peg$fail(peg$c60); }
1684 if (s2 !== peg$FAILED) {
1686 s1 = peg$c61(s1, s2);
1697 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1702 function peg$parsepath() {
1705 var key = peg$currPos * 30 + 17,
1706 cached = peg$resultsCache[key];
1709 peg$currPos = cached.nextPos;
1711 return cached.result;
1715 s1 = peg$parseidentifierName();
1716 if (s1 !== peg$FAILED) {
1722 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1727 function peg$parsetype() {
1728 var s0, s1, s2, s3, s4, s5;
1730 var key = peg$currPos * 30 + 18,
1731 cached = peg$resultsCache[key];
1734 peg$currPos = cached.nextPos;
1736 return cached.result;
1740 if (input.substr(peg$currPos, 5) === peg$c63) {
1745 if (peg$silentFails === 0) { peg$fail(peg$c64); }
1747 if (s1 !== peg$FAILED) {
1749 if (s2 !== peg$FAILED) {
1751 if (peg$c65.test(input.charAt(peg$currPos))) {
1752 s4 = input.charAt(peg$currPos);
1756 if (peg$silentFails === 0) { peg$fail(peg$c66); }
1758 if (s4 !== peg$FAILED) {
1759 while (s4 !== peg$FAILED) {
1761 if (peg$c65.test(input.charAt(peg$currPos))) {
1762 s4 = input.charAt(peg$currPos);
1766 if (peg$silentFails === 0) { peg$fail(peg$c66); }
1772 if (s3 !== peg$FAILED) {
1774 if (s4 !== peg$FAILED) {
1775 if (input.charCodeAt(peg$currPos) === 41) {
1780 if (peg$silentFails === 0) { peg$fail(peg$c68); }
1782 if (s5 !== peg$FAILED) {
1807 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1812 function peg$parseflags() {
1815 var key = peg$currPos * 30 + 19,
1816 cached = peg$resultsCache[key];
1819 peg$currPos = cached.nextPos;
1821 return cached.result;
1825 if (peg$c70.test(input.charAt(peg$currPos))) {
1826 s1 = input.charAt(peg$currPos);
1830 if (peg$silentFails === 0) { peg$fail(peg$c71); }
1832 if (s1 !== peg$FAILED) {
1833 while (s1 !== peg$FAILED) {
1835 if (peg$c70.test(input.charAt(peg$currPos))) {
1836 s1 = input.charAt(peg$currPos);
1840 if (peg$silentFails === 0) { peg$fail(peg$c71); }
1847 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1852 function peg$parseregex() {
1853 var s0, s1, s2, s3, s4;
1855 var key = peg$currPos * 30 + 20,
1856 cached = peg$resultsCache[key];
1859 peg$currPos = cached.nextPos;
1861 return cached.result;
1865 if (input.charCodeAt(peg$currPos) === 47) {
1870 if (peg$silentFails === 0) { peg$fail(peg$c73); }
1872 if (s1 !== peg$FAILED) {
1874 if (peg$c74.test(input.charAt(peg$currPos))) {
1875 s3 = input.charAt(peg$currPos);
1879 if (peg$silentFails === 0) { peg$fail(peg$c75); }
1881 if (s3 !== peg$FAILED) {
1882 while (s3 !== peg$FAILED) {
1884 if (peg$c74.test(input.charAt(peg$currPos))) {
1885 s3 = input.charAt(peg$currPos);
1889 if (peg$silentFails === 0) { peg$fail(peg$c75); }
1895 if (s2 !== peg$FAILED) {
1896 if (input.charCodeAt(peg$currPos) === 47) {
1901 if (peg$silentFails === 0) { peg$fail(peg$c73); }
1903 if (s3 !== peg$FAILED) {
1904 s4 = peg$parseflags();
1905 if (s4 === peg$FAILED) {
1908 if (s4 !== peg$FAILED) {
1910 s1 = peg$c76(s2, s4);
1929 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1934 function peg$parsefield() {
1935 var s0, s1, s2, s3, s4, s5, s6;
1937 var key = peg$currPos * 30 + 21,
1938 cached = peg$resultsCache[key];
1941 peg$currPos = cached.nextPos;
1943 return cached.result;
1947 if (input.charCodeAt(peg$currPos) === 46) {
1952 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1954 if (s1 !== peg$FAILED) {
1955 s2 = peg$parseidentifierName();
1956 if (s2 !== peg$FAILED) {
1959 if (input.charCodeAt(peg$currPos) === 46) {
1964 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1966 if (s5 !== peg$FAILED) {
1967 s6 = peg$parseidentifierName();
1968 if (s6 !== peg$FAILED) {
1979 while (s4 !== peg$FAILED) {
1982 if (input.charCodeAt(peg$currPos) === 46) {
1987 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1989 if (s5 !== peg$FAILED) {
1990 s6 = peg$parseidentifierName();
1991 if (s6 !== peg$FAILED) {
2003 if (s3 !== peg$FAILED) {
2005 s1 = peg$c77(s2, s3);
2020 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2025 function peg$parsenegation() {
2026 var s0, s1, s2, s3, s4, s5;
2028 var key = peg$currPos * 30 + 22,
2029 cached = peg$resultsCache[key];
2032 peg$currPos = cached.nextPos;
2034 return cached.result;
2038 if (input.substr(peg$currPos, 5) === peg$c78) {
2043 if (peg$silentFails === 0) { peg$fail(peg$c79); }
2045 if (s1 !== peg$FAILED) {
2047 if (s2 !== peg$FAILED) {
2048 s3 = peg$parseselectors();
2049 if (s3 !== peg$FAILED) {
2051 if (s4 !== peg$FAILED) {
2052 if (input.charCodeAt(peg$currPos) === 41) {
2057 if (peg$silentFails === 0) { peg$fail(peg$c68); }
2059 if (s5 !== peg$FAILED) {
2084 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2089 function peg$parsematches() {
2090 var s0, s1, s2, s3, s4, s5;
2092 var key = peg$currPos * 30 + 23,
2093 cached = peg$resultsCache[key];
2096 peg$currPos = cached.nextPos;
2098 return cached.result;
2102 if (input.substr(peg$currPos, 9) === peg$c81) {
2107 if (peg$silentFails === 0) { peg$fail(peg$c82); }
2109 if (s1 !== peg$FAILED) {
2111 if (s2 !== peg$FAILED) {
2112 s3 = peg$parseselectors();
2113 if (s3 !== peg$FAILED) {
2115 if (s4 !== peg$FAILED) {
2116 if (input.charCodeAt(peg$currPos) === 41) {
2121 if (peg$silentFails === 0) { peg$fail(peg$c68); }
2123 if (s5 !== peg$FAILED) {
2148 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2153 function peg$parsehas() {
2154 var s0, s1, s2, s3, s4, s5;
2156 var key = peg$currPos * 30 + 24,
2157 cached = peg$resultsCache[key];
2160 peg$currPos = cached.nextPos;
2162 return cached.result;
2166 if (input.substr(peg$currPos, 5) === peg$c84) {
2171 if (peg$silentFails === 0) { peg$fail(peg$c85); }
2173 if (s1 !== peg$FAILED) {
2175 if (s2 !== peg$FAILED) {
2176 s3 = peg$parseselectors();
2177 if (s3 !== peg$FAILED) {
2179 if (s4 !== peg$FAILED) {
2180 if (input.charCodeAt(peg$currPos) === 41) {
2185 if (peg$silentFails === 0) { peg$fail(peg$c68); }
2187 if (s5 !== peg$FAILED) {
2212 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2217 function peg$parsefirstChild() {
2220 var key = peg$currPos * 30 + 25,
2221 cached = peg$resultsCache[key];
2224 peg$currPos = cached.nextPos;
2226 return cached.result;
2230 if (input.substr(peg$currPos, 12) === peg$c87) {
2235 if (peg$silentFails === 0) { peg$fail(peg$c88); }
2237 if (s1 !== peg$FAILED) {
2243 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2248 function peg$parselastChild() {
2251 var key = peg$currPos * 30 + 26,
2252 cached = peg$resultsCache[key];
2255 peg$currPos = cached.nextPos;
2257 return cached.result;
2261 if (input.substr(peg$currPos, 11) === peg$c90) {
2266 if (peg$silentFails === 0) { peg$fail(peg$c91); }
2268 if (s1 !== peg$FAILED) {
2274 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2279 function peg$parsenthChild() {
2280 var s0, s1, s2, s3, s4, s5;
2282 var key = peg$currPos * 30 + 27,
2283 cached = peg$resultsCache[key];
2286 peg$currPos = cached.nextPos;
2288 return cached.result;
2292 if (input.substr(peg$currPos, 11) === peg$c93) {
2297 if (peg$silentFails === 0) { peg$fail(peg$c94); }
2299 if (s1 !== peg$FAILED) {
2301 if (s2 !== peg$FAILED) {
2303 if (peg$c59.test(input.charAt(peg$currPos))) {
2304 s4 = input.charAt(peg$currPos);
2308 if (peg$silentFails === 0) { peg$fail(peg$c60); }
2310 if (s4 !== peg$FAILED) {
2311 while (s4 !== peg$FAILED) {
2313 if (peg$c59.test(input.charAt(peg$currPos))) {
2314 s4 = input.charAt(peg$currPos);
2318 if (peg$silentFails === 0) { peg$fail(peg$c60); }
2324 if (s3 !== peg$FAILED) {
2326 if (s4 !== peg$FAILED) {
2327 if (input.charCodeAt(peg$currPos) === 41) {
2332 if (peg$silentFails === 0) { peg$fail(peg$c68); }
2334 if (s5 !== peg$FAILED) {
2359 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2364 function peg$parsenthLastChild() {
2365 var s0, s1, s2, s3, s4, s5;
2367 var key = peg$currPos * 30 + 28,
2368 cached = peg$resultsCache[key];
2371 peg$currPos = cached.nextPos;
2373 return cached.result;
2377 if (input.substr(peg$currPos, 16) === peg$c96) {
2382 if (peg$silentFails === 0) { peg$fail(peg$c97); }
2384 if (s1 !== peg$FAILED) {
2386 if (s2 !== peg$FAILED) {
2388 if (peg$c59.test(input.charAt(peg$currPos))) {
2389 s4 = input.charAt(peg$currPos);
2393 if (peg$silentFails === 0) { peg$fail(peg$c60); }
2395 if (s4 !== peg$FAILED) {
2396 while (s4 !== peg$FAILED) {
2398 if (peg$c59.test(input.charAt(peg$currPos))) {
2399 s4 = input.charAt(peg$currPos);
2403 if (peg$silentFails === 0) { peg$fail(peg$c60); }
2409 if (s3 !== peg$FAILED) {
2411 if (s4 !== peg$FAILED) {
2412 if (input.charCodeAt(peg$currPos) === 41) {
2417 if (peg$silentFails === 0) { peg$fail(peg$c68); }
2419 if (s5 !== peg$FAILED) {
2444 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2449 function peg$parseclass() {
2452 var key = peg$currPos * 30 + 29,
2453 cached = peg$resultsCache[key];
2456 peg$currPos = cached.nextPos;
2458 return cached.result;
2462 if (input.charCodeAt(peg$currPos) === 58) {
2467 if (peg$silentFails === 0) { peg$fail(peg$c100); }
2469 if (s1 !== peg$FAILED) {
2470 if (input.substr(peg$currPos, 9).toLowerCase() === peg$c101) {
2471 s2 = input.substr(peg$currPos, 9);
2475 if (peg$silentFails === 0) { peg$fail(peg$c102); }
2477 if (s2 === peg$FAILED) {
2478 if (input.substr(peg$currPos, 10).toLowerCase() === peg$c103) {
2479 s2 = input.substr(peg$currPos, 10);
2483 if (peg$silentFails === 0) { peg$fail(peg$c104); }
2485 if (s2 === peg$FAILED) {
2486 if (input.substr(peg$currPos, 11).toLowerCase() === peg$c105) {
2487 s2 = input.substr(peg$currPos, 11);
2491 if (peg$silentFails === 0) { peg$fail(peg$c106); }
2493 if (s2 === peg$FAILED) {
2494 if (input.substr(peg$currPos, 8).toLowerCase() === peg$c107) {
2495 s2 = input.substr(peg$currPos, 8);
2499 if (peg$silentFails === 0) { peg$fail(peg$c108); }
2501 if (s2 === peg$FAILED) {
2502 if (input.substr(peg$currPos, 7).toLowerCase() === peg$c109) {
2503 s2 = input.substr(peg$currPos, 7);
2507 if (peg$silentFails === 0) { peg$fail(peg$c110); }
2513 if (s2 !== peg$FAILED) {
2526 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2532 function nth(n) { return { type: 'nth-child', index: { type: 'literal', value: n } }; }
2533 function nthLast(n) { return { type: 'nth-last-child', index: { type: 'literal', value: n } }; }
2534 function strUnescape(s) {
2535 return s.replace(/\\(.)/g, function(match, ch) {
2537 case 'b': return '\b';
2538 case 'f': return '\f';
2539 case 'n': return '\n';
2540 case 'r': return '\r';
2541 case 't': return '\t';
2542 case 'v': return '\v';
2549 peg$result = peg$startRuleFunction();
2551 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
2554 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
2555 peg$fail(peg$endExpectation());
2558 throw peg$buildStructuredError(
2559 peg$maxFailExpected,
2560 peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
2561 peg$maxFailPos < input.length
2562 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
2563 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
2569 SyntaxError: peg$SyntaxError,