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