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(a, as) {
207 return [].concat.apply([a], as).join('');
209 peg$c45 = function(name, op, value) {
210 return { type: 'attribute', name: name, operator: op, value: value };
212 peg$c46 = function(name) { return { type: 'attribute', name: name }; },
214 peg$c48 = peg$literalExpectation("\"", false),
216 peg$c50 = peg$classExpectation(["\\", "\""], true, false),
218 peg$c52 = peg$literalExpectation("\\", false),
219 peg$c53 = peg$anyExpectation(),
220 peg$c54 = function(a, b) { return a + b; },
221 peg$c55 = function(d) {
222 return { type: 'literal', value: strUnescape(d.join('')) };
225 peg$c57 = peg$literalExpectation("'", false),
227 peg$c59 = peg$classExpectation(["\\", "'"], true, false),
229 peg$c61 = peg$classExpectation([["0", "9"]], false, false),
230 peg$c62 = function(a, b) {
231 // Can use `a.flat().join('')` once supported
232 const leadingDecimals = a ? [].concat.apply([], a).join('') : '';
233 return { type: 'literal', value: parseFloat(leadingDecimals + b.join('')) };
235 peg$c63 = function(i) { return { type: 'literal', value: i }; },
237 peg$c65 = peg$literalExpectation("type(", false),
239 peg$c67 = peg$classExpectation([" ", ")"], true, false),
241 peg$c69 = peg$literalExpectation(")", false),
242 peg$c70 = function(t) { return { type: 'type', value: t.join('') }; },
244 peg$c72 = peg$classExpectation(["i", "m", "s", "u"], false, false),
246 peg$c74 = peg$literalExpectation("/", false),
248 peg$c76 = peg$classExpectation(["/"], true, false),
249 peg$c77 = function(d, flgs) { return {
250 type: 'regexp', value: new RegExp(d.join(''), flgs ? flgs.join('') : '') };
252 peg$c78 = function(i, is) {
253 return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)};
256 peg$c80 = peg$literalExpectation(":not(", false),
257 peg$c81 = function(ss) { return { type: 'not', selectors: ss }; },
258 peg$c82 = ":matches(",
259 peg$c83 = peg$literalExpectation(":matches(", false),
260 peg$c84 = function(ss) { return { type: 'matches', selectors: ss }; },
262 peg$c86 = peg$literalExpectation(":has(", false),
263 peg$c87 = function(ss) { return { type: 'has', selectors: ss }; },
264 peg$c88 = ":first-child",
265 peg$c89 = peg$literalExpectation(":first-child", false),
266 peg$c90 = function() { return nth(1); },
267 peg$c91 = ":last-child",
268 peg$c92 = peg$literalExpectation(":last-child", false),
269 peg$c93 = function() { return nthLast(1); },
270 peg$c94 = ":nth-child(",
271 peg$c95 = peg$literalExpectation(":nth-child(", false),
272 peg$c96 = function(n) { return nth(parseInt(n.join(''), 10)); },
273 peg$c97 = ":nth-last-child(",
274 peg$c98 = peg$literalExpectation(":nth-last-child(", false),
275 peg$c99 = function(n) { return nthLast(parseInt(n.join(''), 10)); },
277 peg$c101 = peg$literalExpectation(":", false),
278 peg$c102 = "statement",
279 peg$c103 = peg$literalExpectation("statement", true),
280 peg$c104 = "expression",
281 peg$c105 = peg$literalExpectation("expression", true),
282 peg$c106 = "declaration",
283 peg$c107 = peg$literalExpectation("declaration", true),
284 peg$c108 = "function",
285 peg$c109 = peg$literalExpectation("function", true),
286 peg$c110 = "pattern",
287 peg$c111 = peg$literalExpectation("pattern", true),
288 peg$c112 = function(c) {
289 return { type: 'class', name: c };
294 peg$posDetailsCache = [{ line: 1, column: 1 }],
296 peg$maxFailExpected = [],
299 peg$resultsCache = {},
303 if ("startRule" in options) {
304 if (!(options.startRule in peg$startRuleFunctions)) {
305 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
308 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
312 return input.substring(peg$savedPos, peg$currPos);
315 function location() {
316 return peg$computeLocation(peg$savedPos, peg$currPos);
319 function expected(description, location) {
320 location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
322 throw peg$buildStructuredError(
323 [peg$otherExpectation(description)],
324 input.substring(peg$savedPos, peg$currPos),
329 function error(message, location) {
330 location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
332 throw peg$buildSimpleError(message, location);
335 function peg$literalExpectation(text, ignoreCase) {
336 return { type: "literal", text: text, ignoreCase: ignoreCase };
339 function peg$classExpectation(parts, inverted, ignoreCase) {
340 return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
343 function peg$anyExpectation() {
344 return { type: "any" };
347 function peg$endExpectation() {
348 return { type: "end" };
351 function peg$otherExpectation(description) {
352 return { type: "other", description: description };
355 function peg$computePosDetails(pos) {
356 var details = peg$posDetailsCache[pos], p;
362 while (!peg$posDetailsCache[p]) {
366 details = peg$posDetailsCache[p];
369 column: details.column
373 if (input.charCodeAt(p) === 10) {
383 peg$posDetailsCache[pos] = details;
388 function peg$computeLocation(startPos, endPos) {
389 var startPosDetails = peg$computePosDetails(startPos),
390 endPosDetails = peg$computePosDetails(endPos);
395 line: startPosDetails.line,
396 column: startPosDetails.column
400 line: endPosDetails.line,
401 column: endPosDetails.column
406 function peg$fail(expected) {
407 if (peg$currPos < peg$maxFailPos) { return; }
409 if (peg$currPos > peg$maxFailPos) {
410 peg$maxFailPos = peg$currPos;
411 peg$maxFailExpected = [];
414 peg$maxFailExpected.push(expected);
417 function peg$buildSimpleError(message, location) {
418 return new peg$SyntaxError(message, null, null, location);
421 function peg$buildStructuredError(expected, found, location) {
422 return new peg$SyntaxError(
423 peg$SyntaxError.buildMessage(expected, found),
430 function peg$parsestart() {
433 var key = peg$currPos * 30 + 0,
434 cached = peg$resultsCache[key];
437 peg$currPos = cached.nextPos;
439 return cached.result;
444 if (s1 !== peg$FAILED) {
445 s2 = peg$parseselectors();
446 if (s2 !== peg$FAILED) {
448 if (s3 !== peg$FAILED) {
464 if (s0 === peg$FAILED) {
467 if (s1 !== peg$FAILED) {
474 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
479 function peg$parse_() {
482 var key = peg$currPos * 30 + 1,
483 cached = peg$resultsCache[key];
486 peg$currPos = cached.nextPos;
488 return cached.result;
492 if (input.charCodeAt(peg$currPos) === 32) {
497 if (peg$silentFails === 0) { peg$fail(peg$c3); }
499 while (s1 !== peg$FAILED) {
501 if (input.charCodeAt(peg$currPos) === 32) {
506 if (peg$silentFails === 0) { peg$fail(peg$c3); }
510 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
515 function peg$parseidentifierName() {
518 var key = peg$currPos * 30 + 2,
519 cached = peg$resultsCache[key];
522 peg$currPos = cached.nextPos;
524 return cached.result;
529 if (peg$c4.test(input.charAt(peg$currPos))) {
530 s2 = input.charAt(peg$currPos);
534 if (peg$silentFails === 0) { peg$fail(peg$c5); }
536 if (s2 !== peg$FAILED) {
537 while (s2 !== peg$FAILED) {
539 if (peg$c4.test(input.charAt(peg$currPos))) {
540 s2 = input.charAt(peg$currPos);
544 if (peg$silentFails === 0) { peg$fail(peg$c5); }
550 if (s1 !== peg$FAILED) {
556 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
561 function peg$parsebinaryOp() {
564 var key = peg$currPos * 30 + 3,
565 cached = peg$resultsCache[key];
568 peg$currPos = cached.nextPos;
570 return cached.result;
575 if (s1 !== peg$FAILED) {
576 if (input.charCodeAt(peg$currPos) === 62) {
581 if (peg$silentFails === 0) { peg$fail(peg$c8); }
583 if (s2 !== peg$FAILED) {
585 if (s3 !== peg$FAILED) {
601 if (s0 === peg$FAILED) {
604 if (s1 !== peg$FAILED) {
605 if (input.charCodeAt(peg$currPos) === 126) {
610 if (peg$silentFails === 0) { peg$fail(peg$c11); }
612 if (s2 !== peg$FAILED) {
614 if (s3 !== peg$FAILED) {
630 if (s0 === peg$FAILED) {
633 if (s1 !== peg$FAILED) {
634 if (input.charCodeAt(peg$currPos) === 43) {
639 if (peg$silentFails === 0) { peg$fail(peg$c14); }
641 if (s2 !== peg$FAILED) {
643 if (s3 !== peg$FAILED) {
659 if (s0 === peg$FAILED) {
661 if (input.charCodeAt(peg$currPos) === 32) {
666 if (peg$silentFails === 0) { peg$fail(peg$c3); }
668 if (s1 !== peg$FAILED) {
670 if (s2 !== peg$FAILED) {
686 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
691 function peg$parseselectors() {
692 var s0, s1, s2, s3, s4, s5, s6, s7;
694 var key = peg$currPos * 30 + 4,
695 cached = peg$resultsCache[key];
698 peg$currPos = cached.nextPos;
700 return cached.result;
704 s1 = peg$parseselector();
705 if (s1 !== peg$FAILED) {
709 if (s4 !== peg$FAILED) {
710 if (input.charCodeAt(peg$currPos) === 44) {
715 if (peg$silentFails === 0) { peg$fail(peg$c18); }
717 if (s5 !== peg$FAILED) {
719 if (s6 !== peg$FAILED) {
720 s7 = peg$parseselector();
721 if (s7 !== peg$FAILED) {
722 s4 = [s4, s5, s6, s7];
740 while (s3 !== peg$FAILED) {
744 if (s4 !== peg$FAILED) {
745 if (input.charCodeAt(peg$currPos) === 44) {
750 if (peg$silentFails === 0) { peg$fail(peg$c18); }
752 if (s5 !== peg$FAILED) {
754 if (s6 !== peg$FAILED) {
755 s7 = peg$parseselector();
756 if (s7 !== peg$FAILED) {
757 s4 = [s4, s5, s6, s7];
776 if (s2 !== peg$FAILED) {
778 s1 = peg$c19(s1, s2);
789 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
794 function peg$parseselector() {
795 var s0, s1, s2, s3, s4, s5;
797 var key = peg$currPos * 30 + 5,
798 cached = peg$resultsCache[key];
801 peg$currPos = cached.nextPos;
803 return cached.result;
807 s1 = peg$parsesequence();
808 if (s1 !== peg$FAILED) {
811 s4 = peg$parsebinaryOp();
812 if (s4 !== peg$FAILED) {
813 s5 = peg$parsesequence();
814 if (s5 !== peg$FAILED) {
825 while (s3 !== peg$FAILED) {
828 s4 = peg$parsebinaryOp();
829 if (s4 !== peg$FAILED) {
830 s5 = peg$parsesequence();
831 if (s5 !== peg$FAILED) {
843 if (s2 !== peg$FAILED) {
845 s1 = peg$c20(s1, s2);
856 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
861 function peg$parsesequence() {
864 var key = peg$currPos * 30 + 6,
865 cached = peg$resultsCache[key];
868 peg$currPos = cached.nextPos;
870 return cached.result;
874 if (input.charCodeAt(peg$currPos) === 33) {
879 if (peg$silentFails === 0) { peg$fail(peg$c22); }
881 if (s1 === peg$FAILED) {
884 if (s1 !== peg$FAILED) {
886 s3 = peg$parseatom();
887 if (s3 !== peg$FAILED) {
888 while (s3 !== peg$FAILED) {
890 s3 = peg$parseatom();
895 if (s2 !== peg$FAILED) {
897 s1 = peg$c23(s1, s2);
908 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
913 function peg$parseatom() {
916 var key = peg$currPos * 30 + 7,
917 cached = peg$resultsCache[key];
920 peg$currPos = cached.nextPos;
922 return cached.result;
925 s0 = peg$parsewildcard();
926 if (s0 === peg$FAILED) {
927 s0 = peg$parseidentifier();
928 if (s0 === peg$FAILED) {
929 s0 = peg$parseattr();
930 if (s0 === peg$FAILED) {
931 s0 = peg$parsefield();
932 if (s0 === peg$FAILED) {
933 s0 = peg$parsenegation();
934 if (s0 === peg$FAILED) {
935 s0 = peg$parsematches();
936 if (s0 === peg$FAILED) {
938 if (s0 === peg$FAILED) {
939 s0 = peg$parsefirstChild();
940 if (s0 === peg$FAILED) {
941 s0 = peg$parselastChild();
942 if (s0 === peg$FAILED) {
943 s0 = peg$parsenthChild();
944 if (s0 === peg$FAILED) {
945 s0 = peg$parsenthLastChild();
946 if (s0 === peg$FAILED) {
947 s0 = peg$parseclass();
960 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
965 function peg$parsewildcard() {
968 var key = peg$currPos * 30 + 8,
969 cached = peg$resultsCache[key];
972 peg$currPos = cached.nextPos;
974 return cached.result;
978 if (input.charCodeAt(peg$currPos) === 42) {
983 if (peg$silentFails === 0) { peg$fail(peg$c25); }
985 if (s1 !== peg$FAILED) {
991 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
996 function peg$parseidentifier() {
999 var key = peg$currPos * 30 + 9,
1000 cached = peg$resultsCache[key];
1003 peg$currPos = cached.nextPos;
1005 return cached.result;
1009 if (input.charCodeAt(peg$currPos) === 35) {
1014 if (peg$silentFails === 0) { peg$fail(peg$c28); }
1016 if (s1 === peg$FAILED) {
1019 if (s1 !== peg$FAILED) {
1020 s2 = peg$parseidentifierName();
1021 if (s2 !== peg$FAILED) {
1034 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1039 function peg$parseattr() {
1040 var s0, s1, s2, s3, s4, s5;
1042 var key = peg$currPos * 30 + 10,
1043 cached = peg$resultsCache[key];
1046 peg$currPos = cached.nextPos;
1048 return cached.result;
1052 if (input.charCodeAt(peg$currPos) === 91) {
1057 if (peg$silentFails === 0) { peg$fail(peg$c31); }
1059 if (s1 !== peg$FAILED) {
1061 if (s2 !== peg$FAILED) {
1062 s3 = peg$parseattrValue();
1063 if (s3 !== peg$FAILED) {
1065 if (s4 !== peg$FAILED) {
1066 if (input.charCodeAt(peg$currPos) === 93) {
1071 if (peg$silentFails === 0) { peg$fail(peg$c33); }
1073 if (s5 !== peg$FAILED) {
1098 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1103 function peg$parseattrOps() {
1106 var key = peg$currPos * 30 + 11,
1107 cached = peg$resultsCache[key];
1110 peg$currPos = cached.nextPos;
1112 return cached.result;
1116 if (peg$c35.test(input.charAt(peg$currPos))) {
1117 s1 = input.charAt(peg$currPos);
1121 if (peg$silentFails === 0) { peg$fail(peg$c36); }
1123 if (s1 === peg$FAILED) {
1126 if (s1 !== peg$FAILED) {
1127 if (input.charCodeAt(peg$currPos) === 61) {
1132 if (peg$silentFails === 0) { peg$fail(peg$c38); }
1134 if (s2 !== peg$FAILED) {
1146 if (s0 === peg$FAILED) {
1147 if (peg$c40.test(input.charAt(peg$currPos))) {
1148 s0 = input.charAt(peg$currPos);
1152 if (peg$silentFails === 0) { peg$fail(peg$c41); }
1156 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1161 function peg$parseattrEqOps() {
1164 var key = peg$currPos * 30 + 12,
1165 cached = peg$resultsCache[key];
1168 peg$currPos = cached.nextPos;
1170 return cached.result;
1174 if (input.charCodeAt(peg$currPos) === 33) {
1179 if (peg$silentFails === 0) { peg$fail(peg$c22); }
1181 if (s1 === peg$FAILED) {
1184 if (s1 !== peg$FAILED) {
1185 if (input.charCodeAt(peg$currPos) === 61) {
1190 if (peg$silentFails === 0) { peg$fail(peg$c38); }
1192 if (s2 !== peg$FAILED) {
1205 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1210 function peg$parseattrName() {
1211 var s0, s1, s2, s3, s4, s5;
1213 var key = peg$currPos * 30 + 13,
1214 cached = peg$resultsCache[key];
1217 peg$currPos = cached.nextPos;
1219 return cached.result;
1223 s1 = peg$parseidentifierName();
1224 if (s1 !== peg$FAILED) {
1227 if (input.charCodeAt(peg$currPos) === 46) {
1232 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1234 if (s4 !== peg$FAILED) {
1235 s5 = peg$parseidentifierName();
1236 if (s5 !== peg$FAILED) {
1247 while (s3 !== peg$FAILED) {
1250 if (input.charCodeAt(peg$currPos) === 46) {
1255 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1257 if (s4 !== peg$FAILED) {
1258 s5 = peg$parseidentifierName();
1259 if (s5 !== peg$FAILED) {
1271 if (s2 !== peg$FAILED) {
1273 s1 = peg$c44(s1, s2);
1284 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1289 function peg$parseattrValue() {
1290 var s0, s1, s2, s3, s4, s5;
1292 var key = peg$currPos * 30 + 14,
1293 cached = peg$resultsCache[key];
1296 peg$currPos = cached.nextPos;
1298 return cached.result;
1302 s1 = peg$parseattrName();
1303 if (s1 !== peg$FAILED) {
1305 if (s2 !== peg$FAILED) {
1306 s3 = peg$parseattrEqOps();
1307 if (s3 !== peg$FAILED) {
1309 if (s4 !== peg$FAILED) {
1310 s5 = peg$parsetype();
1311 if (s5 === peg$FAILED) {
1312 s5 = peg$parseregex();
1314 if (s5 !== peg$FAILED) {
1316 s1 = peg$c45(s1, s3, s5);
1338 if (s0 === peg$FAILED) {
1340 s1 = peg$parseattrName();
1341 if (s1 !== peg$FAILED) {
1343 if (s2 !== peg$FAILED) {
1344 s3 = peg$parseattrOps();
1345 if (s3 !== peg$FAILED) {
1347 if (s4 !== peg$FAILED) {
1348 s5 = peg$parsestring();
1349 if (s5 === peg$FAILED) {
1350 s5 = peg$parsenumber();
1351 if (s5 === peg$FAILED) {
1352 s5 = peg$parsepath();
1355 if (s5 !== peg$FAILED) {
1357 s1 = peg$c45(s1, s3, s5);
1379 if (s0 === peg$FAILED) {
1381 s1 = peg$parseattrName();
1382 if (s1 !== peg$FAILED) {
1390 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1395 function peg$parsestring() {
1396 var s0, s1, s2, s3, s4, s5;
1398 var key = peg$currPos * 30 + 15,
1399 cached = peg$resultsCache[key];
1402 peg$currPos = cached.nextPos;
1404 return cached.result;
1408 if (input.charCodeAt(peg$currPos) === 34) {
1413 if (peg$silentFails === 0) { peg$fail(peg$c48); }
1415 if (s1 !== peg$FAILED) {
1417 if (peg$c49.test(input.charAt(peg$currPos))) {
1418 s3 = input.charAt(peg$currPos);
1422 if (peg$silentFails === 0) { peg$fail(peg$c50); }
1424 if (s3 === peg$FAILED) {
1426 if (input.charCodeAt(peg$currPos) === 92) {
1431 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1433 if (s4 !== peg$FAILED) {
1434 if (input.length > peg$currPos) {
1435 s5 = input.charAt(peg$currPos);
1439 if (peg$silentFails === 0) { peg$fail(peg$c53); }
1441 if (s5 !== peg$FAILED) {
1443 s4 = peg$c54(s4, s5);
1454 while (s3 !== peg$FAILED) {
1456 if (peg$c49.test(input.charAt(peg$currPos))) {
1457 s3 = input.charAt(peg$currPos);
1461 if (peg$silentFails === 0) { peg$fail(peg$c50); }
1463 if (s3 === peg$FAILED) {
1465 if (input.charCodeAt(peg$currPos) === 92) {
1470 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1472 if (s4 !== peg$FAILED) {
1473 if (input.length > peg$currPos) {
1474 s5 = input.charAt(peg$currPos);
1478 if (peg$silentFails === 0) { peg$fail(peg$c53); }
1480 if (s5 !== peg$FAILED) {
1482 s4 = peg$c54(s4, s5);
1494 if (s2 !== peg$FAILED) {
1495 if (input.charCodeAt(peg$currPos) === 34) {
1500 if (peg$silentFails === 0) { peg$fail(peg$c48); }
1502 if (s3 !== peg$FAILED) {
1518 if (s0 === peg$FAILED) {
1520 if (input.charCodeAt(peg$currPos) === 39) {
1525 if (peg$silentFails === 0) { peg$fail(peg$c57); }
1527 if (s1 !== peg$FAILED) {
1529 if (peg$c58.test(input.charAt(peg$currPos))) {
1530 s3 = input.charAt(peg$currPos);
1534 if (peg$silentFails === 0) { peg$fail(peg$c59); }
1536 if (s3 === peg$FAILED) {
1538 if (input.charCodeAt(peg$currPos) === 92) {
1543 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1545 if (s4 !== peg$FAILED) {
1546 if (input.length > peg$currPos) {
1547 s5 = input.charAt(peg$currPos);
1551 if (peg$silentFails === 0) { peg$fail(peg$c53); }
1553 if (s5 !== peg$FAILED) {
1555 s4 = peg$c54(s4, s5);
1566 while (s3 !== peg$FAILED) {
1568 if (peg$c58.test(input.charAt(peg$currPos))) {
1569 s3 = input.charAt(peg$currPos);
1573 if (peg$silentFails === 0) { peg$fail(peg$c59); }
1575 if (s3 === peg$FAILED) {
1577 if (input.charCodeAt(peg$currPos) === 92) {
1582 if (peg$silentFails === 0) { peg$fail(peg$c52); }
1584 if (s4 !== peg$FAILED) {
1585 if (input.length > peg$currPos) {
1586 s5 = input.charAt(peg$currPos);
1590 if (peg$silentFails === 0) { peg$fail(peg$c53); }
1592 if (s5 !== peg$FAILED) {
1594 s4 = peg$c54(s4, s5);
1606 if (s2 !== peg$FAILED) {
1607 if (input.charCodeAt(peg$currPos) === 39) {
1612 if (peg$silentFails === 0) { peg$fail(peg$c57); }
1614 if (s3 !== peg$FAILED) {
1632 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1637 function peg$parsenumber() {
1640 var key = peg$currPos * 30 + 16,
1641 cached = peg$resultsCache[key];
1644 peg$currPos = cached.nextPos;
1646 return cached.result;
1652 if (peg$c60.test(input.charAt(peg$currPos))) {
1653 s3 = input.charAt(peg$currPos);
1657 if (peg$silentFails === 0) { peg$fail(peg$c61); }
1659 while (s3 !== peg$FAILED) {
1661 if (peg$c60.test(input.charAt(peg$currPos))) {
1662 s3 = input.charAt(peg$currPos);
1666 if (peg$silentFails === 0) { peg$fail(peg$c61); }
1669 if (s2 !== peg$FAILED) {
1670 if (input.charCodeAt(peg$currPos) === 46) {
1675 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1677 if (s3 !== peg$FAILED) {
1688 if (s1 === peg$FAILED) {
1691 if (s1 !== peg$FAILED) {
1693 if (peg$c60.test(input.charAt(peg$currPos))) {
1694 s3 = input.charAt(peg$currPos);
1698 if (peg$silentFails === 0) { peg$fail(peg$c61); }
1700 if (s3 !== peg$FAILED) {
1701 while (s3 !== peg$FAILED) {
1703 if (peg$c60.test(input.charAt(peg$currPos))) {
1704 s3 = input.charAt(peg$currPos);
1708 if (peg$silentFails === 0) { peg$fail(peg$c61); }
1714 if (s2 !== peg$FAILED) {
1716 s1 = peg$c62(s1, s2);
1727 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1732 function peg$parsepath() {
1735 var key = peg$currPos * 30 + 17,
1736 cached = peg$resultsCache[key];
1739 peg$currPos = cached.nextPos;
1741 return cached.result;
1745 s1 = peg$parseidentifierName();
1746 if (s1 !== peg$FAILED) {
1752 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1757 function peg$parsetype() {
1758 var s0, s1, s2, s3, s4, s5;
1760 var key = peg$currPos * 30 + 18,
1761 cached = peg$resultsCache[key];
1764 peg$currPos = cached.nextPos;
1766 return cached.result;
1770 if (input.substr(peg$currPos, 5) === peg$c64) {
1775 if (peg$silentFails === 0) { peg$fail(peg$c65); }
1777 if (s1 !== peg$FAILED) {
1779 if (s2 !== peg$FAILED) {
1781 if (peg$c66.test(input.charAt(peg$currPos))) {
1782 s4 = input.charAt(peg$currPos);
1786 if (peg$silentFails === 0) { peg$fail(peg$c67); }
1788 if (s4 !== peg$FAILED) {
1789 while (s4 !== peg$FAILED) {
1791 if (peg$c66.test(input.charAt(peg$currPos))) {
1792 s4 = input.charAt(peg$currPos);
1796 if (peg$silentFails === 0) { peg$fail(peg$c67); }
1802 if (s3 !== peg$FAILED) {
1804 if (s4 !== peg$FAILED) {
1805 if (input.charCodeAt(peg$currPos) === 41) {
1810 if (peg$silentFails === 0) { peg$fail(peg$c69); }
1812 if (s5 !== peg$FAILED) {
1837 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1842 function peg$parseflags() {
1845 var key = peg$currPos * 30 + 19,
1846 cached = peg$resultsCache[key];
1849 peg$currPos = cached.nextPos;
1851 return cached.result;
1855 if (peg$c71.test(input.charAt(peg$currPos))) {
1856 s1 = input.charAt(peg$currPos);
1860 if (peg$silentFails === 0) { peg$fail(peg$c72); }
1862 if (s1 !== peg$FAILED) {
1863 while (s1 !== peg$FAILED) {
1865 if (peg$c71.test(input.charAt(peg$currPos))) {
1866 s1 = input.charAt(peg$currPos);
1870 if (peg$silentFails === 0) { peg$fail(peg$c72); }
1877 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1882 function peg$parseregex() {
1883 var s0, s1, s2, s3, s4;
1885 var key = peg$currPos * 30 + 20,
1886 cached = peg$resultsCache[key];
1889 peg$currPos = cached.nextPos;
1891 return cached.result;
1895 if (input.charCodeAt(peg$currPos) === 47) {
1900 if (peg$silentFails === 0) { peg$fail(peg$c74); }
1902 if (s1 !== peg$FAILED) {
1904 if (peg$c75.test(input.charAt(peg$currPos))) {
1905 s3 = input.charAt(peg$currPos);
1909 if (peg$silentFails === 0) { peg$fail(peg$c76); }
1911 if (s3 !== peg$FAILED) {
1912 while (s3 !== peg$FAILED) {
1914 if (peg$c75.test(input.charAt(peg$currPos))) {
1915 s3 = input.charAt(peg$currPos);
1919 if (peg$silentFails === 0) { peg$fail(peg$c76); }
1925 if (s2 !== peg$FAILED) {
1926 if (input.charCodeAt(peg$currPos) === 47) {
1931 if (peg$silentFails === 0) { peg$fail(peg$c74); }
1933 if (s3 !== peg$FAILED) {
1934 s4 = peg$parseflags();
1935 if (s4 === peg$FAILED) {
1938 if (s4 !== peg$FAILED) {
1940 s1 = peg$c77(s2, s4);
1959 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1964 function peg$parsefield() {
1965 var s0, s1, s2, s3, s4, s5, s6;
1967 var key = peg$currPos * 30 + 21,
1968 cached = peg$resultsCache[key];
1971 peg$currPos = cached.nextPos;
1973 return cached.result;
1977 if (input.charCodeAt(peg$currPos) === 46) {
1982 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1984 if (s1 !== peg$FAILED) {
1985 s2 = peg$parseidentifierName();
1986 if (s2 !== peg$FAILED) {
1989 if (input.charCodeAt(peg$currPos) === 46) {
1994 if (peg$silentFails === 0) { peg$fail(peg$c43); }
1996 if (s5 !== peg$FAILED) {
1997 s6 = peg$parseidentifierName();
1998 if (s6 !== peg$FAILED) {
2009 while (s4 !== peg$FAILED) {
2012 if (input.charCodeAt(peg$currPos) === 46) {
2017 if (peg$silentFails === 0) { peg$fail(peg$c43); }
2019 if (s5 !== peg$FAILED) {
2020 s6 = peg$parseidentifierName();
2021 if (s6 !== peg$FAILED) {
2033 if (s3 !== peg$FAILED) {
2035 s1 = peg$c78(s2, s3);
2050 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2055 function peg$parsenegation() {
2056 var s0, s1, s2, s3, s4, s5;
2058 var key = peg$currPos * 30 + 22,
2059 cached = peg$resultsCache[key];
2062 peg$currPos = cached.nextPos;
2064 return cached.result;
2068 if (input.substr(peg$currPos, 5) === peg$c79) {
2073 if (peg$silentFails === 0) { peg$fail(peg$c80); }
2075 if (s1 !== peg$FAILED) {
2077 if (s2 !== peg$FAILED) {
2078 s3 = peg$parseselectors();
2079 if (s3 !== peg$FAILED) {
2081 if (s4 !== peg$FAILED) {
2082 if (input.charCodeAt(peg$currPos) === 41) {
2087 if (peg$silentFails === 0) { peg$fail(peg$c69); }
2089 if (s5 !== peg$FAILED) {
2114 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2119 function peg$parsematches() {
2120 var s0, s1, s2, s3, s4, s5;
2122 var key = peg$currPos * 30 + 23,
2123 cached = peg$resultsCache[key];
2126 peg$currPos = cached.nextPos;
2128 return cached.result;
2132 if (input.substr(peg$currPos, 9) === peg$c82) {
2137 if (peg$silentFails === 0) { peg$fail(peg$c83); }
2139 if (s1 !== peg$FAILED) {
2141 if (s2 !== peg$FAILED) {
2142 s3 = peg$parseselectors();
2143 if (s3 !== peg$FAILED) {
2145 if (s4 !== peg$FAILED) {
2146 if (input.charCodeAt(peg$currPos) === 41) {
2151 if (peg$silentFails === 0) { peg$fail(peg$c69); }
2153 if (s5 !== peg$FAILED) {
2178 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2183 function peg$parsehas() {
2184 var s0, s1, s2, s3, s4, s5;
2186 var key = peg$currPos * 30 + 24,
2187 cached = peg$resultsCache[key];
2190 peg$currPos = cached.nextPos;
2192 return cached.result;
2196 if (input.substr(peg$currPos, 5) === peg$c85) {
2201 if (peg$silentFails === 0) { peg$fail(peg$c86); }
2203 if (s1 !== peg$FAILED) {
2205 if (s2 !== peg$FAILED) {
2206 s3 = peg$parseselectors();
2207 if (s3 !== peg$FAILED) {
2209 if (s4 !== peg$FAILED) {
2210 if (input.charCodeAt(peg$currPos) === 41) {
2215 if (peg$silentFails === 0) { peg$fail(peg$c69); }
2217 if (s5 !== peg$FAILED) {
2242 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2247 function peg$parsefirstChild() {
2250 var key = peg$currPos * 30 + 25,
2251 cached = peg$resultsCache[key];
2254 peg$currPos = cached.nextPos;
2256 return cached.result;
2260 if (input.substr(peg$currPos, 12) === peg$c88) {
2265 if (peg$silentFails === 0) { peg$fail(peg$c89); }
2267 if (s1 !== peg$FAILED) {
2273 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2278 function peg$parselastChild() {
2281 var key = peg$currPos * 30 + 26,
2282 cached = peg$resultsCache[key];
2285 peg$currPos = cached.nextPos;
2287 return cached.result;
2291 if (input.substr(peg$currPos, 11) === peg$c91) {
2296 if (peg$silentFails === 0) { peg$fail(peg$c92); }
2298 if (s1 !== peg$FAILED) {
2304 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2309 function peg$parsenthChild() {
2310 var s0, s1, s2, s3, s4, s5;
2312 var key = peg$currPos * 30 + 27,
2313 cached = peg$resultsCache[key];
2316 peg$currPos = cached.nextPos;
2318 return cached.result;
2322 if (input.substr(peg$currPos, 11) === peg$c94) {
2327 if (peg$silentFails === 0) { peg$fail(peg$c95); }
2329 if (s1 !== peg$FAILED) {
2331 if (s2 !== peg$FAILED) {
2333 if (peg$c60.test(input.charAt(peg$currPos))) {
2334 s4 = input.charAt(peg$currPos);
2338 if (peg$silentFails === 0) { peg$fail(peg$c61); }
2340 if (s4 !== peg$FAILED) {
2341 while (s4 !== peg$FAILED) {
2343 if (peg$c60.test(input.charAt(peg$currPos))) {
2344 s4 = input.charAt(peg$currPos);
2348 if (peg$silentFails === 0) { peg$fail(peg$c61); }
2354 if (s3 !== peg$FAILED) {
2356 if (s4 !== peg$FAILED) {
2357 if (input.charCodeAt(peg$currPos) === 41) {
2362 if (peg$silentFails === 0) { peg$fail(peg$c69); }
2364 if (s5 !== peg$FAILED) {
2389 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2394 function peg$parsenthLastChild() {
2395 var s0, s1, s2, s3, s4, s5;
2397 var key = peg$currPos * 30 + 28,
2398 cached = peg$resultsCache[key];
2401 peg$currPos = cached.nextPos;
2403 return cached.result;
2407 if (input.substr(peg$currPos, 16) === peg$c97) {
2412 if (peg$silentFails === 0) { peg$fail(peg$c98); }
2414 if (s1 !== peg$FAILED) {
2416 if (s2 !== peg$FAILED) {
2418 if (peg$c60.test(input.charAt(peg$currPos))) {
2419 s4 = input.charAt(peg$currPos);
2423 if (peg$silentFails === 0) { peg$fail(peg$c61); }
2425 if (s4 !== peg$FAILED) {
2426 while (s4 !== peg$FAILED) {
2428 if (peg$c60.test(input.charAt(peg$currPos))) {
2429 s4 = input.charAt(peg$currPos);
2433 if (peg$silentFails === 0) { peg$fail(peg$c61); }
2439 if (s3 !== peg$FAILED) {
2441 if (s4 !== peg$FAILED) {
2442 if (input.charCodeAt(peg$currPos) === 41) {
2447 if (peg$silentFails === 0) { peg$fail(peg$c69); }
2449 if (s5 !== peg$FAILED) {
2474 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2479 function peg$parseclass() {
2482 var key = peg$currPos * 30 + 29,
2483 cached = peg$resultsCache[key];
2486 peg$currPos = cached.nextPos;
2488 return cached.result;
2492 if (input.charCodeAt(peg$currPos) === 58) {
2497 if (peg$silentFails === 0) { peg$fail(peg$c101); }
2499 if (s1 !== peg$FAILED) {
2500 if (input.substr(peg$currPos, 9).toLowerCase() === peg$c102) {
2501 s2 = input.substr(peg$currPos, 9);
2505 if (peg$silentFails === 0) { peg$fail(peg$c103); }
2507 if (s2 === peg$FAILED) {
2508 if (input.substr(peg$currPos, 10).toLowerCase() === peg$c104) {
2509 s2 = input.substr(peg$currPos, 10);
2513 if (peg$silentFails === 0) { peg$fail(peg$c105); }
2515 if (s2 === peg$FAILED) {
2516 if (input.substr(peg$currPos, 11).toLowerCase() === peg$c106) {
2517 s2 = input.substr(peg$currPos, 11);
2521 if (peg$silentFails === 0) { peg$fail(peg$c107); }
2523 if (s2 === peg$FAILED) {
2524 if (input.substr(peg$currPos, 8).toLowerCase() === peg$c108) {
2525 s2 = input.substr(peg$currPos, 8);
2529 if (peg$silentFails === 0) { peg$fail(peg$c109); }
2531 if (s2 === peg$FAILED) {
2532 if (input.substr(peg$currPos, 7).toLowerCase() === peg$c110) {
2533 s2 = input.substr(peg$currPos, 7);
2537 if (peg$silentFails === 0) { peg$fail(peg$c111); }
2543 if (s2 !== peg$FAILED) {
2556 peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2562 function nth(n) { return { type: 'nth-child', index: { type: 'literal', value: n } }; }
2563 function nthLast(n) { return { type: 'nth-last-child', index: { type: 'literal', value: n } }; }
2564 function strUnescape(s) {
2565 return s.replace(/\\(.)/g, function(match, ch) {
2567 case 'b': return '\b';
2568 case 'f': return '\f';
2569 case 'n': return '\n';
2570 case 'r': return '\r';
2571 case 't': return '\t';
2572 case 'v': return '\v';
2579 peg$result = peg$startRuleFunction();
2581 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
2584 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
2585 peg$fail(peg$endExpectation());
2588 throw peg$buildStructuredError(
2589 peg$maxFailExpected,
2590 peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
2591 peg$maxFailPos < input.length
2592 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
2593 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
2599 SyntaxError: peg$SyntaxError,