Total Complexity | 539 |
Complexity/F | 6.27 |
Lines of Code | 2673 |
Function Count | 86 |
Duplicated Lines | 729 |
Ratio | 27.27 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like node_modules/esquery/parser.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | var result = (function(){ |
||
2 | /* |
||
3 | * Generated by PEG.js 0.7.0. |
||
4 | * |
||
5 | * http://pegjs.majda.cz/ |
||
6 | */ |
||
7 | |||
8 | function quote(s) { |
||
9 | /* |
||
10 | * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a |
||
11 | * string literal except for the closing quote character, backslash, |
||
12 | * carriage return, line separator, paragraph separator, and line feed. |
||
13 | * Any character may appear in the form of an escape sequence. |
||
14 | * |
||
15 | * For portability, we also escape escape all control and non-ASCII |
||
16 | * characters. Note that "\0" and "\v" escape sequences are not used |
||
17 | * because JSHint does not like the first and IE the second. |
||
18 | */ |
||
19 | return '"' + s |
||
20 | .replace(/\\/g, '\\\\') // backslash |
||
21 | .replace(/"/g, '\\"') // closing quote character |
||
22 | .replace(/\x08/g, '\\b') // backspace |
||
23 | .replace(/\t/g, '\\t') // horizontal tab |
||
24 | .replace(/\n/g, '\\n') // line feed |
||
25 | .replace(/\f/g, '\\f') // form feed |
||
26 | .replace(/\r/g, '\\r') // carriage return |
||
27 | .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) |
||
28 | + '"'; |
||
29 | } |
||
30 | |||
31 | var result = { |
||
32 | /* |
||
33 | * Parses the input with a generated parser. If the parsing is successfull, |
||
34 | * returns a value explicitly or implicitly specified by the grammar from |
||
35 | * which the parser was generated (see |PEG.buildParser|). If the parsing is |
||
36 | * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. |
||
37 | */ |
||
38 | parse: function(input, startRule) { |
||
39 | var parseFunctions = { |
||
40 | "start": parse_start, |
||
41 | "_": parse__, |
||
42 | "identifierName": parse_identifierName, |
||
43 | "binaryOp": parse_binaryOp, |
||
44 | "selectors": parse_selectors, |
||
45 | "selector": parse_selector, |
||
46 | "sequence": parse_sequence, |
||
47 | "atom": parse_atom, |
||
48 | "wildcard": parse_wildcard, |
||
49 | "identifier": parse_identifier, |
||
50 | "attr": parse_attr, |
||
51 | "attrOps": parse_attrOps, |
||
52 | "attrEqOps": parse_attrEqOps, |
||
53 | "attrName": parse_attrName, |
||
54 | "attrValue": parse_attrValue, |
||
55 | "string": parse_string, |
||
56 | "number": parse_number, |
||
57 | "path": parse_path, |
||
58 | "type": parse_type, |
||
59 | "regex": parse_regex, |
||
60 | "field": parse_field, |
||
61 | "negation": parse_negation, |
||
62 | "matches": parse_matches, |
||
63 | "has": parse_has, |
||
64 | "firstChild": parse_firstChild, |
||
65 | "lastChild": parse_lastChild, |
||
66 | "nthChild": parse_nthChild, |
||
67 | "nthLastChild": parse_nthLastChild, |
||
68 | "class": parse_class |
||
69 | }; |
||
70 | |||
71 | if (startRule !== undefined) { |
||
72 | if (parseFunctions[startRule] === undefined) { |
||
73 | throw new Error("Invalid rule name: " + quote(startRule) + "."); |
||
74 | } |
||
75 | } else { |
||
76 | startRule = "start"; |
||
77 | } |
||
78 | |||
79 | var pos = 0; |
||
80 | var reportFailures = 0; |
||
81 | var rightmostFailuresPos = 0; |
||
82 | var rightmostFailuresExpected = []; |
||
83 | var cache = {}; |
||
84 | |||
85 | function padLeft(input, padding, length) { |
||
86 | var result = input; |
||
87 | |||
88 | var padLength = length - input.length; |
||
89 | for (var i = 0; i < padLength; i++) { |
||
90 | result = padding + result; |
||
91 | } |
||
92 | |||
93 | return result; |
||
94 | } |
||
95 | |||
96 | function escape(ch) { |
||
97 | var charCode = ch.charCodeAt(0); |
||
98 | var escapeChar; |
||
99 | var length; |
||
100 | |||
101 | if (charCode <= 0xFF) { |
||
102 | escapeChar = 'x'; |
||
103 | length = 2; |
||
104 | } else { |
||
105 | escapeChar = 'u'; |
||
106 | length = 4; |
||
107 | } |
||
108 | |||
109 | return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); |
||
110 | } |
||
111 | |||
112 | function matchFailed(failure) { |
||
113 | if (pos < rightmostFailuresPos) { |
||
114 | return; |
||
115 | } |
||
116 | |||
117 | if (pos > rightmostFailuresPos) { |
||
118 | rightmostFailuresPos = pos; |
||
119 | rightmostFailuresExpected = []; |
||
120 | } |
||
121 | |||
122 | rightmostFailuresExpected.push(failure); |
||
123 | } |
||
124 | |||
125 | function parse_start() { |
||
126 | var cacheKey = "start@" + pos; |
||
127 | var cachedResult = cache[cacheKey]; |
||
128 | if (cachedResult) { |
||
129 | pos = cachedResult.nextPos; |
||
130 | return cachedResult.result; |
||
131 | } |
||
132 | |||
133 | var result0, result1, result2; |
||
134 | var pos0, pos1; |
||
135 | |||
136 | pos0 = pos; |
||
137 | pos1 = pos; |
||
138 | result0 = parse__(); |
||
139 | if (result0 !== null) { |
||
140 | result1 = parse_selectors(); |
||
141 | if (result1 !== null) { |
||
142 | result2 = parse__(); |
||
143 | if (result2 !== null) { |
||
144 | result0 = [result0, result1, result2]; |
||
145 | } else { |
||
146 | result0 = null; |
||
147 | pos = pos1; |
||
148 | } |
||
149 | } else { |
||
150 | result0 = null; |
||
151 | pos = pos1; |
||
152 | } |
||
153 | } else { |
||
154 | result0 = null; |
||
155 | pos = pos1; |
||
156 | } |
||
157 | if (result0 !== null) { |
||
158 | result0 = (function(offset, ss) { return ss.length === 1 ? ss[0] : { type: 'matches', selectors: ss }; })(pos0, result0[1]); |
||
159 | } |
||
160 | if (result0 === null) { |
||
161 | pos = pos0; |
||
162 | } |
||
163 | if (result0 === null) { |
||
164 | pos0 = pos; |
||
165 | result0 = parse__(); |
||
166 | if (result0 !== null) { |
||
167 | result0 = (function(offset) { return void 0; })(pos0); |
||
168 | } |
||
169 | if (result0 === null) { |
||
170 | pos = pos0; |
||
171 | } |
||
172 | } |
||
173 | |||
174 | cache[cacheKey] = { |
||
175 | nextPos: pos, |
||
176 | result: result0 |
||
177 | }; |
||
178 | return result0; |
||
179 | } |
||
180 | |||
181 | function parse__() { |
||
182 | var cacheKey = "_@" + pos; |
||
183 | var cachedResult = cache[cacheKey]; |
||
184 | if (cachedResult) { |
||
185 | pos = cachedResult.nextPos; |
||
186 | return cachedResult.result; |
||
187 | } |
||
188 | |||
189 | var result0, result1; |
||
190 | |||
191 | result0 = []; |
||
192 | if (input.charCodeAt(pos) === 32) { |
||
193 | result1 = " "; |
||
194 | pos++; |
||
195 | } else { |
||
196 | result1 = null; |
||
197 | if (reportFailures === 0) { |
||
198 | matchFailed("\" \""); |
||
199 | } |
||
200 | } |
||
201 | while (result1 !== null) { |
||
202 | result0.push(result1); |
||
203 | if (input.charCodeAt(pos) === 32) { |
||
204 | result1 = " "; |
||
205 | pos++; |
||
206 | } else { |
||
207 | result1 = null; |
||
208 | if (reportFailures === 0) { |
||
209 | matchFailed("\" \""); |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | |||
214 | cache[cacheKey] = { |
||
215 | nextPos: pos, |
||
216 | result: result0 |
||
217 | }; |
||
218 | return result0; |
||
219 | } |
||
220 | |||
221 | function parse_identifierName() { |
||
222 | var cacheKey = "identifierName@" + pos; |
||
223 | var cachedResult = cache[cacheKey]; |
||
224 | if (cachedResult) { |
||
225 | pos = cachedResult.nextPos; |
||
226 | return cachedResult.result; |
||
227 | } |
||
228 | |||
229 | var result0, result1; |
||
230 | var pos0; |
||
231 | |||
232 | pos0 = pos; |
||
233 | if (/^[^ [\],():#!=><~+.]/.test(input.charAt(pos))) { |
||
234 | result1 = input.charAt(pos); |
||
235 | pos++; |
||
236 | } else { |
||
237 | result1 = null; |
||
238 | if (reportFailures === 0) { |
||
239 | matchFailed("[^ [\\],():#!=><~+.]"); |
||
240 | } |
||
241 | } |
||
242 | if (result1 !== null) { |
||
243 | result0 = []; |
||
244 | while (result1 !== null) { |
||
245 | result0.push(result1); |
||
246 | if (/^[^ [\],():#!=><~+.]/.test(input.charAt(pos))) { |
||
247 | result1 = input.charAt(pos); |
||
248 | pos++; |
||
249 | } else { |
||
250 | result1 = null; |
||
251 | if (reportFailures === 0) { |
||
252 | matchFailed("[^ [\\],():#!=><~+.]"); |
||
253 | } |
||
254 | } |
||
255 | } |
||
256 | } else { |
||
257 | result0 = null; |
||
258 | } |
||
259 | if (result0 !== null) { |
||
260 | result0 = (function(offset, i) { return i.join(''); })(pos0, result0); |
||
261 | } |
||
262 | if (result0 === null) { |
||
263 | pos = pos0; |
||
264 | } |
||
265 | |||
266 | cache[cacheKey] = { |
||
267 | nextPos: pos, |
||
268 | result: result0 |
||
269 | }; |
||
270 | return result0; |
||
271 | } |
||
272 | |||
273 | function parse_binaryOp() { |
||
274 | var cacheKey = "binaryOp@" + pos; |
||
275 | var cachedResult = cache[cacheKey]; |
||
276 | if (cachedResult) { |
||
277 | pos = cachedResult.nextPos; |
||
278 | return cachedResult.result; |
||
279 | } |
||
280 | |||
281 | var result0, result1, result2; |
||
282 | var pos0, pos1; |
||
283 | |||
284 | pos0 = pos; |
||
285 | pos1 = pos; |
||
286 | result0 = parse__(); |
||
287 | if (result0 !== null) { |
||
288 | if (input.charCodeAt(pos) === 62) { |
||
289 | result1 = ">"; |
||
290 | pos++; |
||
291 | } else { |
||
292 | result1 = null; |
||
293 | if (reportFailures === 0) { |
||
294 | matchFailed("\">\""); |
||
295 | } |
||
296 | } |
||
297 | if (result1 !== null) { |
||
298 | result2 = parse__(); |
||
299 | if (result2 !== null) { |
||
300 | result0 = [result0, result1, result2]; |
||
301 | } else { |
||
302 | result0 = null; |
||
303 | pos = pos1; |
||
304 | } |
||
305 | } else { |
||
306 | result0 = null; |
||
307 | pos = pos1; |
||
308 | } |
||
309 | } else { |
||
310 | result0 = null; |
||
311 | pos = pos1; |
||
312 | } |
||
313 | if (result0 !== null) { |
||
314 | result0 = (function(offset) { return 'child'; })(pos0); |
||
315 | } |
||
316 | if (result0 === null) { |
||
317 | pos = pos0; |
||
318 | } |
||
319 | if (result0 === null) { |
||
320 | pos0 = pos; |
||
321 | pos1 = pos; |
||
322 | result0 = parse__(); |
||
323 | if (result0 !== null) { |
||
324 | if (input.charCodeAt(pos) === 126) { |
||
325 | result1 = "~"; |
||
326 | pos++; |
||
327 | } else { |
||
328 | result1 = null; |
||
329 | if (reportFailures === 0) { |
||
330 | matchFailed("\"~\""); |
||
331 | } |
||
332 | } |
||
333 | if (result1 !== null) { |
||
334 | result2 = parse__(); |
||
335 | if (result2 !== null) { |
||
336 | result0 = [result0, result1, result2]; |
||
337 | } else { |
||
338 | result0 = null; |
||
339 | pos = pos1; |
||
340 | } |
||
341 | } else { |
||
342 | result0 = null; |
||
343 | pos = pos1; |
||
344 | } |
||
345 | } else { |
||
346 | result0 = null; |
||
347 | pos = pos1; |
||
348 | } |
||
349 | if (result0 !== null) { |
||
350 | result0 = (function(offset) { return 'sibling'; })(pos0); |
||
351 | } |
||
352 | if (result0 === null) { |
||
353 | pos = pos0; |
||
354 | } |
||
355 | if (result0 === null) { |
||
356 | pos0 = pos; |
||
357 | pos1 = pos; |
||
358 | result0 = parse__(); |
||
359 | if (result0 !== null) { |
||
360 | if (input.charCodeAt(pos) === 43) { |
||
361 | result1 = "+"; |
||
362 | pos++; |
||
363 | } else { |
||
364 | result1 = null; |
||
365 | if (reportFailures === 0) { |
||
366 | matchFailed("\"+\""); |
||
367 | } |
||
368 | } |
||
369 | if (result1 !== null) { |
||
370 | result2 = parse__(); |
||
371 | if (result2 !== null) { |
||
372 | result0 = [result0, result1, result2]; |
||
373 | } else { |
||
374 | result0 = null; |
||
375 | pos = pos1; |
||
376 | } |
||
377 | } else { |
||
378 | result0 = null; |
||
379 | pos = pos1; |
||
380 | } |
||
381 | } else { |
||
382 | result0 = null; |
||
383 | pos = pos1; |
||
384 | } |
||
385 | if (result0 !== null) { |
||
386 | result0 = (function(offset) { return 'adjacent'; })(pos0); |
||
387 | } |
||
388 | if (result0 === null) { |
||
389 | pos = pos0; |
||
390 | } |
||
391 | if (result0 === null) { |
||
392 | pos0 = pos; |
||
393 | pos1 = pos; |
||
394 | if (input.charCodeAt(pos) === 32) { |
||
395 | result0 = " "; |
||
396 | pos++; |
||
397 | } else { |
||
398 | result0 = null; |
||
399 | if (reportFailures === 0) { |
||
400 | matchFailed("\" \""); |
||
401 | } |
||
402 | } |
||
403 | if (result0 !== null) { |
||
404 | result1 = parse__(); |
||
405 | if (result1 !== null) { |
||
406 | result0 = [result0, result1]; |
||
407 | } else { |
||
408 | result0 = null; |
||
409 | pos = pos1; |
||
410 | } |
||
411 | } else { |
||
412 | result0 = null; |
||
413 | pos = pos1; |
||
414 | } |
||
415 | if (result0 !== null) { |
||
416 | result0 = (function(offset) { return 'descendant'; })(pos0); |
||
417 | } |
||
418 | if (result0 === null) { |
||
419 | pos = pos0; |
||
420 | } |
||
421 | } |
||
422 | } |
||
423 | } |
||
424 | |||
425 | cache[cacheKey] = { |
||
426 | nextPos: pos, |
||
427 | result: result0 |
||
428 | }; |
||
429 | return result0; |
||
430 | } |
||
431 | |||
432 | function parse_selectors() { |
||
433 | var cacheKey = "selectors@" + pos; |
||
434 | var cachedResult = cache[cacheKey]; |
||
435 | if (cachedResult) { |
||
436 | pos = cachedResult.nextPos; |
||
437 | return cachedResult.result; |
||
438 | } |
||
439 | |||
440 | var result0, result1, result2, result3, result4, result5; |
||
441 | var pos0, pos1, pos2; |
||
442 | |||
443 | pos0 = pos; |
||
444 | pos1 = pos; |
||
445 | result0 = parse_selector(); |
||
446 | if (result0 !== null) { |
||
447 | result1 = []; |
||
448 | pos2 = pos; |
||
449 | result2 = parse__(); |
||
450 | if (result2 !== null) { |
||
451 | if (input.charCodeAt(pos) === 44) { |
||
452 | result3 = ","; |
||
453 | pos++; |
||
454 | } else { |
||
455 | result3 = null; |
||
456 | if (reportFailures === 0) { |
||
457 | matchFailed("\",\""); |
||
458 | } |
||
459 | } |
||
460 | if (result3 !== null) { |
||
461 | result4 = parse__(); |
||
462 | if (result4 !== null) { |
||
463 | result5 = parse_selector(); |
||
464 | if (result5 !== null) { |
||
465 | result2 = [result2, result3, result4, result5]; |
||
466 | } else { |
||
467 | result2 = null; |
||
468 | pos = pos2; |
||
469 | } |
||
470 | } else { |
||
471 | result2 = null; |
||
472 | pos = pos2; |
||
473 | } |
||
474 | } else { |
||
475 | result2 = null; |
||
476 | pos = pos2; |
||
477 | } |
||
478 | } else { |
||
479 | result2 = null; |
||
480 | pos = pos2; |
||
481 | } |
||
482 | while (result2 !== null) { |
||
483 | result1.push(result2); |
||
484 | pos2 = pos; |
||
485 | result2 = parse__(); |
||
486 | if (result2 !== null) { |
||
487 | if (input.charCodeAt(pos) === 44) { |
||
488 | result3 = ","; |
||
489 | pos++; |
||
490 | } else { |
||
491 | result3 = null; |
||
492 | if (reportFailures === 0) { |
||
493 | matchFailed("\",\""); |
||
494 | } |
||
495 | } |
||
496 | if (result3 !== null) { |
||
497 | result4 = parse__(); |
||
498 | if (result4 !== null) { |
||
499 | result5 = parse_selector(); |
||
500 | if (result5 !== null) { |
||
501 | result2 = [result2, result3, result4, result5]; |
||
502 | } else { |
||
503 | result2 = null; |
||
504 | pos = pos2; |
||
505 | } |
||
506 | } else { |
||
507 | result2 = null; |
||
508 | pos = pos2; |
||
509 | } |
||
510 | } else { |
||
511 | result2 = null; |
||
512 | pos = pos2; |
||
513 | } |
||
514 | } else { |
||
515 | result2 = null; |
||
516 | pos = pos2; |
||
517 | } |
||
518 | } |
||
519 | if (result1 !== null) { |
||
520 | result0 = [result0, result1]; |
||
521 | } else { |
||
522 | result0 = null; |
||
523 | pos = pos1; |
||
524 | } |
||
525 | } else { |
||
526 | result0 = null; |
||
527 | pos = pos1; |
||
528 | } |
||
529 | if (result0 !== null) { |
||
530 | result0 = (function(offset, s, ss) { |
||
531 | return [s].concat(ss.map(function (s) { return s[3]; })); |
||
532 | })(pos0, result0[0], result0[1]); |
||
533 | } |
||
534 | if (result0 === null) { |
||
535 | pos = pos0; |
||
536 | } |
||
537 | |||
538 | cache[cacheKey] = { |
||
539 | nextPos: pos, |
||
540 | result: result0 |
||
541 | }; |
||
542 | return result0; |
||
543 | } |
||
544 | |||
545 | function parse_selector() { |
||
546 | var cacheKey = "selector@" + pos; |
||
547 | var cachedResult = cache[cacheKey]; |
||
548 | if (cachedResult) { |
||
549 | pos = cachedResult.nextPos; |
||
550 | return cachedResult.result; |
||
551 | } |
||
552 | |||
553 | var result0, result1, result2, result3; |
||
554 | var pos0, pos1, pos2; |
||
555 | |||
556 | pos0 = pos; |
||
557 | pos1 = pos; |
||
558 | result0 = parse_sequence(); |
||
559 | if (result0 !== null) { |
||
560 | result1 = []; |
||
561 | pos2 = pos; |
||
562 | result2 = parse_binaryOp(); |
||
563 | if (result2 !== null) { |
||
564 | result3 = parse_sequence(); |
||
565 | if (result3 !== null) { |
||
566 | result2 = [result2, result3]; |
||
567 | } else { |
||
568 | result2 = null; |
||
569 | pos = pos2; |
||
570 | } |
||
571 | } else { |
||
572 | result2 = null; |
||
573 | pos = pos2; |
||
574 | } |
||
575 | while (result2 !== null) { |
||
576 | result1.push(result2); |
||
577 | pos2 = pos; |
||
578 | result2 = parse_binaryOp(); |
||
579 | if (result2 !== null) { |
||
580 | result3 = parse_sequence(); |
||
581 | if (result3 !== null) { |
||
582 | result2 = [result2, result3]; |
||
583 | } else { |
||
584 | result2 = null; |
||
585 | pos = pos2; |
||
586 | } |
||
587 | } else { |
||
588 | result2 = null; |
||
589 | pos = pos2; |
||
590 | } |
||
591 | } |
||
592 | if (result1 !== null) { |
||
593 | result0 = [result0, result1]; |
||
594 | } else { |
||
595 | result0 = null; |
||
596 | pos = pos1; |
||
597 | } |
||
598 | } else { |
||
599 | result0 = null; |
||
600 | pos = pos1; |
||
601 | } |
||
602 | if (result0 !== null) { |
||
603 | result0 = (function(offset, a, ops) { |
||
604 | return ops.reduce(function (memo, rhs) { |
||
605 | return { type: rhs[0], left: memo, right: rhs[1] }; |
||
606 | }, a); |
||
607 | })(pos0, result0[0], result0[1]); |
||
608 | } |
||
609 | if (result0 === null) { |
||
610 | pos = pos0; |
||
611 | } |
||
612 | |||
613 | cache[cacheKey] = { |
||
614 | nextPos: pos, |
||
615 | result: result0 |
||
616 | }; |
||
617 | return result0; |
||
618 | } |
||
619 | |||
620 | function parse_sequence() { |
||
621 | var cacheKey = "sequence@" + pos; |
||
622 | var cachedResult = cache[cacheKey]; |
||
623 | if (cachedResult) { |
||
624 | pos = cachedResult.nextPos; |
||
625 | return cachedResult.result; |
||
626 | } |
||
627 | |||
628 | var result0, result1, result2; |
||
629 | var pos0, pos1; |
||
630 | |||
631 | pos0 = pos; |
||
632 | pos1 = pos; |
||
633 | if (input.charCodeAt(pos) === 33) { |
||
634 | result0 = "!"; |
||
635 | pos++; |
||
636 | } else { |
||
637 | result0 = null; |
||
638 | if (reportFailures === 0) { |
||
639 | matchFailed("\"!\""); |
||
640 | } |
||
641 | } |
||
642 | result0 = result0 !== null ? result0 : ""; |
||
643 | if (result0 !== null) { |
||
644 | result2 = parse_atom(); |
||
645 | if (result2 !== null) { |
||
646 | result1 = []; |
||
647 | while (result2 !== null) { |
||
648 | result1.push(result2); |
||
649 | result2 = parse_atom(); |
||
650 | } |
||
651 | } else { |
||
652 | result1 = null; |
||
653 | } |
||
654 | if (result1 !== null) { |
||
655 | result0 = [result0, result1]; |
||
656 | } else { |
||
657 | result0 = null; |
||
658 | pos = pos1; |
||
659 | } |
||
660 | } else { |
||
661 | result0 = null; |
||
662 | pos = pos1; |
||
663 | } |
||
664 | if (result0 !== null) { |
||
665 | result0 = (function(offset, subject, as) { |
||
666 | var b = as.length === 1 ? as[0] : { type: 'compound', selectors: as }; |
||
667 | if(subject) b.subject = true; |
||
668 | return b; |
||
669 | })(pos0, result0[0], result0[1]); |
||
670 | } |
||
671 | if (result0 === null) { |
||
672 | pos = pos0; |
||
673 | } |
||
674 | |||
675 | cache[cacheKey] = { |
||
676 | nextPos: pos, |
||
677 | result: result0 |
||
678 | }; |
||
679 | return result0; |
||
680 | } |
||
681 | |||
682 | function parse_atom() { |
||
683 | var cacheKey = "atom@" + pos; |
||
684 | var cachedResult = cache[cacheKey]; |
||
685 | if (cachedResult) { |
||
686 | pos = cachedResult.nextPos; |
||
687 | return cachedResult.result; |
||
688 | } |
||
689 | |||
690 | var result0; |
||
691 | |||
692 | result0 = parse_wildcard(); |
||
693 | if (result0 === null) { |
||
694 | result0 = parse_identifier(); |
||
695 | if (result0 === null) { |
||
696 | result0 = parse_attr(); |
||
697 | if (result0 === null) { |
||
698 | result0 = parse_field(); |
||
699 | if (result0 === null) { |
||
700 | result0 = parse_negation(); |
||
701 | if (result0 === null) { |
||
702 | result0 = parse_matches(); |
||
703 | if (result0 === null) { |
||
704 | result0 = parse_has(); |
||
705 | if (result0 === null) { |
||
706 | result0 = parse_firstChild(); |
||
707 | if (result0 === null) { |
||
708 | result0 = parse_lastChild(); |
||
709 | if (result0 === null) { |
||
710 | result0 = parse_nthChild(); |
||
711 | if (result0 === null) { |
||
712 | result0 = parse_nthLastChild(); |
||
713 | if (result0 === null) { |
||
714 | result0 = parse_class(); |
||
715 | } |
||
716 | } |
||
717 | } |
||
718 | } |
||
719 | } |
||
720 | } |
||
721 | } |
||
722 | } |
||
723 | } |
||
724 | } |
||
725 | } |
||
726 | |||
727 | cache[cacheKey] = { |
||
728 | nextPos: pos, |
||
729 | result: result0 |
||
730 | }; |
||
731 | return result0; |
||
732 | } |
||
733 | |||
734 | function parse_wildcard() { |
||
735 | var cacheKey = "wildcard@" + pos; |
||
736 | var cachedResult = cache[cacheKey]; |
||
737 | if (cachedResult) { |
||
738 | pos = cachedResult.nextPos; |
||
739 | return cachedResult.result; |
||
740 | } |
||
741 | |||
742 | var result0; |
||
743 | var pos0; |
||
744 | |||
745 | pos0 = pos; |
||
746 | if (input.charCodeAt(pos) === 42) { |
||
747 | result0 = "*"; |
||
748 | pos++; |
||
749 | } else { |
||
750 | result0 = null; |
||
751 | if (reportFailures === 0) { |
||
752 | matchFailed("\"*\""); |
||
753 | } |
||
754 | } |
||
755 | if (result0 !== null) { |
||
756 | result0 = (function(offset, a) { return { type: 'wildcard', value: a }; })(pos0, result0); |
||
757 | } |
||
758 | if (result0 === null) { |
||
759 | pos = pos0; |
||
760 | } |
||
761 | |||
762 | cache[cacheKey] = { |
||
763 | nextPos: pos, |
||
764 | result: result0 |
||
765 | }; |
||
766 | return result0; |
||
767 | } |
||
768 | |||
769 | function parse_identifier() { |
||
770 | var cacheKey = "identifier@" + pos; |
||
771 | var cachedResult = cache[cacheKey]; |
||
772 | if (cachedResult) { |
||
773 | pos = cachedResult.nextPos; |
||
774 | return cachedResult.result; |
||
775 | } |
||
776 | |||
777 | var result0, result1; |
||
778 | var pos0, pos1; |
||
779 | |||
780 | pos0 = pos; |
||
781 | pos1 = pos; |
||
782 | if (input.charCodeAt(pos) === 35) { |
||
783 | result0 = "#"; |
||
784 | pos++; |
||
785 | } else { |
||
786 | result0 = null; |
||
787 | if (reportFailures === 0) { |
||
788 | matchFailed("\"#\""); |
||
789 | } |
||
790 | } |
||
791 | result0 = result0 !== null ? result0 : ""; |
||
792 | if (result0 !== null) { |
||
793 | result1 = parse_identifierName(); |
||
794 | if (result1 !== null) { |
||
795 | result0 = [result0, result1]; |
||
796 | } else { |
||
797 | result0 = null; |
||
798 | pos = pos1; |
||
799 | } |
||
800 | } else { |
||
801 | result0 = null; |
||
802 | pos = pos1; |
||
803 | } |
||
804 | if (result0 !== null) { |
||
805 | result0 = (function(offset, i) { return { type: 'identifier', value: i }; })(pos0, result0[1]); |
||
806 | } |
||
807 | if (result0 === null) { |
||
808 | pos = pos0; |
||
809 | } |
||
810 | |||
811 | cache[cacheKey] = { |
||
812 | nextPos: pos, |
||
813 | result: result0 |
||
814 | }; |
||
815 | return result0; |
||
816 | } |
||
817 | |||
818 | function parse_attr() { |
||
819 | var cacheKey = "attr@" + pos; |
||
820 | var cachedResult = cache[cacheKey]; |
||
821 | if (cachedResult) { |
||
822 | pos = cachedResult.nextPos; |
||
823 | return cachedResult.result; |
||
824 | } |
||
825 | |||
826 | var result0, result1, result2, result3, result4; |
||
827 | var pos0, pos1; |
||
828 | |||
829 | pos0 = pos; |
||
830 | pos1 = pos; |
||
831 | if (input.charCodeAt(pos) === 91) { |
||
832 | result0 = "["; |
||
833 | pos++; |
||
834 | } else { |
||
835 | result0 = null; |
||
836 | if (reportFailures === 0) { |
||
837 | matchFailed("\"[\""); |
||
838 | } |
||
839 | } |
||
840 | if (result0 !== null) { |
||
841 | result1 = parse__(); |
||
842 | if (result1 !== null) { |
||
843 | result2 = parse_attrValue(); |
||
844 | if (result2 !== null) { |
||
845 | result3 = parse__(); |
||
846 | if (result3 !== null) { |
||
847 | if (input.charCodeAt(pos) === 93) { |
||
848 | result4 = "]"; |
||
849 | pos++; |
||
850 | } else { |
||
851 | result4 = null; |
||
852 | if (reportFailures === 0) { |
||
853 | matchFailed("\"]\""); |
||
854 | } |
||
855 | } |
||
856 | if (result4 !== null) { |
||
857 | result0 = [result0, result1, result2, result3, result4]; |
||
858 | } else { |
||
859 | result0 = null; |
||
860 | pos = pos1; |
||
861 | } |
||
862 | } else { |
||
863 | result0 = null; |
||
864 | pos = pos1; |
||
865 | } |
||
866 | } else { |
||
867 | result0 = null; |
||
868 | pos = pos1; |
||
869 | } |
||
870 | } else { |
||
871 | result0 = null; |
||
872 | pos = pos1; |
||
873 | } |
||
874 | } else { |
||
875 | result0 = null; |
||
876 | pos = pos1; |
||
877 | } |
||
878 | if (result0 !== null) { |
||
879 | result0 = (function(offset, v) { return v; })(pos0, result0[2]); |
||
880 | } |
||
881 | if (result0 === null) { |
||
882 | pos = pos0; |
||
883 | } |
||
884 | |||
885 | cache[cacheKey] = { |
||
886 | nextPos: pos, |
||
887 | result: result0 |
||
888 | }; |
||
889 | return result0; |
||
890 | } |
||
891 | |||
892 | function parse_attrOps() { |
||
893 | var cacheKey = "attrOps@" + pos; |
||
894 | var cachedResult = cache[cacheKey]; |
||
895 | if (cachedResult) { |
||
896 | pos = cachedResult.nextPos; |
||
897 | return cachedResult.result; |
||
898 | } |
||
899 | |||
900 | var result0, result1; |
||
901 | var pos0, pos1; |
||
902 | |||
903 | pos0 = pos; |
||
904 | pos1 = pos; |
||
905 | if (/^[><!]/.test(input.charAt(pos))) { |
||
906 | result0 = input.charAt(pos); |
||
907 | pos++; |
||
908 | } else { |
||
909 | result0 = null; |
||
910 | if (reportFailures === 0) { |
||
911 | matchFailed("[><!]"); |
||
912 | } |
||
913 | } |
||
914 | result0 = result0 !== null ? result0 : ""; |
||
915 | if (result0 !== null) { |
||
916 | if (input.charCodeAt(pos) === 61) { |
||
917 | result1 = "="; |
||
918 | pos++; |
||
919 | } else { |
||
920 | result1 = null; |
||
921 | if (reportFailures === 0) { |
||
922 | matchFailed("\"=\""); |
||
923 | } |
||
924 | } |
||
925 | if (result1 !== null) { |
||
926 | result0 = [result0, result1]; |
||
927 | } else { |
||
928 | result0 = null; |
||
929 | pos = pos1; |
||
930 | } |
||
931 | } else { |
||
932 | result0 = null; |
||
933 | pos = pos1; |
||
934 | } |
||
935 | if (result0 !== null) { |
||
936 | result0 = (function(offset, a) { return a + '='; })(pos0, result0[0]); |
||
937 | } |
||
938 | if (result0 === null) { |
||
939 | pos = pos0; |
||
940 | } |
||
941 | if (result0 === null) { |
||
942 | if (/^[><]/.test(input.charAt(pos))) { |
||
943 | result0 = input.charAt(pos); |
||
944 | pos++; |
||
945 | } else { |
||
946 | result0 = null; |
||
947 | if (reportFailures === 0) { |
||
948 | matchFailed("[><]"); |
||
949 | } |
||
950 | } |
||
951 | } |
||
952 | |||
953 | cache[cacheKey] = { |
||
954 | nextPos: pos, |
||
955 | result: result0 |
||
956 | }; |
||
957 | return result0; |
||
958 | } |
||
959 | |||
960 | function parse_attrEqOps() { |
||
961 | var cacheKey = "attrEqOps@" + pos; |
||
962 | var cachedResult = cache[cacheKey]; |
||
963 | if (cachedResult) { |
||
964 | pos = cachedResult.nextPos; |
||
965 | return cachedResult.result; |
||
966 | } |
||
967 | |||
968 | var result0, result1; |
||
969 | var pos0, pos1; |
||
970 | |||
971 | pos0 = pos; |
||
972 | pos1 = pos; |
||
973 | if (input.charCodeAt(pos) === 33) { |
||
974 | result0 = "!"; |
||
975 | pos++; |
||
976 | } else { |
||
977 | result0 = null; |
||
978 | if (reportFailures === 0) { |
||
979 | matchFailed("\"!\""); |
||
980 | } |
||
981 | } |
||
982 | result0 = result0 !== null ? result0 : ""; |
||
983 | if (result0 !== null) { |
||
984 | if (input.charCodeAt(pos) === 61) { |
||
985 | result1 = "="; |
||
986 | pos++; |
||
987 | } else { |
||
988 | result1 = null; |
||
989 | if (reportFailures === 0) { |
||
990 | matchFailed("\"=\""); |
||
991 | } |
||
992 | } |
||
993 | if (result1 !== null) { |
||
994 | result0 = [result0, result1]; |
||
995 | } else { |
||
996 | result0 = null; |
||
997 | pos = pos1; |
||
998 | } |
||
999 | } else { |
||
1000 | result0 = null; |
||
1001 | pos = pos1; |
||
1002 | } |
||
1003 | if (result0 !== null) { |
||
1004 | result0 = (function(offset, a) { return a + '='; })(pos0, result0[0]); |
||
1005 | } |
||
1006 | if (result0 === null) { |
||
1007 | pos = pos0; |
||
1008 | } |
||
1009 | |||
1010 | cache[cacheKey] = { |
||
1011 | nextPos: pos, |
||
1012 | result: result0 |
||
1013 | }; |
||
1014 | return result0; |
||
1015 | } |
||
1016 | |||
1017 | function parse_attrName() { |
||
1018 | var cacheKey = "attrName@" + pos; |
||
1019 | var cachedResult = cache[cacheKey]; |
||
1020 | if (cachedResult) { |
||
1021 | pos = cachedResult.nextPos; |
||
1022 | return cachedResult.result; |
||
1023 | } |
||
1024 | |||
1025 | var result0, result1; |
||
1026 | var pos0; |
||
1027 | |||
1028 | pos0 = pos; |
||
1029 | result1 = parse_identifierName(); |
||
1030 | if (result1 === null) { |
||
1031 | if (input.charCodeAt(pos) === 46) { |
||
1032 | result1 = "."; |
||
1033 | pos++; |
||
1034 | } else { |
||
1035 | result1 = null; |
||
1036 | if (reportFailures === 0) { |
||
1037 | matchFailed("\".\""); |
||
1038 | } |
||
1039 | } |
||
1040 | } |
||
1041 | if (result1 !== null) { |
||
1042 | result0 = []; |
||
1043 | while (result1 !== null) { |
||
1044 | result0.push(result1); |
||
1045 | result1 = parse_identifierName(); |
||
1046 | if (result1 === null) { |
||
1047 | if (input.charCodeAt(pos) === 46) { |
||
1048 | result1 = "."; |
||
1049 | pos++; |
||
1050 | } else { |
||
1051 | result1 = null; |
||
1052 | if (reportFailures === 0) { |
||
1053 | matchFailed("\".\""); |
||
1054 | } |
||
1055 | } |
||
1056 | } |
||
1057 | } |
||
1058 | } else { |
||
1059 | result0 = null; |
||
1060 | } |
||
1061 | if (result0 !== null) { |
||
1062 | result0 = (function(offset, i) { return i.join(''); })(pos0, result0); |
||
1063 | } |
||
1064 | if (result0 === null) { |
||
1065 | pos = pos0; |
||
1066 | } |
||
1067 | |||
1068 | cache[cacheKey] = { |
||
1069 | nextPos: pos, |
||
1070 | result: result0 |
||
1071 | }; |
||
1072 | return result0; |
||
1073 | } |
||
1074 | |||
1075 | function parse_attrValue() { |
||
1076 | var cacheKey = "attrValue@" + pos; |
||
1077 | var cachedResult = cache[cacheKey]; |
||
1078 | if (cachedResult) { |
||
1079 | pos = cachedResult.nextPos; |
||
1080 | return cachedResult.result; |
||
1081 | } |
||
1082 | |||
1083 | var result0, result1, result2, result3, result4; |
||
1084 | var pos0, pos1; |
||
1085 | |||
1086 | pos0 = pos; |
||
1087 | pos1 = pos; |
||
1088 | result0 = parse_attrName(); |
||
1089 | if (result0 !== null) { |
||
1090 | result1 = parse__(); |
||
1091 | if (result1 !== null) { |
||
1092 | result2 = parse_attrEqOps(); |
||
1093 | if (result2 !== null) { |
||
1094 | result3 = parse__(); |
||
1095 | if (result3 !== null) { |
||
1096 | result4 = parse_type(); |
||
1097 | if (result4 === null) { |
||
1098 | result4 = parse_regex(); |
||
1099 | } |
||
1100 | if (result4 !== null) { |
||
1101 | result0 = [result0, result1, result2, result3, result4]; |
||
1102 | } else { |
||
1103 | result0 = null; |
||
1104 | pos = pos1; |
||
1105 | } |
||
1106 | } else { |
||
1107 | result0 = null; |
||
1108 | pos = pos1; |
||
1109 | } |
||
1110 | } else { |
||
1111 | result0 = null; |
||
1112 | pos = pos1; |
||
1113 | } |
||
1114 | } else { |
||
1115 | result0 = null; |
||
1116 | pos = pos1; |
||
1117 | } |
||
1118 | } else { |
||
1119 | result0 = null; |
||
1120 | pos = pos1; |
||
1121 | } |
||
1122 | if (result0 !== null) { |
||
1123 | result0 = (function(offset, name, op, value) { |
||
1124 | return { type: 'attribute', name: name, operator: op, value: value }; |
||
1125 | })(pos0, result0[0], result0[2], result0[4]); |
||
1126 | } |
||
1127 | if (result0 === null) { |
||
1128 | pos = pos0; |
||
1129 | } |
||
1130 | if (result0 === null) { |
||
1131 | pos0 = pos; |
||
1132 | pos1 = pos; |
||
1133 | result0 = parse_attrName(); |
||
1134 | if (result0 !== null) { |
||
1135 | result1 = parse__(); |
||
1136 | if (result1 !== null) { |
||
1137 | result2 = parse_attrOps(); |
||
1138 | if (result2 !== null) { |
||
1139 | result3 = parse__(); |
||
1140 | if (result3 !== null) { |
||
1141 | result4 = parse_string(); |
||
1142 | if (result4 === null) { |
||
1143 | result4 = parse_number(); |
||
1144 | if (result4 === null) { |
||
1145 | result4 = parse_path(); |
||
1146 | } |
||
1147 | } |
||
1148 | if (result4 !== null) { |
||
1149 | result0 = [result0, result1, result2, result3, result4]; |
||
1150 | } else { |
||
1151 | result0 = null; |
||
1152 | pos = pos1; |
||
1153 | } |
||
1154 | } else { |
||
1155 | result0 = null; |
||
1156 | pos = pos1; |
||
1157 | } |
||
1158 | } else { |
||
1159 | result0 = null; |
||
1160 | pos = pos1; |
||
1161 | } |
||
1162 | } else { |
||
1163 | result0 = null; |
||
1164 | pos = pos1; |
||
1165 | } |
||
1166 | } else { |
||
1167 | result0 = null; |
||
1168 | pos = pos1; |
||
1169 | } |
||
1170 | if (result0 !== null) { |
||
1171 | result0 = (function(offset, name, op, value) { |
||
1172 | return { type: 'attribute', name: name, operator: op, value: value }; |
||
1173 | })(pos0, result0[0], result0[2], result0[4]); |
||
1174 | } |
||
1175 | if (result0 === null) { |
||
1176 | pos = pos0; |
||
1177 | } |
||
1178 | if (result0 === null) { |
||
1179 | pos0 = pos; |
||
1180 | result0 = parse_attrName(); |
||
1181 | if (result0 !== null) { |
||
1182 | result0 = (function(offset, name) { return { type: 'attribute', name: name }; })(pos0, result0); |
||
1183 | } |
||
1184 | if (result0 === null) { |
||
1185 | pos = pos0; |
||
1186 | } |
||
1187 | } |
||
1188 | } |
||
1189 | |||
1190 | cache[cacheKey] = { |
||
1191 | nextPos: pos, |
||
1192 | result: result0 |
||
1193 | }; |
||
1194 | return result0; |
||
1195 | } |
||
1196 | |||
1197 | function parse_string() { |
||
1198 | var cacheKey = "string@" + pos; |
||
1199 | var cachedResult = cache[cacheKey]; |
||
1200 | if (cachedResult) { |
||
1201 | pos = cachedResult.nextPos; |
||
1202 | return cachedResult.result; |
||
1203 | } |
||
1204 | |||
1205 | var result0, result1, result2, result3; |
||
1206 | var pos0, pos1, pos2, pos3; |
||
1207 | |||
1208 | pos0 = pos; |
||
1209 | pos1 = pos; |
||
1210 | if (input.charCodeAt(pos) === 34) { |
||
1211 | result0 = "\""; |
||
1212 | pos++; |
||
1213 | } else { |
||
1214 | result0 = null; |
||
1215 | if (reportFailures === 0) { |
||
1216 | matchFailed("\"\\\"\""); |
||
1217 | } |
||
1218 | } |
||
1219 | if (result0 !== null) { |
||
1220 | result1 = []; |
||
1221 | if (/^[^\\"]/.test(input.charAt(pos))) { |
||
1222 | result2 = input.charAt(pos); |
||
1223 | pos++; |
||
1224 | } else { |
||
1225 | result2 = null; |
||
1226 | if (reportFailures === 0) { |
||
1227 | matchFailed("[^\\\\\"]"); |
||
1228 | } |
||
1229 | } |
||
1230 | if (result2 === null) { |
||
1231 | pos2 = pos; |
||
1232 | pos3 = pos; |
||
1233 | if (input.charCodeAt(pos) === 92) { |
||
1234 | result2 = "\\"; |
||
1235 | pos++; |
||
1236 | } else { |
||
1237 | result2 = null; |
||
1238 | if (reportFailures === 0) { |
||
1239 | matchFailed("\"\\\\\""); |
||
1240 | } |
||
1241 | } |
||
1242 | if (result2 !== null) { |
||
1243 | if (input.length > pos) { |
||
1244 | result3 = input.charAt(pos); |
||
1245 | pos++; |
||
1246 | } else { |
||
1247 | result3 = null; |
||
1248 | if (reportFailures === 0) { |
||
1249 | matchFailed("any character"); |
||
1250 | } |
||
1251 | } |
||
1252 | if (result3 !== null) { |
||
1253 | result2 = [result2, result3]; |
||
1254 | } else { |
||
1255 | result2 = null; |
||
1256 | pos = pos3; |
||
1257 | } |
||
1258 | } else { |
||
1259 | result2 = null; |
||
1260 | pos = pos3; |
||
1261 | } |
||
1262 | if (result2 !== null) { |
||
1263 | result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]); |
||
1264 | } |
||
1265 | if (result2 === null) { |
||
1266 | pos = pos2; |
||
1267 | } |
||
1268 | } |
||
1269 | while (result2 !== null) { |
||
1270 | result1.push(result2); |
||
1271 | if (/^[^\\"]/.test(input.charAt(pos))) { |
||
1272 | result2 = input.charAt(pos); |
||
1273 | pos++; |
||
1274 | } else { |
||
1275 | result2 = null; |
||
1276 | if (reportFailures === 0) { |
||
1277 | matchFailed("[^\\\\\"]"); |
||
1278 | } |
||
1279 | } |
||
1280 | if (result2 === null) { |
||
1281 | pos2 = pos; |
||
1282 | pos3 = pos; |
||
1283 | if (input.charCodeAt(pos) === 92) { |
||
1284 | result2 = "\\"; |
||
1285 | pos++; |
||
1286 | } else { |
||
1287 | result2 = null; |
||
1288 | if (reportFailures === 0) { |
||
1289 | matchFailed("\"\\\\\""); |
||
1290 | } |
||
1291 | } |
||
1292 | if (result2 !== null) { |
||
1293 | if (input.length > pos) { |
||
1294 | result3 = input.charAt(pos); |
||
1295 | pos++; |
||
1296 | } else { |
||
1297 | result3 = null; |
||
1298 | if (reportFailures === 0) { |
||
1299 | matchFailed("any character"); |
||
1300 | } |
||
1301 | } |
||
1302 | if (result3 !== null) { |
||
1303 | result2 = [result2, result3]; |
||
1304 | } else { |
||
1305 | result2 = null; |
||
1306 | pos = pos3; |
||
1307 | } |
||
1308 | } else { |
||
1309 | result2 = null; |
||
1310 | pos = pos3; |
||
1311 | } |
||
1312 | if (result2 !== null) { |
||
1313 | result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]); |
||
1314 | } |
||
1315 | if (result2 === null) { |
||
1316 | pos = pos2; |
||
1317 | } |
||
1318 | } |
||
1319 | } |
||
1320 | if (result1 !== null) { |
||
1321 | if (input.charCodeAt(pos) === 34) { |
||
1322 | result2 = "\""; |
||
1323 | pos++; |
||
1324 | } else { |
||
1325 | result2 = null; |
||
1326 | if (reportFailures === 0) { |
||
1327 | matchFailed("\"\\\"\""); |
||
1328 | } |
||
1329 | } |
||
1330 | if (result2 !== null) { |
||
1331 | result0 = [result0, result1, result2]; |
||
1332 | } else { |
||
1333 | result0 = null; |
||
1334 | pos = pos1; |
||
1335 | } |
||
1336 | } else { |
||
1337 | result0 = null; |
||
1338 | pos = pos1; |
||
1339 | } |
||
1340 | } else { |
||
1341 | result0 = null; |
||
1342 | pos = pos1; |
||
1343 | } |
||
1344 | if (result0 !== null) { |
||
1345 | result0 = (function(offset, d) { |
||
1346 | return { type: 'literal', value: strUnescape(d.join('')) }; |
||
1347 | })(pos0, result0[1]); |
||
1348 | } |
||
1349 | if (result0 === null) { |
||
1350 | pos = pos0; |
||
1351 | } |
||
1352 | if (result0 === null) { |
||
1353 | pos0 = pos; |
||
1354 | pos1 = pos; |
||
1355 | if (input.charCodeAt(pos) === 39) { |
||
1356 | result0 = "'"; |
||
1357 | pos++; |
||
1358 | } else { |
||
1359 | result0 = null; |
||
1360 | if (reportFailures === 0) { |
||
1361 | matchFailed("\"'\""); |
||
1362 | } |
||
1363 | } |
||
1364 | if (result0 !== null) { |
||
1365 | result1 = []; |
||
1366 | if (/^[^\\']/.test(input.charAt(pos))) { |
||
1367 | result2 = input.charAt(pos); |
||
1368 | pos++; |
||
1369 | } else { |
||
1370 | result2 = null; |
||
1371 | if (reportFailures === 0) { |
||
1372 | matchFailed("[^\\\\']"); |
||
1373 | } |
||
1374 | } |
||
1375 | if (result2 === null) { |
||
1376 | pos2 = pos; |
||
1377 | pos3 = pos; |
||
1378 | if (input.charCodeAt(pos) === 92) { |
||
1379 | result2 = "\\"; |
||
1380 | pos++; |
||
1381 | } else { |
||
1382 | result2 = null; |
||
1383 | if (reportFailures === 0) { |
||
1384 | matchFailed("\"\\\\\""); |
||
1385 | } |
||
1386 | } |
||
1387 | if (result2 !== null) { |
||
1388 | if (input.length > pos) { |
||
1389 | result3 = input.charAt(pos); |
||
1390 | pos++; |
||
1391 | } else { |
||
1392 | result3 = null; |
||
1393 | if (reportFailures === 0) { |
||
1394 | matchFailed("any character"); |
||
1395 | } |
||
1396 | } |
||
1397 | if (result3 !== null) { |
||
1398 | result2 = [result2, result3]; |
||
1399 | } else { |
||
1400 | result2 = null; |
||
1401 | pos = pos3; |
||
1402 | } |
||
1403 | } else { |
||
1404 | result2 = null; |
||
1405 | pos = pos3; |
||
1406 | } |
||
1407 | if (result2 !== null) { |
||
1408 | result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]); |
||
1409 | } |
||
1410 | if (result2 === null) { |
||
1411 | pos = pos2; |
||
1412 | } |
||
1413 | } |
||
1414 | while (result2 !== null) { |
||
1415 | result1.push(result2); |
||
1416 | if (/^[^\\']/.test(input.charAt(pos))) { |
||
1417 | result2 = input.charAt(pos); |
||
1418 | pos++; |
||
1419 | } else { |
||
1420 | result2 = null; |
||
1421 | if (reportFailures === 0) { |
||
1422 | matchFailed("[^\\\\']"); |
||
1423 | } |
||
1424 | } |
||
1425 | if (result2 === null) { |
||
1426 | pos2 = pos; |
||
1427 | pos3 = pos; |
||
1428 | if (input.charCodeAt(pos) === 92) { |
||
1429 | result2 = "\\"; |
||
1430 | pos++; |
||
1431 | } else { |
||
1432 | result2 = null; |
||
1433 | if (reportFailures === 0) { |
||
1434 | matchFailed("\"\\\\\""); |
||
1435 | } |
||
1436 | } |
||
1437 | if (result2 !== null) { |
||
1438 | if (input.length > pos) { |
||
1439 | result3 = input.charAt(pos); |
||
1440 | pos++; |
||
1441 | } else { |
||
1442 | result3 = null; |
||
1443 | if (reportFailures === 0) { |
||
1444 | matchFailed("any character"); |
||
1445 | } |
||
1446 | } |
||
1447 | if (result3 !== null) { |
||
1448 | result2 = [result2, result3]; |
||
1449 | } else { |
||
1450 | result2 = null; |
||
1451 | pos = pos3; |
||
1452 | } |
||
1453 | } else { |
||
1454 | result2 = null; |
||
1455 | pos = pos3; |
||
1456 | } |
||
1457 | if (result2 !== null) { |
||
1458 | result2 = (function(offset, a, b) { return a + b; })(pos2, result2[0], result2[1]); |
||
1459 | } |
||
1460 | if (result2 === null) { |
||
1461 | pos = pos2; |
||
1462 | } |
||
1463 | } |
||
1464 | } |
||
1465 | if (result1 !== null) { |
||
1466 | if (input.charCodeAt(pos) === 39) { |
||
1467 | result2 = "'"; |
||
1468 | pos++; |
||
1469 | } else { |
||
1470 | result2 = null; |
||
1471 | if (reportFailures === 0) { |
||
1472 | matchFailed("\"'\""); |
||
1473 | } |
||
1474 | } |
||
1475 | if (result2 !== null) { |
||
1476 | result0 = [result0, result1, result2]; |
||
1477 | } else { |
||
1478 | result0 = null; |
||
1479 | pos = pos1; |
||
1480 | } |
||
1481 | } else { |
||
1482 | result0 = null; |
||
1483 | pos = pos1; |
||
1484 | } |
||
1485 | } else { |
||
1486 | result0 = null; |
||
1487 | pos = pos1; |
||
1488 | } |
||
1489 | if (result0 !== null) { |
||
1490 | result0 = (function(offset, d) { |
||
1491 | return { type: 'literal', value: strUnescape(d.join('')) }; |
||
1492 | })(pos0, result0[1]); |
||
1493 | } |
||
1494 | if (result0 === null) { |
||
1495 | pos = pos0; |
||
1496 | } |
||
1497 | } |
||
1498 | |||
1499 | cache[cacheKey] = { |
||
1500 | nextPos: pos, |
||
1501 | result: result0 |
||
1502 | }; |
||
1503 | return result0; |
||
1504 | } |
||
1505 | |||
1506 | function parse_number() { |
||
1507 | var cacheKey = "number@" + pos; |
||
1508 | var cachedResult = cache[cacheKey]; |
||
1509 | if (cachedResult) { |
||
1510 | pos = cachedResult.nextPos; |
||
1511 | return cachedResult.result; |
||
1512 | } |
||
1513 | |||
1514 | var result0, result1, result2; |
||
1515 | var pos0, pos1, pos2; |
||
1516 | |||
1517 | pos0 = pos; |
||
1518 | pos1 = pos; |
||
1519 | pos2 = pos; |
||
1520 | result0 = []; |
||
1521 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
1522 | result1 = input.charAt(pos); |
||
1523 | pos++; |
||
1524 | } else { |
||
1525 | result1 = null; |
||
1526 | if (reportFailures === 0) { |
||
1527 | matchFailed("[0-9]"); |
||
1528 | } |
||
1529 | } |
||
1530 | while (result1 !== null) { |
||
1531 | result0.push(result1); |
||
1532 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
1533 | result1 = input.charAt(pos); |
||
1534 | pos++; |
||
1535 | } else { |
||
1536 | result1 = null; |
||
1537 | if (reportFailures === 0) { |
||
1538 | matchFailed("[0-9]"); |
||
1539 | } |
||
1540 | } |
||
1541 | } |
||
1542 | if (result0 !== null) { |
||
1543 | if (input.charCodeAt(pos) === 46) { |
||
1544 | result1 = "."; |
||
1545 | pos++; |
||
1546 | } else { |
||
1547 | result1 = null; |
||
1548 | if (reportFailures === 0) { |
||
1549 | matchFailed("\".\""); |
||
1550 | } |
||
1551 | } |
||
1552 | if (result1 !== null) { |
||
1553 | result0 = [result0, result1]; |
||
1554 | } else { |
||
1555 | result0 = null; |
||
1556 | pos = pos2; |
||
1557 | } |
||
1558 | } else { |
||
1559 | result0 = null; |
||
1560 | pos = pos2; |
||
1561 | } |
||
1562 | result0 = result0 !== null ? result0 : ""; |
||
1563 | if (result0 !== null) { |
||
1564 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
1565 | result2 = input.charAt(pos); |
||
1566 | pos++; |
||
1567 | } else { |
||
1568 | result2 = null; |
||
1569 | if (reportFailures === 0) { |
||
1570 | matchFailed("[0-9]"); |
||
1571 | } |
||
1572 | } |
||
1573 | if (result2 !== null) { |
||
1574 | result1 = []; |
||
1575 | while (result2 !== null) { |
||
1576 | result1.push(result2); |
||
1577 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
1578 | result2 = input.charAt(pos); |
||
1579 | pos++; |
||
1580 | } else { |
||
1581 | result2 = null; |
||
1582 | if (reportFailures === 0) { |
||
1583 | matchFailed("[0-9]"); |
||
1584 | } |
||
1585 | } |
||
1586 | } |
||
1587 | } else { |
||
1588 | result1 = null; |
||
1589 | } |
||
1590 | if (result1 !== null) { |
||
1591 | result0 = [result0, result1]; |
||
1592 | } else { |
||
1593 | result0 = null; |
||
1594 | pos = pos1; |
||
1595 | } |
||
1596 | } else { |
||
1597 | result0 = null; |
||
1598 | pos = pos1; |
||
1599 | } |
||
1600 | if (result0 !== null) { |
||
1601 | result0 = (function(offset, a, b) { |
||
1602 | return { type: 'literal', value: parseFloat((a ? a.join('') : '') + b.join('')) }; |
||
1603 | })(pos0, result0[0], result0[1]); |
||
1604 | } |
||
1605 | if (result0 === null) { |
||
1606 | pos = pos0; |
||
1607 | } |
||
1608 | |||
1609 | cache[cacheKey] = { |
||
1610 | nextPos: pos, |
||
1611 | result: result0 |
||
1612 | }; |
||
1613 | return result0; |
||
1614 | } |
||
1615 | |||
1616 | function parse_path() { |
||
1617 | var cacheKey = "path@" + pos; |
||
1618 | var cachedResult = cache[cacheKey]; |
||
1619 | if (cachedResult) { |
||
1620 | pos = cachedResult.nextPos; |
||
1621 | return cachedResult.result; |
||
1622 | } |
||
1623 | |||
1624 | var result0; |
||
1625 | var pos0; |
||
1626 | |||
1627 | pos0 = pos; |
||
1628 | result0 = parse_identifierName(); |
||
1629 | if (result0 !== null) { |
||
1630 | result0 = (function(offset, i) { return { type: 'literal', value: i }; })(pos0, result0); |
||
1631 | } |
||
1632 | if (result0 === null) { |
||
1633 | pos = pos0; |
||
1634 | } |
||
1635 | |||
1636 | cache[cacheKey] = { |
||
1637 | nextPos: pos, |
||
1638 | result: result0 |
||
1639 | }; |
||
1640 | return result0; |
||
1641 | } |
||
1642 | |||
1643 | function parse_type() { |
||
1644 | var cacheKey = "type@" + pos; |
||
1645 | var cachedResult = cache[cacheKey]; |
||
1646 | if (cachedResult) { |
||
1647 | pos = cachedResult.nextPos; |
||
1648 | return cachedResult.result; |
||
1649 | } |
||
1650 | |||
1651 | var result0, result1, result2, result3, result4; |
||
1652 | var pos0, pos1; |
||
1653 | |||
1654 | pos0 = pos; |
||
1655 | pos1 = pos; |
||
1656 | if (input.substr(pos, 5) === "type(") { |
||
1657 | result0 = "type("; |
||
1658 | pos += 5; |
||
1659 | } else { |
||
1660 | result0 = null; |
||
1661 | if (reportFailures === 0) { |
||
1662 | matchFailed("\"type(\""); |
||
1663 | } |
||
1664 | } |
||
1665 | if (result0 !== null) { |
||
1666 | result1 = parse__(); |
||
1667 | if (result1 !== null) { |
||
1668 | if (/^[^ )]/.test(input.charAt(pos))) { |
||
1669 | result3 = input.charAt(pos); |
||
1670 | pos++; |
||
1671 | } else { |
||
1672 | result3 = null; |
||
1673 | if (reportFailures === 0) { |
||
1674 | matchFailed("[^ )]"); |
||
1675 | } |
||
1676 | } |
||
1677 | if (result3 !== null) { |
||
1678 | result2 = []; |
||
1679 | while (result3 !== null) { |
||
1680 | result2.push(result3); |
||
1681 | if (/^[^ )]/.test(input.charAt(pos))) { |
||
1682 | result3 = input.charAt(pos); |
||
1683 | pos++; |
||
1684 | } else { |
||
1685 | result3 = null; |
||
1686 | if (reportFailures === 0) { |
||
1687 | matchFailed("[^ )]"); |
||
1688 | } |
||
1689 | } |
||
1690 | } |
||
1691 | } else { |
||
1692 | result2 = null; |
||
1693 | } |
||
1694 | if (result2 !== null) { |
||
1695 | result3 = parse__(); |
||
1696 | if (result3 !== null) { |
||
1697 | if (input.charCodeAt(pos) === 41) { |
||
1698 | result4 = ")"; |
||
1699 | pos++; |
||
1700 | } else { |
||
1701 | result4 = null; |
||
1702 | if (reportFailures === 0) { |
||
1703 | matchFailed("\")\""); |
||
1704 | } |
||
1705 | } |
||
1706 | if (result4 !== null) { |
||
1707 | result0 = [result0, result1, result2, result3, result4]; |
||
1708 | } else { |
||
1709 | result0 = null; |
||
1710 | pos = pos1; |
||
1711 | } |
||
1712 | } else { |
||
1713 | result0 = null; |
||
1714 | pos = pos1; |
||
1715 | } |
||
1716 | } else { |
||
1717 | result0 = null; |
||
1718 | pos = pos1; |
||
1719 | } |
||
1720 | } else { |
||
1721 | result0 = null; |
||
1722 | pos = pos1; |
||
1723 | } |
||
1724 | } else { |
||
1725 | result0 = null; |
||
1726 | pos = pos1; |
||
1727 | } |
||
1728 | if (result0 !== null) { |
||
1729 | result0 = (function(offset, t) { return { type: 'type', value: t.join('') }; })(pos0, result0[2]); |
||
1730 | } |
||
1731 | if (result0 === null) { |
||
1732 | pos = pos0; |
||
1733 | } |
||
1734 | |||
1735 | cache[cacheKey] = { |
||
1736 | nextPos: pos, |
||
1737 | result: result0 |
||
1738 | }; |
||
1739 | return result0; |
||
1740 | } |
||
1741 | |||
1742 | function parse_regex() { |
||
1743 | var cacheKey = "regex@" + pos; |
||
1744 | var cachedResult = cache[cacheKey]; |
||
1745 | if (cachedResult) { |
||
1746 | pos = cachedResult.nextPos; |
||
1747 | return cachedResult.result; |
||
1748 | } |
||
1749 | |||
1750 | var result0, result1, result2; |
||
1751 | var pos0, pos1; |
||
1752 | |||
1753 | pos0 = pos; |
||
1754 | pos1 = pos; |
||
1755 | if (input.charCodeAt(pos) === 47) { |
||
1756 | result0 = "/"; |
||
1757 | pos++; |
||
1758 | } else { |
||
1759 | result0 = null; |
||
1760 | if (reportFailures === 0) { |
||
1761 | matchFailed("\"/\""); |
||
1762 | } |
||
1763 | } |
||
1764 | if (result0 !== null) { |
||
1765 | if (/^[^\/]/.test(input.charAt(pos))) { |
||
1766 | result2 = input.charAt(pos); |
||
1767 | pos++; |
||
1768 | } else { |
||
1769 | result2 = null; |
||
1770 | if (reportFailures === 0) { |
||
1771 | matchFailed("[^\\/]"); |
||
1772 | } |
||
1773 | } |
||
1774 | if (result2 !== null) { |
||
1775 | result1 = []; |
||
1776 | while (result2 !== null) { |
||
1777 | result1.push(result2); |
||
1778 | if (/^[^\/]/.test(input.charAt(pos))) { |
||
1779 | result2 = input.charAt(pos); |
||
1780 | pos++; |
||
1781 | } else { |
||
1782 | result2 = null; |
||
1783 | if (reportFailures === 0) { |
||
1784 | matchFailed("[^\\/]"); |
||
1785 | } |
||
1786 | } |
||
1787 | } |
||
1788 | } else { |
||
1789 | result1 = null; |
||
1790 | } |
||
1791 | if (result1 !== null) { |
||
1792 | if (input.charCodeAt(pos) === 47) { |
||
1793 | result2 = "/"; |
||
1794 | pos++; |
||
1795 | } else { |
||
1796 | result2 = null; |
||
1797 | if (reportFailures === 0) { |
||
1798 | matchFailed("\"/\""); |
||
1799 | } |
||
1800 | } |
||
1801 | if (result2 !== null) { |
||
1802 | result0 = [result0, result1, result2]; |
||
1803 | } else { |
||
1804 | result0 = null; |
||
1805 | pos = pos1; |
||
1806 | } |
||
1807 | } else { |
||
1808 | result0 = null; |
||
1809 | pos = pos1; |
||
1810 | } |
||
1811 | } else { |
||
1812 | result0 = null; |
||
1813 | pos = pos1; |
||
1814 | } |
||
1815 | if (result0 !== null) { |
||
1816 | result0 = (function(offset, d) { return { type: 'regexp', value: new RegExp(d.join('')) }; })(pos0, result0[1]); |
||
1817 | } |
||
1818 | if (result0 === null) { |
||
1819 | pos = pos0; |
||
1820 | } |
||
1821 | |||
1822 | cache[cacheKey] = { |
||
1823 | nextPos: pos, |
||
1824 | result: result0 |
||
1825 | }; |
||
1826 | return result0; |
||
1827 | } |
||
1828 | |||
1829 | function parse_field() { |
||
1830 | var cacheKey = "field@" + pos; |
||
1831 | var cachedResult = cache[cacheKey]; |
||
1832 | if (cachedResult) { |
||
1833 | pos = cachedResult.nextPos; |
||
1834 | return cachedResult.result; |
||
1835 | } |
||
1836 | |||
1837 | var result0, result1, result2, result3, result4; |
||
1838 | var pos0, pos1, pos2; |
||
1839 | |||
1840 | pos0 = pos; |
||
1841 | pos1 = pos; |
||
1842 | if (input.charCodeAt(pos) === 46) { |
||
1843 | result0 = "."; |
||
1844 | pos++; |
||
1845 | } else { |
||
1846 | result0 = null; |
||
1847 | if (reportFailures === 0) { |
||
1848 | matchFailed("\".\""); |
||
1849 | } |
||
1850 | } |
||
1851 | if (result0 !== null) { |
||
1852 | result1 = parse_identifierName(); |
||
1853 | if (result1 !== null) { |
||
1854 | result2 = []; |
||
1855 | pos2 = pos; |
||
1856 | if (input.charCodeAt(pos) === 46) { |
||
1857 | result3 = "."; |
||
1858 | pos++; |
||
1859 | } else { |
||
1860 | result3 = null; |
||
1861 | if (reportFailures === 0) { |
||
1862 | matchFailed("\".\""); |
||
1863 | } |
||
1864 | } |
||
1865 | if (result3 !== null) { |
||
1866 | result4 = parse_identifierName(); |
||
1867 | if (result4 !== null) { |
||
1868 | result3 = [result3, result4]; |
||
1869 | } else { |
||
1870 | result3 = null; |
||
1871 | pos = pos2; |
||
1872 | } |
||
1873 | } else { |
||
1874 | result3 = null; |
||
1875 | pos = pos2; |
||
1876 | } |
||
1877 | while (result3 !== null) { |
||
1878 | result2.push(result3); |
||
1879 | pos2 = pos; |
||
1880 | if (input.charCodeAt(pos) === 46) { |
||
1881 | result3 = "."; |
||
1882 | pos++; |
||
1883 | } else { |
||
1884 | result3 = null; |
||
1885 | if (reportFailures === 0) { |
||
1886 | matchFailed("\".\""); |
||
1887 | } |
||
1888 | } |
||
1889 | if (result3 !== null) { |
||
1890 | result4 = parse_identifierName(); |
||
1891 | if (result4 !== null) { |
||
1892 | result3 = [result3, result4]; |
||
1893 | } else { |
||
1894 | result3 = null; |
||
1895 | pos = pos2; |
||
1896 | } |
||
1897 | } else { |
||
1898 | result3 = null; |
||
1899 | pos = pos2; |
||
1900 | } |
||
1901 | } |
||
1902 | if (result2 !== null) { |
||
1903 | result0 = [result0, result1, result2]; |
||
1904 | } else { |
||
1905 | result0 = null; |
||
1906 | pos = pos1; |
||
1907 | } |
||
1908 | } else { |
||
1909 | result0 = null; |
||
1910 | pos = pos1; |
||
1911 | } |
||
1912 | } else { |
||
1913 | result0 = null; |
||
1914 | pos = pos1; |
||
1915 | } |
||
1916 | if (result0 !== null) { |
||
1917 | result0 = (function(offset, i, is) { |
||
1918 | return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)}; |
||
1919 | })(pos0, result0[1], result0[2]); |
||
1920 | } |
||
1921 | if (result0 === null) { |
||
1922 | pos = pos0; |
||
1923 | } |
||
1924 | |||
1925 | cache[cacheKey] = { |
||
1926 | nextPos: pos, |
||
1927 | result: result0 |
||
1928 | }; |
||
1929 | return result0; |
||
1930 | } |
||
1931 | |||
1932 | function parse_negation() { |
||
1933 | var cacheKey = "negation@" + pos; |
||
1934 | var cachedResult = cache[cacheKey]; |
||
1935 | if (cachedResult) { |
||
1936 | pos = cachedResult.nextPos; |
||
1937 | return cachedResult.result; |
||
1938 | } |
||
1939 | |||
1940 | var result0, result1, result2, result3, result4; |
||
1941 | var pos0, pos1; |
||
1942 | |||
1943 | pos0 = pos; |
||
1944 | pos1 = pos; |
||
1945 | if (input.substr(pos, 5) === ":not(") { |
||
1946 | result0 = ":not("; |
||
1947 | pos += 5; |
||
1948 | } else { |
||
1949 | result0 = null; |
||
1950 | if (reportFailures === 0) { |
||
1951 | matchFailed("\":not(\""); |
||
1952 | } |
||
1953 | } |
||
1954 | if (result0 !== null) { |
||
1955 | result1 = parse__(); |
||
1956 | if (result1 !== null) { |
||
1957 | result2 = parse_selectors(); |
||
1958 | if (result2 !== null) { |
||
1959 | result3 = parse__(); |
||
1960 | if (result3 !== null) { |
||
1961 | if (input.charCodeAt(pos) === 41) { |
||
1962 | result4 = ")"; |
||
1963 | pos++; |
||
1964 | } else { |
||
1965 | result4 = null; |
||
1966 | if (reportFailures === 0) { |
||
1967 | matchFailed("\")\""); |
||
1968 | } |
||
1969 | } |
||
1970 | if (result4 !== null) { |
||
1971 | result0 = [result0, result1, result2, result3, result4]; |
||
1972 | } else { |
||
1973 | result0 = null; |
||
1974 | pos = pos1; |
||
1975 | } |
||
1976 | } else { |
||
1977 | result0 = null; |
||
1978 | pos = pos1; |
||
1979 | } |
||
1980 | } else { |
||
1981 | result0 = null; |
||
1982 | pos = pos1; |
||
1983 | } |
||
1984 | } else { |
||
1985 | result0 = null; |
||
1986 | pos = pos1; |
||
1987 | } |
||
1988 | } else { |
||
1989 | result0 = null; |
||
1990 | pos = pos1; |
||
1991 | } |
||
1992 | if (result0 !== null) { |
||
1993 | result0 = (function(offset, ss) { return { type: 'not', selectors: ss }; })(pos0, result0[2]); |
||
1994 | } |
||
1995 | if (result0 === null) { |
||
1996 | pos = pos0; |
||
1997 | } |
||
1998 | |||
1999 | cache[cacheKey] = { |
||
2000 | nextPos: pos, |
||
2001 | result: result0 |
||
2002 | }; |
||
2003 | return result0; |
||
2004 | } |
||
2005 | |||
2006 | function parse_matches() { |
||
2007 | var cacheKey = "matches@" + pos; |
||
2008 | var cachedResult = cache[cacheKey]; |
||
2009 | if (cachedResult) { |
||
2010 | pos = cachedResult.nextPos; |
||
2011 | return cachedResult.result; |
||
2012 | } |
||
2013 | |||
2014 | var result0, result1, result2, result3, result4; |
||
2015 | var pos0, pos1; |
||
2016 | |||
2017 | pos0 = pos; |
||
2018 | pos1 = pos; |
||
2019 | if (input.substr(pos, 9) === ":matches(") { |
||
2020 | result0 = ":matches("; |
||
2021 | pos += 9; |
||
2022 | } else { |
||
2023 | result0 = null; |
||
2024 | if (reportFailures === 0) { |
||
2025 | matchFailed("\":matches(\""); |
||
2026 | } |
||
2027 | } |
||
2028 | if (result0 !== null) { |
||
2029 | result1 = parse__(); |
||
2030 | if (result1 !== null) { |
||
2031 | result2 = parse_selectors(); |
||
2032 | if (result2 !== null) { |
||
2033 | result3 = parse__(); |
||
2034 | if (result3 !== null) { |
||
2035 | if (input.charCodeAt(pos) === 41) { |
||
2036 | result4 = ")"; |
||
2037 | pos++; |
||
2038 | } else { |
||
2039 | result4 = null; |
||
2040 | if (reportFailures === 0) { |
||
2041 | matchFailed("\")\""); |
||
2042 | } |
||
2043 | } |
||
2044 | if (result4 !== null) { |
||
2045 | result0 = [result0, result1, result2, result3, result4]; |
||
2046 | } else { |
||
2047 | result0 = null; |
||
2048 | pos = pos1; |
||
2049 | } |
||
2050 | } else { |
||
2051 | result0 = null; |
||
2052 | pos = pos1; |
||
2053 | } |
||
2054 | } else { |
||
2055 | result0 = null; |
||
2056 | pos = pos1; |
||
2057 | } |
||
2058 | } else { |
||
2059 | result0 = null; |
||
2060 | pos = pos1; |
||
2061 | } |
||
2062 | } else { |
||
2063 | result0 = null; |
||
2064 | pos = pos1; |
||
2065 | } |
||
2066 | if (result0 !== null) { |
||
2067 | result0 = (function(offset, ss) { return { type: 'matches', selectors: ss }; })(pos0, result0[2]); |
||
2068 | } |
||
2069 | if (result0 === null) { |
||
2070 | pos = pos0; |
||
2071 | } |
||
2072 | |||
2073 | cache[cacheKey] = { |
||
2074 | nextPos: pos, |
||
2075 | result: result0 |
||
2076 | }; |
||
2077 | return result0; |
||
2078 | } |
||
2079 | |||
2080 | function parse_has() { |
||
2081 | var cacheKey = "has@" + pos; |
||
2082 | var cachedResult = cache[cacheKey]; |
||
2083 | if (cachedResult) { |
||
2084 | pos = cachedResult.nextPos; |
||
2085 | return cachedResult.result; |
||
2086 | } |
||
2087 | |||
2088 | var result0, result1, result2, result3, result4; |
||
2089 | var pos0, pos1; |
||
2090 | |||
2091 | pos0 = pos; |
||
2092 | pos1 = pos; |
||
2093 | if (input.substr(pos, 5) === ":has(") { |
||
2094 | result0 = ":has("; |
||
2095 | pos += 5; |
||
2096 | } else { |
||
2097 | result0 = null; |
||
2098 | if (reportFailures === 0) { |
||
2099 | matchFailed("\":has(\""); |
||
2100 | } |
||
2101 | } |
||
2102 | if (result0 !== null) { |
||
2103 | result1 = parse__(); |
||
2104 | if (result1 !== null) { |
||
2105 | result2 = parse_selectors(); |
||
2106 | if (result2 !== null) { |
||
2107 | result3 = parse__(); |
||
2108 | if (result3 !== null) { |
||
2109 | if (input.charCodeAt(pos) === 41) { |
||
2110 | result4 = ")"; |
||
2111 | pos++; |
||
2112 | } else { |
||
2113 | result4 = null; |
||
2114 | if (reportFailures === 0) { |
||
2115 | matchFailed("\")\""); |
||
2116 | } |
||
2117 | } |
||
2118 | if (result4 !== null) { |
||
2119 | result0 = [result0, result1, result2, result3, result4]; |
||
2120 | } else { |
||
2121 | result0 = null; |
||
2122 | pos = pos1; |
||
2123 | } |
||
2124 | } else { |
||
2125 | result0 = null; |
||
2126 | pos = pos1; |
||
2127 | } |
||
2128 | } else { |
||
2129 | result0 = null; |
||
2130 | pos = pos1; |
||
2131 | } |
||
2132 | } else { |
||
2133 | result0 = null; |
||
2134 | pos = pos1; |
||
2135 | } |
||
2136 | } else { |
||
2137 | result0 = null; |
||
2138 | pos = pos1; |
||
2139 | } |
||
2140 | if (result0 !== null) { |
||
2141 | result0 = (function(offset, ss) { return { type: 'has', selectors: ss }; })(pos0, result0[2]); |
||
2142 | } |
||
2143 | if (result0 === null) { |
||
2144 | pos = pos0; |
||
2145 | } |
||
2146 | |||
2147 | cache[cacheKey] = { |
||
2148 | nextPos: pos, |
||
2149 | result: result0 |
||
2150 | }; |
||
2151 | return result0; |
||
2152 | } |
||
2153 | |||
2154 | function parse_firstChild() { |
||
2155 | var cacheKey = "firstChild@" + pos; |
||
2156 | var cachedResult = cache[cacheKey]; |
||
2157 | if (cachedResult) { |
||
2158 | pos = cachedResult.nextPos; |
||
2159 | return cachedResult.result; |
||
2160 | } |
||
2161 | |||
2162 | var result0; |
||
2163 | var pos0; |
||
2164 | |||
2165 | pos0 = pos; |
||
2166 | if (input.substr(pos, 12) === ":first-child") { |
||
2167 | result0 = ":first-child"; |
||
2168 | pos += 12; |
||
2169 | } else { |
||
2170 | result0 = null; |
||
2171 | if (reportFailures === 0) { |
||
2172 | matchFailed("\":first-child\""); |
||
2173 | } |
||
2174 | } |
||
2175 | if (result0 !== null) { |
||
2176 | result0 = (function(offset) { return nth(1); })(pos0); |
||
2177 | } |
||
2178 | if (result0 === null) { |
||
2179 | pos = pos0; |
||
2180 | } |
||
2181 | |||
2182 | cache[cacheKey] = { |
||
2183 | nextPos: pos, |
||
2184 | result: result0 |
||
2185 | }; |
||
2186 | return result0; |
||
2187 | } |
||
2188 | |||
2189 | function parse_lastChild() { |
||
2190 | var cacheKey = "lastChild@" + pos; |
||
2191 | var cachedResult = cache[cacheKey]; |
||
2192 | if (cachedResult) { |
||
2193 | pos = cachedResult.nextPos; |
||
2194 | return cachedResult.result; |
||
2195 | } |
||
2196 | |||
2197 | var result0; |
||
2198 | var pos0; |
||
2199 | |||
2200 | pos0 = pos; |
||
2201 | if (input.substr(pos, 11) === ":last-child") { |
||
2202 | result0 = ":last-child"; |
||
2203 | pos += 11; |
||
2204 | } else { |
||
2205 | result0 = null; |
||
2206 | if (reportFailures === 0) { |
||
2207 | matchFailed("\":last-child\""); |
||
2208 | } |
||
2209 | } |
||
2210 | if (result0 !== null) { |
||
2211 | result0 = (function(offset) { return nthLast(1); })(pos0); |
||
2212 | } |
||
2213 | if (result0 === null) { |
||
2214 | pos = pos0; |
||
2215 | } |
||
2216 | |||
2217 | cache[cacheKey] = { |
||
2218 | nextPos: pos, |
||
2219 | result: result0 |
||
2220 | }; |
||
2221 | return result0; |
||
2222 | } |
||
2223 | |||
2224 | function parse_nthChild() { |
||
2225 | var cacheKey = "nthChild@" + pos; |
||
2226 | var cachedResult = cache[cacheKey]; |
||
2227 | if (cachedResult) { |
||
2228 | pos = cachedResult.nextPos; |
||
2229 | return cachedResult.result; |
||
2230 | } |
||
2231 | |||
2232 | var result0, result1, result2, result3, result4; |
||
2233 | var pos0, pos1; |
||
2234 | |||
2235 | pos0 = pos; |
||
2236 | pos1 = pos; |
||
2237 | if (input.substr(pos, 11) === ":nth-child(") { |
||
2238 | result0 = ":nth-child("; |
||
2239 | pos += 11; |
||
2240 | } else { |
||
2241 | result0 = null; |
||
2242 | if (reportFailures === 0) { |
||
2243 | matchFailed("\":nth-child(\""); |
||
2244 | } |
||
2245 | } |
||
2246 | if (result0 !== null) { |
||
2247 | result1 = parse__(); |
||
2248 | if (result1 !== null) { |
||
2249 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
2250 | result3 = input.charAt(pos); |
||
2251 | pos++; |
||
2252 | } else { |
||
2253 | result3 = null; |
||
2254 | if (reportFailures === 0) { |
||
2255 | matchFailed("[0-9]"); |
||
2256 | } |
||
2257 | } |
||
2258 | if (result3 !== null) { |
||
2259 | result2 = []; |
||
2260 | while (result3 !== null) { |
||
2261 | result2.push(result3); |
||
2262 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
2263 | result3 = input.charAt(pos); |
||
2264 | pos++; |
||
2265 | } else { |
||
2266 | result3 = null; |
||
2267 | if (reportFailures === 0) { |
||
2268 | matchFailed("[0-9]"); |
||
2269 | } |
||
2270 | } |
||
2271 | } |
||
2272 | } else { |
||
2273 | result2 = null; |
||
2274 | } |
||
2275 | if (result2 !== null) { |
||
2276 | result3 = parse__(); |
||
2277 | if (result3 !== null) { |
||
2278 | if (input.charCodeAt(pos) === 41) { |
||
2279 | result4 = ")"; |
||
2280 | pos++; |
||
2281 | } else { |
||
2282 | result4 = null; |
||
2283 | if (reportFailures === 0) { |
||
2284 | matchFailed("\")\""); |
||
2285 | } |
||
2286 | } |
||
2287 | if (result4 !== null) { |
||
2288 | result0 = [result0, result1, result2, result3, result4]; |
||
2289 | } else { |
||
2290 | result0 = null; |
||
2291 | pos = pos1; |
||
2292 | } |
||
2293 | } else { |
||
2294 | result0 = null; |
||
2295 | pos = pos1; |
||
2296 | } |
||
2297 | } else { |
||
2298 | result0 = null; |
||
2299 | pos = pos1; |
||
2300 | } |
||
2301 | } else { |
||
2302 | result0 = null; |
||
2303 | pos = pos1; |
||
2304 | } |
||
2305 | } else { |
||
2306 | result0 = null; |
||
2307 | pos = pos1; |
||
2308 | } |
||
2309 | if (result0 !== null) { |
||
2310 | result0 = (function(offset, n) { return nth(parseInt(n.join(''), 10)); })(pos0, result0[2]); |
||
2311 | } |
||
2312 | if (result0 === null) { |
||
2313 | pos = pos0; |
||
2314 | } |
||
2315 | |||
2316 | cache[cacheKey] = { |
||
2317 | nextPos: pos, |
||
2318 | result: result0 |
||
2319 | }; |
||
2320 | return result0; |
||
2321 | } |
||
2322 | |||
2323 | function parse_nthLastChild() { |
||
2324 | var cacheKey = "nthLastChild@" + pos; |
||
2325 | var cachedResult = cache[cacheKey]; |
||
2326 | if (cachedResult) { |
||
2327 | pos = cachedResult.nextPos; |
||
2328 | return cachedResult.result; |
||
2329 | } |
||
2330 | |||
2331 | var result0, result1, result2, result3, result4; |
||
2332 | var pos0, pos1; |
||
2333 | |||
2334 | pos0 = pos; |
||
2335 | pos1 = pos; |
||
2336 | if (input.substr(pos, 16) === ":nth-last-child(") { |
||
2337 | result0 = ":nth-last-child("; |
||
2338 | pos += 16; |
||
2339 | } else { |
||
2340 | result0 = null; |
||
2341 | if (reportFailures === 0) { |
||
2342 | matchFailed("\":nth-last-child(\""); |
||
2343 | } |
||
2344 | } |
||
2345 | if (result0 !== null) { |
||
2346 | result1 = parse__(); |
||
2347 | if (result1 !== null) { |
||
2348 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
2349 | result3 = input.charAt(pos); |
||
2350 | pos++; |
||
2351 | } else { |
||
2352 | result3 = null; |
||
2353 | if (reportFailures === 0) { |
||
2354 | matchFailed("[0-9]"); |
||
2355 | } |
||
2356 | } |
||
2357 | if (result3 !== null) { |
||
2358 | result2 = []; |
||
2359 | while (result3 !== null) { |
||
2360 | result2.push(result3); |
||
2361 | if (/^[0-9]/.test(input.charAt(pos))) { |
||
2362 | result3 = input.charAt(pos); |
||
2363 | pos++; |
||
2364 | } else { |
||
2365 | result3 = null; |
||
2366 | if (reportFailures === 0) { |
||
2367 | matchFailed("[0-9]"); |
||
2368 | } |
||
2369 | } |
||
2370 | } |
||
2371 | } else { |
||
2372 | result2 = null; |
||
2373 | } |
||
2374 | if (result2 !== null) { |
||
2375 | result3 = parse__(); |
||
2376 | if (result3 !== null) { |
||
2377 | if (input.charCodeAt(pos) === 41) { |
||
2378 | result4 = ")"; |
||
2379 | pos++; |
||
2380 | } else { |
||
2381 | result4 = null; |
||
2382 | if (reportFailures === 0) { |
||
2383 | matchFailed("\")\""); |
||
2384 | } |
||
2385 | } |
||
2386 | if (result4 !== null) { |
||
2387 | result0 = [result0, result1, result2, result3, result4]; |
||
2388 | } else { |
||
2389 | result0 = null; |
||
2390 | pos = pos1; |
||
2391 | } |
||
2392 | } else { |
||
2393 | result0 = null; |
||
2394 | pos = pos1; |
||
2395 | } |
||
2396 | } else { |
||
2397 | result0 = null; |
||
2398 | pos = pos1; |
||
2399 | } |
||
2400 | } else { |
||
2401 | result0 = null; |
||
2402 | pos = pos1; |
||
2403 | } |
||
2404 | } else { |
||
2405 | result0 = null; |
||
2406 | pos = pos1; |
||
2407 | } |
||
2408 | if (result0 !== null) { |
||
2409 | result0 = (function(offset, n) { return nthLast(parseInt(n.join(''), 10)); })(pos0, result0[2]); |
||
2410 | } |
||
2411 | if (result0 === null) { |
||
2412 | pos = pos0; |
||
2413 | } |
||
2414 | |||
2415 | cache[cacheKey] = { |
||
2416 | nextPos: pos, |
||
2417 | result: result0 |
||
2418 | }; |
||
2419 | return result0; |
||
2420 | } |
||
2421 | |||
2422 | function parse_class() { |
||
2423 | var cacheKey = "class@" + pos; |
||
2424 | var cachedResult = cache[cacheKey]; |
||
2425 | if (cachedResult) { |
||
2426 | pos = cachedResult.nextPos; |
||
2427 | return cachedResult.result; |
||
2428 | } |
||
2429 | |||
2430 | var result0, result1; |
||
2431 | var pos0, pos1; |
||
2432 | |||
2433 | pos0 = pos; |
||
2434 | pos1 = pos; |
||
2435 | if (input.charCodeAt(pos) === 58) { |
||
2436 | result0 = ":"; |
||
2437 | pos++; |
||
2438 | } else { |
||
2439 | result0 = null; |
||
2440 | if (reportFailures === 0) { |
||
2441 | matchFailed("\":\""); |
||
2442 | } |
||
2443 | } |
||
2444 | if (result0 !== null) { |
||
2445 | if (input.substr(pos, 9).toLowerCase() === "statement") { |
||
2446 | result1 = input.substr(pos, 9); |
||
2447 | pos += 9; |
||
2448 | } else { |
||
2449 | result1 = null; |
||
2450 | if (reportFailures === 0) { |
||
2451 | matchFailed("\"statement\""); |
||
2452 | } |
||
2453 | } |
||
2454 | if (result1 === null) { |
||
2455 | if (input.substr(pos, 10).toLowerCase() === "expression") { |
||
2456 | result1 = input.substr(pos, 10); |
||
2457 | pos += 10; |
||
2458 | } else { |
||
2459 | result1 = null; |
||
2460 | if (reportFailures === 0) { |
||
2461 | matchFailed("\"expression\""); |
||
2462 | } |
||
2463 | } |
||
2464 | if (result1 === null) { |
||
2465 | if (input.substr(pos, 11).toLowerCase() === "declaration") { |
||
2466 | result1 = input.substr(pos, 11); |
||
2467 | pos += 11; |
||
2468 | } else { |
||
2469 | result1 = null; |
||
2470 | if (reportFailures === 0) { |
||
2471 | matchFailed("\"declaration\""); |
||
2472 | } |
||
2473 | } |
||
2474 | if (result1 === null) { |
||
2475 | if (input.substr(pos, 8).toLowerCase() === "function") { |
||
2476 | result1 = input.substr(pos, 8); |
||
2477 | pos += 8; |
||
2478 | } else { |
||
2479 | result1 = null; |
||
2480 | if (reportFailures === 0) { |
||
2481 | matchFailed("\"function\""); |
||
2482 | } |
||
2483 | } |
||
2484 | if (result1 === null) { |
||
2485 | if (input.substr(pos, 7).toLowerCase() === "pattern") { |
||
2486 | result1 = input.substr(pos, 7); |
||
2487 | pos += 7; |
||
2488 | } else { |
||
2489 | result1 = null; |
||
2490 | if (reportFailures === 0) { |
||
2491 | matchFailed("\"pattern\""); |
||
2492 | } |
||
2493 | } |
||
2494 | } |
||
2495 | } |
||
2496 | } |
||
2497 | } |
||
2498 | if (result1 !== null) { |
||
2499 | result0 = [result0, result1]; |
||
2500 | } else { |
||
2501 | result0 = null; |
||
2502 | pos = pos1; |
||
2503 | } |
||
2504 | } else { |
||
2505 | result0 = null; |
||
2506 | pos = pos1; |
||
2507 | } |
||
2508 | if (result0 !== null) { |
||
2509 | result0 = (function(offset, c) { |
||
2510 | return { type: 'class', name: c }; |
||
2511 | })(pos0, result0[1]); |
||
2512 | } |
||
2513 | if (result0 === null) { |
||
2514 | pos = pos0; |
||
2515 | } |
||
2516 | |||
2517 | cache[cacheKey] = { |
||
2518 | nextPos: pos, |
||
2519 | result: result0 |
||
2520 | }; |
||
2521 | return result0; |
||
2522 | } |
||
2523 | |||
2524 | |||
2525 | function cleanupExpected(expected) { |
||
2526 | expected.sort(); |
||
2527 | |||
2528 | var lastExpected = null; |
||
2529 | var cleanExpected = []; |
||
2530 | for (var i = 0; i < expected.length; i++) { |
||
2531 | if (expected[i] !== lastExpected) { |
||
2532 | cleanExpected.push(expected[i]); |
||
2533 | lastExpected = expected[i]; |
||
2534 | } |
||
2535 | } |
||
2536 | return cleanExpected; |
||
2537 | } |
||
2538 | |||
2539 | function computeErrorPosition() { |
||
2540 | /* |
||
2541 | * The first idea was to use |String.split| to break the input up to the |
||
2542 | * error position along newlines and derive the line and column from |
||
2543 | * there. However IE's |split| implementation is so broken that it was |
||
2544 | * enough to prevent it. |
||
2545 | */ |
||
2546 | |||
2547 | var line = 1; |
||
2548 | var column = 1; |
||
2549 | var seenCR = false; |
||
2550 | |||
2551 | for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) { |
||
2552 | var ch = input.charAt(i); |
||
2553 | if (ch === "\n") { |
||
2554 | if (!seenCR) { line++; } |
||
2555 | column = 1; |
||
2556 | seenCR = false; |
||
2557 | } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { |
||
2558 | line++; |
||
2559 | column = 1; |
||
2560 | seenCR = true; |
||
2561 | } else { |
||
2562 | column++; |
||
2563 | seenCR = false; |
||
2564 | } |
||
2565 | } |
||
2566 | |||
2567 | return { line: line, column: column }; |
||
2568 | } |
||
2569 | |||
2570 | |||
2571 | function nth(n) { return { type: 'nth-child', index: { type: 'literal', value: n } }; } |
||
2572 | function nthLast(n) { return { type: 'nth-last-child', index: { type: 'literal', value: n } }; } |
||
2573 | function strUnescape(s) { |
||
2574 | return s.replace(/\\(.)/g, function(match, ch) { |
||
2575 | switch(ch) { |
||
2576 | case 'a': return '\a'; |
||
2577 | case 'b': return '\b'; |
||
2578 | case 'f': return '\f'; |
||
2579 | case 'n': return '\n'; |
||
2580 | case 'r': return '\r'; |
||
2581 | case 't': return '\t'; |
||
2582 | case 'v': return '\v'; |
||
2583 | default: return ch; |
||
2584 | } |
||
2585 | }); |
||
2586 | } |
||
2587 | |||
2588 | |||
2589 | var result = parseFunctions[startRule](); |
||
2590 | |||
2591 | /* |
||
2592 | * The parser is now in one of the following three states: |
||
2593 | * |
||
2594 | * 1. The parser successfully parsed the whole input. |
||
2595 | * |
||
2596 | * - |result !== null| |
||
2597 | * - |pos === input.length| |
||
2598 | * - |rightmostFailuresExpected| may or may not contain something |
||
2599 | * |
||
2600 | * 2. The parser successfully parsed only a part of the input. |
||
2601 | * |
||
2602 | * - |result !== null| |
||
2603 | * - |pos < input.length| |
||
2604 | * - |rightmostFailuresExpected| may or may not contain something |
||
2605 | * |
||
2606 | * 3. The parser did not successfully parse any part of the input. |
||
2607 | * |
||
2608 | * - |result === null| |
||
2609 | * - |pos === 0| |
||
2610 | * - |rightmostFailuresExpected| contains at least one failure |
||
2611 | * |
||
2612 | * All code following this comment (including called functions) must |
||
2613 | * handle these states. |
||
2614 | */ |
||
2615 | if (result === null || pos !== input.length) { |
||
2616 | var offset = Math.max(pos, rightmostFailuresPos); |
||
2617 | var found = offset < input.length ? input.charAt(offset) : null; |
||
2618 | var errorPosition = computeErrorPosition(); |
||
2619 | |||
2620 | throw new this.SyntaxError( |
||
2621 | cleanupExpected(rightmostFailuresExpected), |
||
2622 | found, |
||
2623 | offset, |
||
2624 | errorPosition.line, |
||
2625 | errorPosition.column |
||
2626 | ); |
||
2627 | } |
||
2628 | |||
2629 | return result; |
||
2630 | }, |
||
2631 | |||
2632 | /* Returns the parser source code. */ |
||
2633 | toSource: function() { return this._source; } |
||
2634 | }; |
||
2635 | |||
2636 | /* Thrown when a parser encounters a syntax error. */ |
||
2637 | |||
2638 | result.SyntaxError = function(expected, found, offset, line, column) { |
||
2639 | function buildMessage(expected, found) { |
||
2640 | var expectedHumanized, foundHumanized; |
||
2641 | |||
2642 | switch (expected.length) { |
||
2643 | case 0: |
||
2644 | expectedHumanized = "end of input"; |
||
2645 | break; |
||
2646 | case 1: |
||
2647 | expectedHumanized = expected[0]; |
||
2648 | break; |
||
2649 | default: |
||
2650 | expectedHumanized = expected.slice(0, expected.length - 1).join(", ") |
||
2651 | + " or " |
||
2652 | + expected[expected.length - 1]; |
||
2653 | } |
||
2654 | |||
2655 | foundHumanized = found ? quote(found) : "end of input"; |
||
2656 | |||
2657 | return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; |
||
2658 | } |
||
2659 | |||
2660 | this.name = "SyntaxError"; |
||
2661 | this.expected = expected; |
||
2662 | this.found = found; |
||
2663 | this.message = buildMessage(expected, found); |
||
2664 | this.offset = offset; |
||
2665 | this.line = line; |
||
2666 | this.column = column; |
||
2667 | }; |
||
2668 | |||
2669 | result.SyntaxError.prototype = Error.prototype; |
||
2670 | |||
2671 | return result; |
||
2672 | })(); |
||
2673 | if (typeof define === "function" && define.amd) { define(function(){ return result; }); } else if (typeof module !== "undefined" && module.exports) { module.exports = result; } else { this.esquery = result; } |
||
2674 |