@loancrate/json-selector 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3450 @@
1
+ import deepEqual from 'fast-deep-equal';
2
+
3
+ function isArray(value) {
4
+ return Array.isArray(value);
5
+ }
6
+ function asArray(value) {
7
+ return value == null ? [] : isArray(value) ? value : [value];
8
+ }
9
+ function isObject(value) {
10
+ return typeof value === "object" && value != null;
11
+ }
12
+ function isFalseOrEmpty(value) {
13
+ return (value == null ||
14
+ value === false ||
15
+ value === "" ||
16
+ (isArray(value) && value.length === 0) ||
17
+ (isObject(value) && !hasOwnProperties(value)));
18
+ }
19
+ function hasOwnProperties(value) {
20
+ for (const key in value) {
21
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ }
27
+ function getField(obj, name) {
28
+ return isObject(obj) ? obj[name] ?? null : null;
29
+ }
30
+ function getIndex(obj, index) {
31
+ return isArray(obj)
32
+ ? obj[index < 0 ? obj.length + index : index] ?? null
33
+ : null;
34
+ }
35
+ function findId(obj, id) {
36
+ return isArray(obj)
37
+ ? obj.find((e) => isObject(e) && e.id === id) ?? null
38
+ : null;
39
+ }
40
+ function findIdIndex(arr, id) {
41
+ return arr.findIndex((e) => isObject(e) && e.id === id);
42
+ }
43
+ function formatLiteral(value) {
44
+ return "`" + JSON.stringify(value).replace(/`/g, "\\`") + "`";
45
+ }
46
+ function isValidIdentifier(s) {
47
+ return /^[a-z_][0-9a-z_]*$/i.test(s);
48
+ }
49
+ function formatIdentifier(s) {
50
+ return isValidIdentifier(s) ? s : JSON.stringify(s);
51
+ }
52
+ function formatRawString(s) {
53
+ // https://jmespath.org/specification.html#raw-string-literals
54
+ // eslint-disable-next-line no-control-regex
55
+ return `'${s.replace(/[\0-\x1F]/g, "").replace(/['\\]/g, (c) => `\\${c}`)}'`;
56
+ }
57
+
58
+ function visitJsonSelector(selector, visitor, context) {
59
+ switch (selector.type) {
60
+ case "current":
61
+ return visitor.current(selector, context);
62
+ case "literal":
63
+ return visitor.literal(selector, context);
64
+ case "identifier":
65
+ return visitor.identifier(selector, context);
66
+ case "fieldAccess":
67
+ return visitor.fieldAccess(selector, context);
68
+ case "indexAccess":
69
+ return visitor.indexAccess(selector, context);
70
+ case "idAccess":
71
+ return visitor.idAccess(selector, context);
72
+ case "project":
73
+ return visitor.project(selector, context);
74
+ case "filter":
75
+ return visitor.filter(selector, context);
76
+ case "slice":
77
+ return visitor.slice(selector, context);
78
+ case "flatten":
79
+ return visitor.flatten(selector, context);
80
+ case "not":
81
+ return visitor.not(selector, context);
82
+ case "compare":
83
+ return visitor.compare(selector, context);
84
+ case "and":
85
+ return visitor.and(selector, context);
86
+ case "or":
87
+ return visitor.or(selector, context);
88
+ case "pipe":
89
+ return visitor.pipe(selector, context);
90
+ }
91
+ }
92
+
93
+ function evaluateJsonSelector(selector, context) {
94
+ return visitJsonSelector(selector, {
95
+ current() {
96
+ return context;
97
+ },
98
+ literal({ value }) {
99
+ return value;
100
+ },
101
+ identifier({ id }) {
102
+ return getField(context, id);
103
+ },
104
+ fieldAccess({ expression, field }) {
105
+ return getField(evaluateJsonSelector(expression, context), field);
106
+ },
107
+ indexAccess({ expression, index }) {
108
+ return getIndex(evaluateJsonSelector(expression, context), index);
109
+ },
110
+ idAccess({ expression, id }) {
111
+ return findId(evaluateJsonSelector(expression, context), id);
112
+ },
113
+ project({ expression, projection }) {
114
+ return project(evaluateJsonSelector(expression, context), projection);
115
+ },
116
+ filter({ expression, condition }) {
117
+ return filter(evaluateJsonSelector(expression, context), condition);
118
+ },
119
+ slice({ expression, start, end, step }) {
120
+ return slice(evaluateJsonSelector(expression, context), start, end, step);
121
+ },
122
+ flatten({ expression }) {
123
+ return flatten(evaluateJsonSelector(expression, context));
124
+ },
125
+ not({ expression }) {
126
+ return isFalseOrEmpty(evaluateJsonSelector(expression, context));
127
+ },
128
+ compare({ lhs, rhs, operator }) {
129
+ const lv = evaluateJsonSelector(lhs, context);
130
+ const rv = evaluateJsonSelector(rhs, context);
131
+ return compare(lv, rv, operator);
132
+ },
133
+ and({ lhs, rhs }) {
134
+ const lv = evaluateJsonSelector(lhs, context);
135
+ return isFalseOrEmpty(lv) ? lv : evaluateJsonSelector(rhs, context);
136
+ },
137
+ or({ lhs, rhs }) {
138
+ const lv = evaluateJsonSelector(lhs, context);
139
+ return !isFalseOrEmpty(lv) ? lv : evaluateJsonSelector(rhs, context);
140
+ },
141
+ pipe({ lhs, rhs }) {
142
+ return evaluateJsonSelector(rhs, evaluateJsonSelector(lhs, context));
143
+ },
144
+ }, context);
145
+ }
146
+ function project(value, projection) {
147
+ if (!isArray(value)) {
148
+ return null;
149
+ }
150
+ if (!projection) {
151
+ return value;
152
+ }
153
+ const result = value
154
+ .map((e) => evaluateJsonSelector(projection, e))
155
+ .filter((e) => e != null);
156
+ return result;
157
+ }
158
+ function filter(value, condition) {
159
+ if (!isArray(value)) {
160
+ return null;
161
+ }
162
+ const result = value.filter((e) => !isFalseOrEmpty(evaluateJsonSelector(condition, e)));
163
+ return result;
164
+ }
165
+ function slice(value, start, end, step) {
166
+ if (!isArray(value)) {
167
+ return null;
168
+ }
169
+ ({ start, end, step } = normalizeSlice(value.length, start, end, step));
170
+ const collected = [];
171
+ if (step > 0) {
172
+ for (let i = start; i < end; i += step) {
173
+ collected.push(value[i]);
174
+ }
175
+ }
176
+ else {
177
+ for (let i = start; i > end; i += step) {
178
+ collected.push(value[i]);
179
+ }
180
+ }
181
+ return collected;
182
+ }
183
+ function normalizeSlice(length, start, end, step) {
184
+ if (step == null) {
185
+ step = 1;
186
+ }
187
+ else if (step === 0) {
188
+ throw new Error("Invalid slice: step cannot be 0");
189
+ }
190
+ if (start == null) {
191
+ start = step < 0 ? length - 1 : 0;
192
+ }
193
+ else {
194
+ start = limitSlice(start, step, length);
195
+ }
196
+ if (end == null) {
197
+ end = step < 0 ? -1 : length;
198
+ }
199
+ else {
200
+ end = limitSlice(end, step, length);
201
+ }
202
+ return { start, end, step };
203
+ }
204
+ function limitSlice(value, step, length) {
205
+ if (value < 0) {
206
+ value += length;
207
+ if (value < 0) {
208
+ value = step < 0 ? -1 : 0;
209
+ }
210
+ }
211
+ else if (value >= length) {
212
+ value = step < 0 ? length - 1 : length;
213
+ }
214
+ return value;
215
+ }
216
+ function flatten(value) {
217
+ return isArray(value) ? value.flat() : null;
218
+ }
219
+ function compare(lv, rv, operator) {
220
+ switch (operator) {
221
+ case "==":
222
+ return deepEqual(lv, rv);
223
+ case "!=":
224
+ return !deepEqual(lv, rv);
225
+ case "<":
226
+ case "<=":
227
+ case ">":
228
+ case ">=":
229
+ if (typeof lv === "number" && typeof rv === "number") {
230
+ switch (operator) {
231
+ case "<":
232
+ return lv < rv;
233
+ case "<=":
234
+ return lv <= rv;
235
+ case ">":
236
+ return lv > rv;
237
+ case ">=":
238
+ return lv >= rv;
239
+ }
240
+ }
241
+ }
242
+ return null;
243
+ }
244
+
245
+ const PRECEDENCE_ACCESS = 1;
246
+ const PRECEDENCE_NOT = 2;
247
+ const PRECEDENCE_COMPARE = 3;
248
+ const PRECEDENCE_AND = 4;
249
+ const PRECEDENCE_OR = 5;
250
+ const PRECEDENCE_PIPE = 6;
251
+ const PRECEDENCE_MAX = 7;
252
+ const operatorPrecedence = {
253
+ fieldAccess: PRECEDENCE_ACCESS,
254
+ idAccess: PRECEDENCE_ACCESS,
255
+ indexAccess: PRECEDENCE_ACCESS,
256
+ project: PRECEDENCE_ACCESS,
257
+ filter: PRECEDENCE_ACCESS,
258
+ slice: PRECEDENCE_ACCESS,
259
+ flatten: PRECEDENCE_ACCESS,
260
+ not: PRECEDENCE_NOT,
261
+ compare: PRECEDENCE_COMPARE,
262
+ and: PRECEDENCE_AND,
263
+ or: PRECEDENCE_OR,
264
+ pipe: PRECEDENCE_PIPE,
265
+ };
266
+ function formatSubexpression(expr, options, precedence) {
267
+ // Ensure @ is only used as a bare expression
268
+ if (!options.currentImplied) {
269
+ options = { ...options, currentImplied: true };
270
+ }
271
+ let result = formatJsonSelector(expr, options);
272
+ const subPrecedence = operatorPrecedence[expr.type];
273
+ if (subPrecedence != null && subPrecedence > precedence) {
274
+ result = `(${result})`;
275
+ }
276
+ return result;
277
+ }
278
+ const projectionNodeTypes = new Set([
279
+ "project",
280
+ "filter",
281
+ "slice",
282
+ "flatten",
283
+ ]);
284
+ function formatJsonSelector(selector, options = {}) {
285
+ return visitJsonSelector(selector, {
286
+ current() {
287
+ return !options.currentImplied ? "@" : "";
288
+ },
289
+ literal({ value }) {
290
+ return formatLiteral(value);
291
+ },
292
+ identifier({ id }) {
293
+ return formatIdentifier(id);
294
+ },
295
+ fieldAccess({ expression, field }) {
296
+ const lv = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
297
+ return `${lv}.${formatIdentifier(field)}`;
298
+ },
299
+ indexAccess({ expression, index }) {
300
+ const lv = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
301
+ return `${lv}[${index}]`;
302
+ },
303
+ idAccess({ expression, id }) {
304
+ const lv = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
305
+ return `${lv}[${formatRawString(id)}]`;
306
+ },
307
+ project({ expression, projection }) {
308
+ let result = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
309
+ // Wildcard operator is only needed if expression is not already a projection
310
+ if (!projectionNodeTypes.has(expression.type)) {
311
+ result += "[*]";
312
+ }
313
+ if (projection) {
314
+ result += formatSubexpression(projection, options, PRECEDENCE_MAX);
315
+ }
316
+ return result;
317
+ },
318
+ filter({ expression, condition }) {
319
+ const lv = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
320
+ const rv = formatSubexpression(condition, options, PRECEDENCE_MAX);
321
+ return `${lv}[?${rv}]`;
322
+ },
323
+ slice({ expression, start, end, step }) {
324
+ const lv = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
325
+ const rv = `${start ?? ""}:${end ?? ""}${step != null ? `:${step}` : ""}`;
326
+ return `${lv}[${rv}]`;
327
+ },
328
+ flatten({ expression }) {
329
+ const lv = formatSubexpression(expression, options, PRECEDENCE_ACCESS);
330
+ return `${lv}[]`;
331
+ },
332
+ not({ expression }) {
333
+ return `!${formatSubexpression(expression, options, PRECEDENCE_NOT)}`;
334
+ },
335
+ compare({ lhs, operator, rhs }) {
336
+ const lv = formatSubexpression(lhs, options, PRECEDENCE_COMPARE);
337
+ const rv = formatSubexpression(rhs, options, PRECEDENCE_COMPARE - 1);
338
+ return `${lv} ${operator} ${rv}`;
339
+ },
340
+ and({ lhs, rhs }) {
341
+ const lv = formatSubexpression(lhs, options, PRECEDENCE_AND);
342
+ const rv = formatSubexpression(rhs, options, PRECEDENCE_AND - 1);
343
+ return `${lv} && ${rv}`;
344
+ },
345
+ or({ lhs, rhs }) {
346
+ const lv = formatSubexpression(lhs, options, PRECEDENCE_OR);
347
+ const rv = formatSubexpression(rhs, options, PRECEDENCE_OR - 1);
348
+ return `${lv} || ${rv}`;
349
+ },
350
+ pipe({ lhs, rhs }) {
351
+ const lv = formatSubexpression(lhs, options, PRECEDENCE_PIPE);
352
+ const rv = formatSubexpression(rhs, options, PRECEDENCE_PIPE - 1);
353
+ return `${lv} | ${rv}`;
354
+ },
355
+ }, undefined);
356
+ }
357
+
358
+ class BaseAccessor {
359
+ constructor(selector) {
360
+ this.selector = selector;
361
+ }
362
+ }
363
+ class ReadOnlyAccessor extends BaseAccessor {
364
+ constructor(selector) {
365
+ super(selector);
366
+ }
367
+ isValidContext() {
368
+ return true;
369
+ }
370
+ set() {
371
+ // ignored
372
+ }
373
+ delete() {
374
+ // ignored
375
+ }
376
+ }
377
+ class ConstantAccessor extends ReadOnlyAccessor {
378
+ constructor(selector, value) {
379
+ super(selector);
380
+ this.value = value;
381
+ }
382
+ get() {
383
+ return this.value;
384
+ }
385
+ }
386
+ class ContextAccessor extends ReadOnlyAccessor {
387
+ constructor() {
388
+ super({ type: "current" });
389
+ }
390
+ get(context) {
391
+ return context;
392
+ }
393
+ }
394
+ function makeJsonSelectorAccessor(selector) {
395
+ return visitJsonSelector(selector, {
396
+ current() {
397
+ return new ContextAccessor();
398
+ },
399
+ literal(selector) {
400
+ return new ConstantAccessor(selector, selector.value);
401
+ },
402
+ identifier(selector) {
403
+ const { id } = selector;
404
+ const Accessor = class extends BaseAccessor {
405
+ constructor() {
406
+ super(selector);
407
+ }
408
+ isValidContext(context) {
409
+ return isObject(context);
410
+ }
411
+ get(context) {
412
+ return getField(context, id);
413
+ }
414
+ set(context, value) {
415
+ if (isObject(context)) {
416
+ context[id] = value;
417
+ }
418
+ }
419
+ delete(context) {
420
+ if (isObject(context)) {
421
+ delete context[id];
422
+ }
423
+ }
424
+ };
425
+ return new Accessor();
426
+ },
427
+ fieldAccess(selector) {
428
+ const { expression, field } = selector;
429
+ const base = makeJsonSelectorAccessor(expression);
430
+ const Accessor = class extends BaseAccessor {
431
+ constructor() {
432
+ super(selector);
433
+ }
434
+ isValidContext(context) {
435
+ return isObject(base.get(context));
436
+ }
437
+ get(context) {
438
+ return getField(base.get(context), field);
439
+ }
440
+ set(context, value) {
441
+ const obj = base.get(context);
442
+ if (isObject(obj)) {
443
+ obj[field] = value;
444
+ }
445
+ }
446
+ delete(context) {
447
+ const obj = base.get(context);
448
+ if (isObject(obj)) {
449
+ delete obj[field];
450
+ }
451
+ }
452
+ };
453
+ return new Accessor();
454
+ },
455
+ indexAccess(selector) {
456
+ const { expression, index } = selector;
457
+ const base = makeJsonSelectorAccessor(expression);
458
+ const Accessor = class extends BaseAccessor {
459
+ constructor() {
460
+ super(selector);
461
+ }
462
+ isValidContext(context) {
463
+ return isArray(base.get(context));
464
+ }
465
+ get(context) {
466
+ return getIndex(base.get(context), index);
467
+ }
468
+ set(context, value) {
469
+ const arr = base.get(context);
470
+ if (isArray(arr)) {
471
+ arr[index] = value;
472
+ }
473
+ }
474
+ delete(context) {
475
+ const arr = base.get(context);
476
+ if (isArray(arr)) {
477
+ arr.splice(index, 1);
478
+ }
479
+ }
480
+ };
481
+ return new Accessor();
482
+ },
483
+ idAccess(selector) {
484
+ const { expression, id } = selector;
485
+ const base = makeJsonSelectorAccessor(expression);
486
+ const Accessor = class extends BaseAccessor {
487
+ constructor() {
488
+ super(selector);
489
+ }
490
+ isValidContext(context) {
491
+ return isArray(base.get(context));
492
+ }
493
+ get(context) {
494
+ return findId(base.get(context), id);
495
+ }
496
+ set(context, value) {
497
+ const arr = base.get(context);
498
+ if (isArray(arr)) {
499
+ const index = findIdIndex(arr, id);
500
+ if (index >= 0) {
501
+ arr[index] = value;
502
+ }
503
+ }
504
+ }
505
+ delete(context) {
506
+ const arr = base.get(context);
507
+ if (isArray(arr)) {
508
+ const index = findIdIndex(arr, id);
509
+ if (index >= 0) {
510
+ arr.splice(index, 1);
511
+ }
512
+ }
513
+ }
514
+ };
515
+ return new Accessor();
516
+ },
517
+ project(selector) {
518
+ const { expression, projection } = selector;
519
+ const base = makeJsonSelectorAccessor(expression);
520
+ const proj = projection && makeJsonSelectorAccessor(projection);
521
+ const Accessor = class extends BaseAccessor {
522
+ constructor() {
523
+ super(selector);
524
+ }
525
+ isValidContext(context) {
526
+ return isArray(base.get(context));
527
+ }
528
+ get(context) {
529
+ return project(base.get(context), projection);
530
+ }
531
+ set(context, value) {
532
+ const arr = base.get(context);
533
+ if (isArray(arr)) {
534
+ if (proj) {
535
+ for (const element of arr) {
536
+ proj.set(element, value);
537
+ }
538
+ }
539
+ else {
540
+ replaceArray(arr, asArray(value));
541
+ }
542
+ }
543
+ }
544
+ delete(context) {
545
+ const arr = base.get(context);
546
+ if (isArray(arr)) {
547
+ if (proj) {
548
+ for (const element of arr) {
549
+ proj.delete(element);
550
+ }
551
+ }
552
+ else {
553
+ arr.length = 0;
554
+ }
555
+ }
556
+ }
557
+ };
558
+ return new Accessor();
559
+ },
560
+ filter(selector) {
561
+ const { expression, condition } = selector;
562
+ const base = makeJsonSelectorAccessor(expression);
563
+ const Accessor = class extends BaseAccessor {
564
+ constructor() {
565
+ super(selector);
566
+ }
567
+ isValidContext(context) {
568
+ return isArray(base.get(context));
569
+ }
570
+ get(context) {
571
+ return filter(base.get(context), condition);
572
+ }
573
+ set(context, value) {
574
+ const arr = base.get(context);
575
+ if (isArray(arr)) {
576
+ replaceArray(arr, invertedFilter(arr, condition).concat(asArray(value)));
577
+ }
578
+ }
579
+ delete(context) {
580
+ const arr = base.get(context);
581
+ if (isArray(arr)) {
582
+ replaceArray(arr, invertedFilter(arr, condition));
583
+ }
584
+ }
585
+ };
586
+ return new Accessor();
587
+ },
588
+ slice(selector) {
589
+ const { expression, start, end, step } = selector;
590
+ const base = makeJsonSelectorAccessor(expression);
591
+ const Accessor = class extends BaseAccessor {
592
+ constructor() {
593
+ super(selector);
594
+ }
595
+ isValidContext(context) {
596
+ return isArray(base.get(context));
597
+ }
598
+ get(context) {
599
+ return slice(base.get(context), start, end, step);
600
+ }
601
+ set(context, value) {
602
+ const arr = base.get(context);
603
+ if (isArray(arr)) {
604
+ replaceArray(arr, invertedSlice(arr, start, end, step).concat(asArray(value)));
605
+ }
606
+ }
607
+ delete(context) {
608
+ const arr = base.get(context);
609
+ if (isArray(arr)) {
610
+ replaceArray(arr, invertedSlice(arr, start, end, step));
611
+ }
612
+ }
613
+ };
614
+ return new Accessor();
615
+ },
616
+ flatten(selector) {
617
+ const { expression } = selector;
618
+ const base = makeJsonSelectorAccessor(expression);
619
+ const Accessor = class extends BaseAccessor {
620
+ constructor() {
621
+ super(selector);
622
+ }
623
+ isValidContext(context) {
624
+ return isArray(base.get(context));
625
+ }
626
+ get(context) {
627
+ return flatten(base.get(context));
628
+ }
629
+ set(context, value) {
630
+ const arr = base.get(context);
631
+ if (isArray(arr)) {
632
+ replaceArray(arr, asArray(value));
633
+ }
634
+ }
635
+ delete(context) {
636
+ const arr = base.get(context);
637
+ if (isArray(arr)) {
638
+ arr.length = 0;
639
+ }
640
+ }
641
+ };
642
+ return new Accessor();
643
+ },
644
+ not(selector) {
645
+ const { expression } = selector;
646
+ const base = makeJsonSelectorAccessor(expression);
647
+ const Accessor = class extends ReadOnlyAccessor {
648
+ constructor() {
649
+ super(selector);
650
+ }
651
+ get(context) {
652
+ return isFalseOrEmpty(base.get(context));
653
+ }
654
+ };
655
+ return new Accessor();
656
+ },
657
+ compare(selector) {
658
+ const { lhs, rhs, operator } = selector;
659
+ const la = makeJsonSelectorAccessor(lhs);
660
+ const ra = makeJsonSelectorAccessor(rhs);
661
+ const Accessor = class extends ReadOnlyAccessor {
662
+ constructor() {
663
+ super(selector);
664
+ }
665
+ get(context) {
666
+ const lv = la.get(context);
667
+ const rv = ra.get(context);
668
+ return compare(lv, rv, operator);
669
+ }
670
+ };
671
+ return new Accessor();
672
+ },
673
+ and(selector) {
674
+ const { lhs, rhs } = selector;
675
+ const la = makeJsonSelectorAccessor(lhs);
676
+ const ra = makeJsonSelectorAccessor(rhs);
677
+ const Accessor = class extends ReadOnlyAccessor {
678
+ constructor() {
679
+ super(selector);
680
+ }
681
+ get(context) {
682
+ const lv = la.get(context);
683
+ return isFalseOrEmpty(lv) ? lv : ra.get(context);
684
+ }
685
+ };
686
+ return new Accessor();
687
+ },
688
+ or(selector) {
689
+ const { lhs, rhs } = selector;
690
+ const la = makeJsonSelectorAccessor(lhs);
691
+ const ra = makeJsonSelectorAccessor(rhs);
692
+ const Accessor = class extends ReadOnlyAccessor {
693
+ constructor() {
694
+ super(selector);
695
+ }
696
+ get(context) {
697
+ const lv = la.get(context);
698
+ return !isFalseOrEmpty(lv) ? lv : ra.get(context);
699
+ }
700
+ };
701
+ return new Accessor();
702
+ },
703
+ pipe(selector) {
704
+ const { lhs, rhs } = selector;
705
+ const la = makeJsonSelectorAccessor(lhs);
706
+ const ra = makeJsonSelectorAccessor(rhs);
707
+ const Accessor = class extends BaseAccessor {
708
+ constructor() {
709
+ super(selector);
710
+ }
711
+ isValidContext(context) {
712
+ return ra.isValidContext(la.get(context));
713
+ }
714
+ get(context) {
715
+ return ra.get(la.get(context));
716
+ }
717
+ set(context, value) {
718
+ ra.set(la.get(context), value);
719
+ }
720
+ delete(context) {
721
+ ra.delete(la.get(context));
722
+ }
723
+ };
724
+ return new Accessor();
725
+ },
726
+ }, undefined);
727
+ }
728
+ function bindJsonSelectorAccessor(unbound, context) {
729
+ const { selector } = unbound;
730
+ const valid = unbound.isValidContext(context);
731
+ return {
732
+ selector,
733
+ valid,
734
+ path: formatJsonSelector(selector),
735
+ get() {
736
+ return unbound.get(context);
737
+ },
738
+ set(v) {
739
+ unbound.set(context, v);
740
+ },
741
+ delete() {
742
+ unbound.delete(context);
743
+ },
744
+ };
745
+ }
746
+ function accessWithJsonSelector(selector, context) {
747
+ return bindJsonSelectorAccessor(makeJsonSelectorAccessor(selector), context);
748
+ }
749
+ function replaceArray(target, source) {
750
+ target.length = 0;
751
+ target.push(...source);
752
+ return target;
753
+ }
754
+ function invertedFilter(value, condition) {
755
+ return value.filter((e) => isFalseOrEmpty(evaluateJsonSelector(condition, e)));
756
+ }
757
+ function invertedSlice(value, start, end, step) {
758
+ ({ start, end, step } = normalizeSlice(value.length, start, end, step));
759
+ const collected = [];
760
+ if (step > 0) {
761
+ if (start >= end) {
762
+ return value;
763
+ }
764
+ let skip = start;
765
+ for (let i = 0; i < value.length; ++i) {
766
+ if (i < skip || i >= end) {
767
+ collected.push(value[i]);
768
+ }
769
+ else {
770
+ skip += step;
771
+ }
772
+ }
773
+ }
774
+ else {
775
+ if (start <= end) {
776
+ return value;
777
+ }
778
+ let skip = start;
779
+ for (let i = value.length - 1; i >= 0; --i) {
780
+ if (i > skip || i <= end) {
781
+ collected.push(value[i]);
782
+ }
783
+ else {
784
+ skip += step;
785
+ }
786
+ }
787
+ }
788
+ return collected;
789
+ }
790
+
791
+ function getWithJsonSelector(selector, context) {
792
+ return accessWithJsonSelector(selector, context).get();
793
+ }
794
+
795
+ function peg$subclass(child, parent) {
796
+ function C() { this.constructor = child; }
797
+ C.prototype = parent.prototype;
798
+ child.prototype = new C();
799
+ }
800
+
801
+ function peg$SyntaxError(message, expected, found, location) {
802
+ var self = Error.call(this, message);
803
+ // istanbul ignore next Check is a necessary evil to support older environments
804
+ if (Object.setPrototypeOf) {
805
+ Object.setPrototypeOf(self, peg$SyntaxError.prototype);
806
+ }
807
+ self.expected = expected;
808
+ self.found = found;
809
+ self.location = location;
810
+ self.name = "SyntaxError";
811
+ return self;
812
+ }
813
+
814
+ peg$subclass(peg$SyntaxError, Error);
815
+
816
+ function peg$padEnd(str, targetLength, padString) {
817
+ padString = padString || " ";
818
+ if (str.length > targetLength) { return str; }
819
+ targetLength -= str.length;
820
+ padString += padString.repeat(targetLength);
821
+ return str + padString.slice(0, targetLength);
822
+ }
823
+
824
+ peg$SyntaxError.prototype.format = function(sources) {
825
+ var str = "Error: " + this.message;
826
+ if (this.location) {
827
+ var src = null;
828
+ var k;
829
+ for (k = 0; k < sources.length; k++) {
830
+ if (sources[k].source === this.location.source) {
831
+ src = sources[k].text.split(/\r\n|\n|\r/g);
832
+ break;
833
+ }
834
+ }
835
+ var s = this.location.start;
836
+ var loc = this.location.source + ":" + s.line + ":" + s.column;
837
+ if (src) {
838
+ var e = this.location.end;
839
+ var filler = peg$padEnd("", s.line.toString().length, ' ');
840
+ var line = src[s.line - 1];
841
+ var last = s.line === e.line ? e.column : line.length + 1;
842
+ var hatLen = (last - s.column) || 1;
843
+ str += "\n --> " + loc + "\n"
844
+ + filler + " |\n"
845
+ + s.line + " | " + line + "\n"
846
+ + filler + " | " + peg$padEnd("", s.column - 1, ' ')
847
+ + peg$padEnd("", hatLen, "^");
848
+ } else {
849
+ str += "\n at " + loc;
850
+ }
851
+ }
852
+ return str;
853
+ };
854
+
855
+ peg$SyntaxError.buildMessage = function(expected, found) {
856
+ var DESCRIBE_EXPECTATION_FNS = {
857
+ literal: function(expectation) {
858
+ return "\"" + literalEscape(expectation.text) + "\"";
859
+ },
860
+
861
+ class: function(expectation) {
862
+ var escapedParts = expectation.parts.map(function(part) {
863
+ return Array.isArray(part)
864
+ ? classEscape(part[0]) + "-" + classEscape(part[1])
865
+ : classEscape(part);
866
+ });
867
+
868
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
869
+ },
870
+
871
+ any: function() {
872
+ return "any character";
873
+ },
874
+
875
+ end: function() {
876
+ return "end of input";
877
+ },
878
+
879
+ other: function(expectation) {
880
+ return expectation.description;
881
+ }
882
+ };
883
+
884
+ function hex(ch) {
885
+ return ch.charCodeAt(0).toString(16).toUpperCase();
886
+ }
887
+
888
+ function literalEscape(s) {
889
+ return s
890
+ .replace(/\\/g, "\\\\")
891
+ .replace(/"/g, "\\\"")
892
+ .replace(/\0/g, "\\0")
893
+ .replace(/\t/g, "\\t")
894
+ .replace(/\n/g, "\\n")
895
+ .replace(/\r/g, "\\r")
896
+ .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
897
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
898
+ }
899
+
900
+ function classEscape(s) {
901
+ return s
902
+ .replace(/\\/g, "\\\\")
903
+ .replace(/\]/g, "\\]")
904
+ .replace(/\^/g, "\\^")
905
+ .replace(/-/g, "\\-")
906
+ .replace(/\0/g, "\\0")
907
+ .replace(/\t/g, "\\t")
908
+ .replace(/\n/g, "\\n")
909
+ .replace(/\r/g, "\\r")
910
+ .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
911
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
912
+ }
913
+
914
+ function describeExpectation(expectation) {
915
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
916
+ }
917
+
918
+ function describeExpected(expected) {
919
+ var descriptions = expected.map(describeExpectation);
920
+ var i, j;
921
+
922
+ descriptions.sort();
923
+
924
+ if (descriptions.length > 0) {
925
+ for (i = 1, j = 1; i < descriptions.length; i++) {
926
+ if (descriptions[i - 1] !== descriptions[i]) {
927
+ descriptions[j] = descriptions[i];
928
+ j++;
929
+ }
930
+ }
931
+ descriptions.length = j;
932
+ }
933
+
934
+ switch (descriptions.length) {
935
+ case 1:
936
+ return descriptions[0];
937
+
938
+ case 2:
939
+ return descriptions[0] + " or " + descriptions[1];
940
+
941
+ default:
942
+ return descriptions.slice(0, -1).join(", ")
943
+ + ", or "
944
+ + descriptions[descriptions.length - 1];
945
+ }
946
+ }
947
+
948
+ function describeFound(found) {
949
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
950
+ }
951
+
952
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
953
+ };
954
+
955
+ function peg$parse(input, options) {
956
+ options = options !== undefined ? options : {};
957
+
958
+ var peg$FAILED = {};
959
+ var peg$source = options.grammarSource;
960
+
961
+ var peg$startRuleFunctions = { selector: peg$parseselector };
962
+ var peg$startRuleFunction = peg$parseselector;
963
+
964
+ var peg$c0 = "|";
965
+ var peg$c1 = "||";
966
+ var peg$c2 = "&&";
967
+ var peg$c3 = "<=";
968
+ var peg$c4 = ">=";
969
+ var peg$c5 = "<";
970
+ var peg$c6 = ">";
971
+ var peg$c7 = "==";
972
+ var peg$c8 = "!=";
973
+ var peg$c9 = "!";
974
+ var peg$c10 = "[]";
975
+ var peg$c11 = "[?";
976
+ var peg$c12 = "]";
977
+ var peg$c13 = "[";
978
+ var peg$c14 = "*";
979
+ var peg$c15 = ":";
980
+ var peg$c16 = ".";
981
+ var peg$c17 = "@";
982
+ var peg$c18 = "(";
983
+ var peg$c19 = ")";
984
+ var peg$c20 = "`";
985
+ var peg$c21 = "\"";
986
+ var peg$c22 = "\\";
987
+ var peg$c23 = "/";
988
+ var peg$c24 = "b";
989
+ var peg$c25 = "f";
990
+ var peg$c26 = "n";
991
+ var peg$c27 = "r";
992
+ var peg$c28 = "t";
993
+ var peg$c29 = "u";
994
+ var peg$c30 = "'";
995
+ var peg$c31 = "-";
996
+ var peg$c32 = "0";
997
+ var peg$c33 = "null";
998
+ var peg$c34 = "false";
999
+ var peg$c35 = "true";
1000
+ var peg$c36 = "{";
1001
+ var peg$c37 = ",";
1002
+ var peg$c38 = "}";
1003
+
1004
+ var peg$r0 = /^[a-z_]/i;
1005
+ var peg$r1 = /^[0-9a-z_]/i;
1006
+ var peg$r2 = /^[^\0-\x1F"\\]/;
1007
+ var peg$r3 = /^[0-9a-f]/i;
1008
+ var peg$r4 = /^[^'\\]/;
1009
+ var peg$r5 = /^[^']/;
1010
+ var peg$r6 = /^[1-9]/;
1011
+ var peg$r7 = /^[0-9]/;
1012
+ var peg$r8 = /^[eE]/;
1013
+ var peg$r9 = /^[+\-]/;
1014
+ var peg$r10 = /^[^\0-\x1F"\\`]/;
1015
+ var peg$r11 = /^[ \t\n\r]/;
1016
+
1017
+ var peg$e0 = peg$literalExpectation("|", false);
1018
+ var peg$e1 = peg$literalExpectation("||", false);
1019
+ var peg$e2 = peg$literalExpectation("&&", false);
1020
+ var peg$e3 = peg$literalExpectation("<=", false);
1021
+ var peg$e4 = peg$literalExpectation(">=", false);
1022
+ var peg$e5 = peg$literalExpectation("<", false);
1023
+ var peg$e6 = peg$literalExpectation(">", false);
1024
+ var peg$e7 = peg$literalExpectation("==", false);
1025
+ var peg$e8 = peg$literalExpectation("!=", false);
1026
+ var peg$e9 = peg$literalExpectation("!", false);
1027
+ var peg$e10 = peg$literalExpectation("[]", false);
1028
+ var peg$e11 = peg$literalExpectation("[?", false);
1029
+ var peg$e12 = peg$literalExpectation("]", false);
1030
+ var peg$e13 = peg$literalExpectation("[", false);
1031
+ var peg$e14 = peg$literalExpectation("*", false);
1032
+ var peg$e15 = peg$literalExpectation(":", false);
1033
+ var peg$e16 = peg$literalExpectation(".", false);
1034
+ var peg$e17 = peg$literalExpectation("@", false);
1035
+ var peg$e18 = peg$literalExpectation("(", false);
1036
+ var peg$e19 = peg$literalExpectation(")", false);
1037
+ var peg$e20 = peg$literalExpectation("`", false);
1038
+ var peg$e21 = peg$classExpectation([["a", "z"], "_"], false, true);
1039
+ var peg$e22 = peg$classExpectation([["0", "9"], ["a", "z"], "_"], false, true);
1040
+ var peg$e23 = peg$literalExpectation("\"", false);
1041
+ var peg$e24 = peg$classExpectation([["\0", "\x1F"], "\"", "\\"], true, false);
1042
+ var peg$e25 = peg$literalExpectation("\\", false);
1043
+ var peg$e26 = peg$literalExpectation("/", false);
1044
+ var peg$e27 = peg$literalExpectation("b", false);
1045
+ var peg$e28 = peg$literalExpectation("f", false);
1046
+ var peg$e29 = peg$literalExpectation("n", false);
1047
+ var peg$e30 = peg$literalExpectation("r", false);
1048
+ var peg$e31 = peg$literalExpectation("t", false);
1049
+ var peg$e32 = peg$literalExpectation("u", false);
1050
+ var peg$e33 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true);
1051
+ var peg$e34 = peg$literalExpectation("'", false);
1052
+ var peg$e35 = peg$classExpectation(["'", "\\"], true, false);
1053
+ var peg$e36 = peg$classExpectation(["'"], true, false);
1054
+ var peg$e37 = peg$literalExpectation("-", false);
1055
+ var peg$e38 = peg$literalExpectation("0", false);
1056
+ var peg$e39 = peg$classExpectation([["1", "9"]], false, false);
1057
+ var peg$e40 = peg$classExpectation([["0", "9"]], false, false);
1058
+ var peg$e41 = peg$literalExpectation("null", false);
1059
+ var peg$e42 = peg$literalExpectation("false", false);
1060
+ var peg$e43 = peg$literalExpectation("true", false);
1061
+ var peg$e44 = peg$classExpectation(["e", "E"], false, false);
1062
+ var peg$e45 = peg$classExpectation(["+", "-"], false, false);
1063
+ var peg$e46 = peg$classExpectation([["\0", "\x1F"], "\"", "\\", "`"], true, false);
1064
+ var peg$e47 = peg$literalExpectation("{", false);
1065
+ var peg$e48 = peg$literalExpectation(",", false);
1066
+ var peg$e49 = peg$literalExpectation("}", false);
1067
+ var peg$e50 = peg$otherExpectation("whitespace");
1068
+ var peg$e51 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false);
1069
+
1070
+ var peg$f0 = function(head, tail) { return binaryExpression("pipe", head, tail); };
1071
+ var peg$f1 = function(head, tail) { return binaryExpression("or", head, tail); };
1072
+ var peg$f2 = function(head, tail) { return binaryExpression("and", head, tail); };
1073
+ var peg$f3 = function(head, tail) {
1074
+ return tail.reduce((result, [operator, rhs]) => (
1075
+ {
1076
+ type: "compare",
1077
+ operator,
1078
+ lhs: result,
1079
+ rhs
1080
+ }
1081
+ ), head);
1082
+ };
1083
+ var peg$f4 = function(expression) { return { type: "not", expression }; };
1084
+ var peg$f5 = function(lhs, rhs) { return reduceProjection(lhs, rhs); };
1085
+ var peg$f6 = function(flatten) { return flatten({ type: "current" }); };
1086
+ var peg$f7 = function(flatten, pfns) { return (expression) => maybeProject(flatten(expression), pfns); };
1087
+ var peg$f8 = function() { return (expression) => ({ type: "flatten", expression }); };
1088
+ var peg$f9 = function(lhs, rhs) { return reduceProjection(lhs, rhs); };
1089
+ var peg$f10 = function(filter) { return filter({ type: "current" }); };
1090
+ var peg$f11 = function(filter, pfns) { return (expression) => maybeProject(filter(expression), pfns); };
1091
+ var peg$f12 = function(condition) { return (expression) => ({ type: "filter", expression, condition }); };
1092
+ var peg$f13 = function(lhs, rhs) { return reduceProjection(lhs, rhs); };
1093
+ var peg$f14 = function(projection) { return projection({ type: "current" }); };
1094
+ var peg$f15 = function(projection, pfns) { return (expression) => maybeProject(projection(expression), pfns); };
1095
+ var peg$f16 = function() { return (expression) => ({ type: "project", expression, projection: { type: "current" } }); };
1096
+ var peg$f17 = function(start, end, step) { return (expression) => ({ type: "slice", expression, start, end, step }); };
1097
+ var peg$f18 = function(lhs, rhs) { return reduceProjection(lhs, rhs); };
1098
+ var peg$f19 = function(index) { return index({ type: "current" }); };
1099
+ var peg$f20 = function(index) { return (expression) => ({ type: "indexAccess", expression, index }); };
1100
+ var peg$f21 = function(id) { return (expression) => ({ type: "idAccess", expression, id }); };
1101
+ var peg$f22 = function(field) { return (expression) => ({ type: "fieldAccess", expression, field }); };
1102
+ var peg$f23 = function(lhs, rhs) { return reduceProjection(lhs, rhs); };
1103
+ var peg$f24 = function(id) { return { type: "identifier", id }; };
1104
+ var peg$f25 = function() { return { type: "current" }; };
1105
+ var peg$f26 = function(value) { return { type: "literal", value }; };
1106
+ var peg$f27 = function(value) { return { type: "literal", value }; };
1107
+ var peg$f28 = function(head, tail) { return head + tail.join(""); };
1108
+ var peg$f29 = function(chars) { return chars.join(""); };
1109
+ var peg$f30 = function() { return "\b"; };
1110
+ var peg$f31 = function() { return "\f"; };
1111
+ var peg$f32 = function() { return "\n"; };
1112
+ var peg$f33 = function() { return "\r"; };
1113
+ var peg$f34 = function() { return "\t"; };
1114
+ var peg$f35 = function(digits) {
1115
+ return String.fromCharCode(parseInt(digits, 16));
1116
+ };
1117
+ var peg$f36 = function(chars) { return chars.join(""); };
1118
+ var peg$f37 = function() { return text(); };
1119
+ var peg$f38 = function() { return parseInt(text()); };
1120
+ var peg$f39 = function() { return null; };
1121
+ var peg$f40 = function() { return false; };
1122
+ var peg$f41 = function() { return true; };
1123
+ var peg$f42 = function() { return parseFloat(text()); };
1124
+ var peg$f43 = function(chars) { return chars.join(""); };
1125
+ var peg$f44 = function(head, tail) { return [head].concat(tail); };
1126
+ var peg$f45 = function(members) { return Object.fromEntries(members ?? []); };
1127
+ var peg$f46 = function(name, value) { return [name, value]; };
1128
+ var peg$f47 = function(head, tail) { return [head].concat(tail); };
1129
+ var peg$f48 = function(values) { return values ?? []; };
1130
+ var peg$currPos = 0;
1131
+ var peg$savedPos = 0;
1132
+ var peg$posDetailsCache = [{ line: 1, column: 1 }];
1133
+ var peg$maxFailPos = 0;
1134
+ var peg$maxFailExpected = [];
1135
+ var peg$silentFails = 0;
1136
+
1137
+ var peg$result;
1138
+
1139
+ if ("startRule" in options) {
1140
+ if (!(options.startRule in peg$startRuleFunctions)) {
1141
+ throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
1142
+ }
1143
+
1144
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
1145
+ }
1146
+
1147
+ function text() {
1148
+ return input.substring(peg$savedPos, peg$currPos);
1149
+ }
1150
+
1151
+ function peg$literalExpectation(text, ignoreCase) {
1152
+ return { type: "literal", text: text, ignoreCase: ignoreCase };
1153
+ }
1154
+
1155
+ function peg$classExpectation(parts, inverted, ignoreCase) {
1156
+ return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
1157
+ }
1158
+
1159
+ function peg$endExpectation() {
1160
+ return { type: "end" };
1161
+ }
1162
+
1163
+ function peg$otherExpectation(description) {
1164
+ return { type: "other", description: description };
1165
+ }
1166
+
1167
+ function peg$computePosDetails(pos) {
1168
+ var details = peg$posDetailsCache[pos];
1169
+ var p;
1170
+
1171
+ if (details) {
1172
+ return details;
1173
+ } else {
1174
+ p = pos - 1;
1175
+ while (!peg$posDetailsCache[p]) {
1176
+ p--;
1177
+ }
1178
+
1179
+ details = peg$posDetailsCache[p];
1180
+ details = {
1181
+ line: details.line,
1182
+ column: details.column
1183
+ };
1184
+
1185
+ while (p < pos) {
1186
+ if (input.charCodeAt(p) === 10) {
1187
+ details.line++;
1188
+ details.column = 1;
1189
+ } else {
1190
+ details.column++;
1191
+ }
1192
+
1193
+ p++;
1194
+ }
1195
+
1196
+ peg$posDetailsCache[pos] = details;
1197
+
1198
+ return details;
1199
+ }
1200
+ }
1201
+
1202
+ function peg$computeLocation(startPos, endPos) {
1203
+ var startPosDetails = peg$computePosDetails(startPos);
1204
+ var endPosDetails = peg$computePosDetails(endPos);
1205
+
1206
+ return {
1207
+ source: peg$source,
1208
+ start: {
1209
+ offset: startPos,
1210
+ line: startPosDetails.line,
1211
+ column: startPosDetails.column
1212
+ },
1213
+ end: {
1214
+ offset: endPos,
1215
+ line: endPosDetails.line,
1216
+ column: endPosDetails.column
1217
+ }
1218
+ };
1219
+ }
1220
+
1221
+ function peg$fail(expected) {
1222
+ if (peg$currPos < peg$maxFailPos) { return; }
1223
+
1224
+ if (peg$currPos > peg$maxFailPos) {
1225
+ peg$maxFailPos = peg$currPos;
1226
+ peg$maxFailExpected = [];
1227
+ }
1228
+
1229
+ peg$maxFailExpected.push(expected);
1230
+ }
1231
+
1232
+ function peg$buildStructuredError(expected, found, location) {
1233
+ return new peg$SyntaxError(
1234
+ peg$SyntaxError.buildMessage(expected, found),
1235
+ expected,
1236
+ found,
1237
+ location
1238
+ );
1239
+ }
1240
+
1241
+ function peg$parseselector() {
1242
+ var s0, s2;
1243
+
1244
+ s0 = peg$currPos;
1245
+ peg$parsews();
1246
+ s2 = peg$parsepipe_expression();
1247
+ if (s2 !== peg$FAILED) {
1248
+ peg$parsews();
1249
+ s0 = s2;
1250
+ } else {
1251
+ peg$currPos = s0;
1252
+ s0 = peg$FAILED;
1253
+ }
1254
+
1255
+ return s0;
1256
+ }
1257
+
1258
+ function peg$parsepipe_expression() {
1259
+ var s0, s1, s2, s3, s5, s7;
1260
+
1261
+ s0 = peg$currPos;
1262
+ s1 = peg$parseor_expression();
1263
+ if (s1 !== peg$FAILED) {
1264
+ s2 = [];
1265
+ s3 = peg$currPos;
1266
+ peg$parsews();
1267
+ if (input.charCodeAt(peg$currPos) === 124) {
1268
+ s5 = peg$c0;
1269
+ peg$currPos++;
1270
+ } else {
1271
+ s5 = peg$FAILED;
1272
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
1273
+ }
1274
+ if (s5 !== peg$FAILED) {
1275
+ peg$parsews();
1276
+ s7 = peg$parseor_expression();
1277
+ if (s7 !== peg$FAILED) {
1278
+ s3 = s7;
1279
+ } else {
1280
+ peg$currPos = s3;
1281
+ s3 = peg$FAILED;
1282
+ }
1283
+ } else {
1284
+ peg$currPos = s3;
1285
+ s3 = peg$FAILED;
1286
+ }
1287
+ while (s3 !== peg$FAILED) {
1288
+ s2.push(s3);
1289
+ s3 = peg$currPos;
1290
+ peg$parsews();
1291
+ if (input.charCodeAt(peg$currPos) === 124) {
1292
+ s5 = peg$c0;
1293
+ peg$currPos++;
1294
+ } else {
1295
+ s5 = peg$FAILED;
1296
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
1297
+ }
1298
+ if (s5 !== peg$FAILED) {
1299
+ peg$parsews();
1300
+ s7 = peg$parseor_expression();
1301
+ if (s7 !== peg$FAILED) {
1302
+ s3 = s7;
1303
+ } else {
1304
+ peg$currPos = s3;
1305
+ s3 = peg$FAILED;
1306
+ }
1307
+ } else {
1308
+ peg$currPos = s3;
1309
+ s3 = peg$FAILED;
1310
+ }
1311
+ }
1312
+ peg$savedPos = s0;
1313
+ s0 = peg$f0(s1, s2);
1314
+ } else {
1315
+ peg$currPos = s0;
1316
+ s0 = peg$FAILED;
1317
+ }
1318
+
1319
+ return s0;
1320
+ }
1321
+
1322
+ function peg$parseor_expression() {
1323
+ var s0, s1, s2, s3, s5, s7;
1324
+
1325
+ s0 = peg$currPos;
1326
+ s1 = peg$parseand_expression();
1327
+ if (s1 !== peg$FAILED) {
1328
+ s2 = [];
1329
+ s3 = peg$currPos;
1330
+ peg$parsews();
1331
+ if (input.substr(peg$currPos, 2) === peg$c1) {
1332
+ s5 = peg$c1;
1333
+ peg$currPos += 2;
1334
+ } else {
1335
+ s5 = peg$FAILED;
1336
+ if (peg$silentFails === 0) { peg$fail(peg$e1); }
1337
+ }
1338
+ if (s5 !== peg$FAILED) {
1339
+ peg$parsews();
1340
+ s7 = peg$parseand_expression();
1341
+ if (s7 !== peg$FAILED) {
1342
+ s3 = s7;
1343
+ } else {
1344
+ peg$currPos = s3;
1345
+ s3 = peg$FAILED;
1346
+ }
1347
+ } else {
1348
+ peg$currPos = s3;
1349
+ s3 = peg$FAILED;
1350
+ }
1351
+ while (s3 !== peg$FAILED) {
1352
+ s2.push(s3);
1353
+ s3 = peg$currPos;
1354
+ peg$parsews();
1355
+ if (input.substr(peg$currPos, 2) === peg$c1) {
1356
+ s5 = peg$c1;
1357
+ peg$currPos += 2;
1358
+ } else {
1359
+ s5 = peg$FAILED;
1360
+ if (peg$silentFails === 0) { peg$fail(peg$e1); }
1361
+ }
1362
+ if (s5 !== peg$FAILED) {
1363
+ peg$parsews();
1364
+ s7 = peg$parseand_expression();
1365
+ if (s7 !== peg$FAILED) {
1366
+ s3 = s7;
1367
+ } else {
1368
+ peg$currPos = s3;
1369
+ s3 = peg$FAILED;
1370
+ }
1371
+ } else {
1372
+ peg$currPos = s3;
1373
+ s3 = peg$FAILED;
1374
+ }
1375
+ }
1376
+ peg$savedPos = s0;
1377
+ s0 = peg$f1(s1, s2);
1378
+ } else {
1379
+ peg$currPos = s0;
1380
+ s0 = peg$FAILED;
1381
+ }
1382
+
1383
+ return s0;
1384
+ }
1385
+
1386
+ function peg$parseand_expression() {
1387
+ var s0, s1, s2, s3, s5, s7;
1388
+
1389
+ s0 = peg$currPos;
1390
+ s1 = peg$parsecompare_expression();
1391
+ if (s1 !== peg$FAILED) {
1392
+ s2 = [];
1393
+ s3 = peg$currPos;
1394
+ peg$parsews();
1395
+ if (input.substr(peg$currPos, 2) === peg$c2) {
1396
+ s5 = peg$c2;
1397
+ peg$currPos += 2;
1398
+ } else {
1399
+ s5 = peg$FAILED;
1400
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1401
+ }
1402
+ if (s5 !== peg$FAILED) {
1403
+ peg$parsews();
1404
+ s7 = peg$parsecompare_expression();
1405
+ if (s7 !== peg$FAILED) {
1406
+ s3 = s7;
1407
+ } else {
1408
+ peg$currPos = s3;
1409
+ s3 = peg$FAILED;
1410
+ }
1411
+ } else {
1412
+ peg$currPos = s3;
1413
+ s3 = peg$FAILED;
1414
+ }
1415
+ while (s3 !== peg$FAILED) {
1416
+ s2.push(s3);
1417
+ s3 = peg$currPos;
1418
+ peg$parsews();
1419
+ if (input.substr(peg$currPos, 2) === peg$c2) {
1420
+ s5 = peg$c2;
1421
+ peg$currPos += 2;
1422
+ } else {
1423
+ s5 = peg$FAILED;
1424
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1425
+ }
1426
+ if (s5 !== peg$FAILED) {
1427
+ peg$parsews();
1428
+ s7 = peg$parsecompare_expression();
1429
+ if (s7 !== peg$FAILED) {
1430
+ s3 = s7;
1431
+ } else {
1432
+ peg$currPos = s3;
1433
+ s3 = peg$FAILED;
1434
+ }
1435
+ } else {
1436
+ peg$currPos = s3;
1437
+ s3 = peg$FAILED;
1438
+ }
1439
+ }
1440
+ peg$savedPos = s0;
1441
+ s0 = peg$f2(s1, s2);
1442
+ } else {
1443
+ peg$currPos = s0;
1444
+ s0 = peg$FAILED;
1445
+ }
1446
+
1447
+ return s0;
1448
+ }
1449
+
1450
+ function peg$parsecompare_expression() {
1451
+ var s0, s1, s2, s3, s5, s7;
1452
+
1453
+ s0 = peg$currPos;
1454
+ s1 = peg$parsenot_expression();
1455
+ if (s1 !== peg$FAILED) {
1456
+ s2 = [];
1457
+ s3 = peg$currPos;
1458
+ peg$parsews();
1459
+ if (input.substr(peg$currPos, 2) === peg$c3) {
1460
+ s5 = peg$c3;
1461
+ peg$currPos += 2;
1462
+ } else {
1463
+ s5 = peg$FAILED;
1464
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
1465
+ }
1466
+ if (s5 === peg$FAILED) {
1467
+ if (input.substr(peg$currPos, 2) === peg$c4) {
1468
+ s5 = peg$c4;
1469
+ peg$currPos += 2;
1470
+ } else {
1471
+ s5 = peg$FAILED;
1472
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
1473
+ }
1474
+ if (s5 === peg$FAILED) {
1475
+ if (input.charCodeAt(peg$currPos) === 60) {
1476
+ s5 = peg$c5;
1477
+ peg$currPos++;
1478
+ } else {
1479
+ s5 = peg$FAILED;
1480
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
1481
+ }
1482
+ if (s5 === peg$FAILED) {
1483
+ if (input.charCodeAt(peg$currPos) === 62) {
1484
+ s5 = peg$c6;
1485
+ peg$currPos++;
1486
+ } else {
1487
+ s5 = peg$FAILED;
1488
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
1489
+ }
1490
+ if (s5 === peg$FAILED) {
1491
+ if (input.substr(peg$currPos, 2) === peg$c7) {
1492
+ s5 = peg$c7;
1493
+ peg$currPos += 2;
1494
+ } else {
1495
+ s5 = peg$FAILED;
1496
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
1497
+ }
1498
+ if (s5 === peg$FAILED) {
1499
+ if (input.substr(peg$currPos, 2) === peg$c8) {
1500
+ s5 = peg$c8;
1501
+ peg$currPos += 2;
1502
+ } else {
1503
+ s5 = peg$FAILED;
1504
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
1505
+ }
1506
+ }
1507
+ }
1508
+ }
1509
+ }
1510
+ }
1511
+ if (s5 !== peg$FAILED) {
1512
+ peg$parsews();
1513
+ s7 = peg$parsenot_expression();
1514
+ if (s7 !== peg$FAILED) {
1515
+ s3 = [ s5, s7 ];
1516
+ } else {
1517
+ peg$currPos = s3;
1518
+ s3 = peg$FAILED;
1519
+ }
1520
+ } else {
1521
+ peg$currPos = s3;
1522
+ s3 = peg$FAILED;
1523
+ }
1524
+ while (s3 !== peg$FAILED) {
1525
+ s2.push(s3);
1526
+ s3 = peg$currPos;
1527
+ peg$parsews();
1528
+ if (input.substr(peg$currPos, 2) === peg$c3) {
1529
+ s5 = peg$c3;
1530
+ peg$currPos += 2;
1531
+ } else {
1532
+ s5 = peg$FAILED;
1533
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
1534
+ }
1535
+ if (s5 === peg$FAILED) {
1536
+ if (input.substr(peg$currPos, 2) === peg$c4) {
1537
+ s5 = peg$c4;
1538
+ peg$currPos += 2;
1539
+ } else {
1540
+ s5 = peg$FAILED;
1541
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
1542
+ }
1543
+ if (s5 === peg$FAILED) {
1544
+ if (input.charCodeAt(peg$currPos) === 60) {
1545
+ s5 = peg$c5;
1546
+ peg$currPos++;
1547
+ } else {
1548
+ s5 = peg$FAILED;
1549
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
1550
+ }
1551
+ if (s5 === peg$FAILED) {
1552
+ if (input.charCodeAt(peg$currPos) === 62) {
1553
+ s5 = peg$c6;
1554
+ peg$currPos++;
1555
+ } else {
1556
+ s5 = peg$FAILED;
1557
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
1558
+ }
1559
+ if (s5 === peg$FAILED) {
1560
+ if (input.substr(peg$currPos, 2) === peg$c7) {
1561
+ s5 = peg$c7;
1562
+ peg$currPos += 2;
1563
+ } else {
1564
+ s5 = peg$FAILED;
1565
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
1566
+ }
1567
+ if (s5 === peg$FAILED) {
1568
+ if (input.substr(peg$currPos, 2) === peg$c8) {
1569
+ s5 = peg$c8;
1570
+ peg$currPos += 2;
1571
+ } else {
1572
+ s5 = peg$FAILED;
1573
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
1574
+ }
1575
+ }
1576
+ }
1577
+ }
1578
+ }
1579
+ }
1580
+ if (s5 !== peg$FAILED) {
1581
+ peg$parsews();
1582
+ s7 = peg$parsenot_expression();
1583
+ if (s7 !== peg$FAILED) {
1584
+ s3 = [ s5, s7 ];
1585
+ } else {
1586
+ peg$currPos = s3;
1587
+ s3 = peg$FAILED;
1588
+ }
1589
+ } else {
1590
+ peg$currPos = s3;
1591
+ s3 = peg$FAILED;
1592
+ }
1593
+ }
1594
+ peg$savedPos = s0;
1595
+ s0 = peg$f3(s1, s2);
1596
+ } else {
1597
+ peg$currPos = s0;
1598
+ s0 = peg$FAILED;
1599
+ }
1600
+
1601
+ return s0;
1602
+ }
1603
+
1604
+ function peg$parsenot_expression() {
1605
+ var s0, s1, s2;
1606
+
1607
+ s0 = peg$currPos;
1608
+ if (input.charCodeAt(peg$currPos) === 33) {
1609
+ s1 = peg$c9;
1610
+ peg$currPos++;
1611
+ } else {
1612
+ s1 = peg$FAILED;
1613
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
1614
+ }
1615
+ if (s1 !== peg$FAILED) {
1616
+ s2 = peg$parsenot_expression();
1617
+ if (s2 !== peg$FAILED) {
1618
+ peg$savedPos = s0;
1619
+ s0 = peg$f4(s2);
1620
+ } else {
1621
+ peg$currPos = s0;
1622
+ s0 = peg$FAILED;
1623
+ }
1624
+ } else {
1625
+ peg$currPos = s0;
1626
+ s0 = peg$FAILED;
1627
+ }
1628
+ if (s0 === peg$FAILED) {
1629
+ s0 = peg$parseflatten_expression();
1630
+ }
1631
+
1632
+ return s0;
1633
+ }
1634
+
1635
+ function peg$parseflatten_expression() {
1636
+ var s0, s1, s2, s3;
1637
+
1638
+ s0 = peg$currPos;
1639
+ s1 = peg$parseflatten_lhs();
1640
+ if (s1 !== peg$FAILED) {
1641
+ s2 = [];
1642
+ s3 = peg$parseflatten_rhs();
1643
+ while (s3 !== peg$FAILED) {
1644
+ s2.push(s3);
1645
+ s3 = peg$parseflatten_rhs();
1646
+ }
1647
+ peg$savedPos = s0;
1648
+ s0 = peg$f5(s1, s2);
1649
+ } else {
1650
+ peg$currPos = s0;
1651
+ s0 = peg$FAILED;
1652
+ }
1653
+
1654
+ return s0;
1655
+ }
1656
+
1657
+ function peg$parseflatten_lhs() {
1658
+ var s0, s1;
1659
+
1660
+ s0 = peg$currPos;
1661
+ s1 = peg$parseflatten();
1662
+ if (s1 !== peg$FAILED) {
1663
+ peg$savedPos = s0;
1664
+ s1 = peg$f6(s1);
1665
+ }
1666
+ s0 = s1;
1667
+ if (s0 === peg$FAILED) {
1668
+ s0 = peg$parsefilter_expression();
1669
+ }
1670
+
1671
+ return s0;
1672
+ }
1673
+
1674
+ function peg$parseflatten_rhs() {
1675
+ var s0, s1, s2, s3;
1676
+
1677
+ s0 = peg$currPos;
1678
+ s1 = peg$parseflatten();
1679
+ if (s1 !== peg$FAILED) {
1680
+ s2 = [];
1681
+ s3 = peg$parsefilter_rhs();
1682
+ while (s3 !== peg$FAILED) {
1683
+ s2.push(s3);
1684
+ s3 = peg$parsefilter_rhs();
1685
+ }
1686
+ peg$savedPos = s0;
1687
+ s0 = peg$f7(s1, s2);
1688
+ } else {
1689
+ peg$currPos = s0;
1690
+ s0 = peg$FAILED;
1691
+ }
1692
+ if (s0 === peg$FAILED) {
1693
+ s0 = peg$parsefilter_rhs();
1694
+ }
1695
+
1696
+ return s0;
1697
+ }
1698
+
1699
+ function peg$parseflatten() {
1700
+ var s0, s2;
1701
+
1702
+ s0 = peg$currPos;
1703
+ peg$parsews();
1704
+ if (input.substr(peg$currPos, 2) === peg$c10) {
1705
+ s2 = peg$c10;
1706
+ peg$currPos += 2;
1707
+ } else {
1708
+ s2 = peg$FAILED;
1709
+ if (peg$silentFails === 0) { peg$fail(peg$e10); }
1710
+ }
1711
+ if (s2 !== peg$FAILED) {
1712
+ peg$savedPos = s0;
1713
+ s0 = peg$f8();
1714
+ } else {
1715
+ peg$currPos = s0;
1716
+ s0 = peg$FAILED;
1717
+ }
1718
+
1719
+ return s0;
1720
+ }
1721
+
1722
+ function peg$parsefilter_expression() {
1723
+ var s0, s1, s2, s3;
1724
+
1725
+ s0 = peg$currPos;
1726
+ s1 = peg$parsefilter_lhs();
1727
+ if (s1 !== peg$FAILED) {
1728
+ s2 = [];
1729
+ s3 = peg$parsefilter_rhs();
1730
+ while (s3 !== peg$FAILED) {
1731
+ s2.push(s3);
1732
+ s3 = peg$parsefilter_rhs();
1733
+ }
1734
+ peg$savedPos = s0;
1735
+ s0 = peg$f9(s1, s2);
1736
+ } else {
1737
+ peg$currPos = s0;
1738
+ s0 = peg$FAILED;
1739
+ }
1740
+
1741
+ return s0;
1742
+ }
1743
+
1744
+ function peg$parsefilter_lhs() {
1745
+ var s0, s1;
1746
+
1747
+ s0 = peg$currPos;
1748
+ s1 = peg$parsefilter();
1749
+ if (s1 !== peg$FAILED) {
1750
+ peg$savedPos = s0;
1751
+ s1 = peg$f10(s1);
1752
+ }
1753
+ s0 = s1;
1754
+ if (s0 === peg$FAILED) {
1755
+ s0 = peg$parseprojection_expression();
1756
+ }
1757
+
1758
+ return s0;
1759
+ }
1760
+
1761
+ function peg$parsefilter_rhs() {
1762
+ var s0, s1, s2, s3;
1763
+
1764
+ s0 = peg$currPos;
1765
+ s1 = peg$parsefilter();
1766
+ if (s1 !== peg$FAILED) {
1767
+ s2 = [];
1768
+ s3 = peg$parsefilter_rhs();
1769
+ while (s3 !== peg$FAILED) {
1770
+ s2.push(s3);
1771
+ s3 = peg$parsefilter_rhs();
1772
+ }
1773
+ peg$savedPos = s0;
1774
+ s0 = peg$f11(s1, s2);
1775
+ } else {
1776
+ peg$currPos = s0;
1777
+ s0 = peg$FAILED;
1778
+ }
1779
+ if (s0 === peg$FAILED) {
1780
+ s0 = peg$parseprojection_rhs();
1781
+ if (s0 === peg$FAILED) {
1782
+ s0 = peg$parsedot_rhs();
1783
+ }
1784
+ }
1785
+
1786
+ return s0;
1787
+ }
1788
+
1789
+ function peg$parsefilter() {
1790
+ var s0, s2, s3, s4;
1791
+
1792
+ s0 = peg$currPos;
1793
+ peg$parsews();
1794
+ if (input.substr(peg$currPos, 2) === peg$c11) {
1795
+ s2 = peg$c11;
1796
+ peg$currPos += 2;
1797
+ } else {
1798
+ s2 = peg$FAILED;
1799
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
1800
+ }
1801
+ if (s2 !== peg$FAILED) {
1802
+ s3 = peg$parseselector();
1803
+ if (s3 !== peg$FAILED) {
1804
+ if (input.charCodeAt(peg$currPos) === 93) {
1805
+ s4 = peg$c12;
1806
+ peg$currPos++;
1807
+ } else {
1808
+ s4 = peg$FAILED;
1809
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1810
+ }
1811
+ if (s4 !== peg$FAILED) {
1812
+ peg$savedPos = s0;
1813
+ s0 = peg$f12(s3);
1814
+ } else {
1815
+ peg$currPos = s0;
1816
+ s0 = peg$FAILED;
1817
+ }
1818
+ } else {
1819
+ peg$currPos = s0;
1820
+ s0 = peg$FAILED;
1821
+ }
1822
+ } else {
1823
+ peg$currPos = s0;
1824
+ s0 = peg$FAILED;
1825
+ }
1826
+
1827
+ return s0;
1828
+ }
1829
+
1830
+ function peg$parseprojection_expression() {
1831
+ var s0, s1, s2, s3;
1832
+
1833
+ s0 = peg$currPos;
1834
+ s1 = peg$parseprojection_lhs();
1835
+ if (s1 !== peg$FAILED) {
1836
+ s2 = [];
1837
+ s3 = peg$parseprojection_rhs();
1838
+ while (s3 !== peg$FAILED) {
1839
+ s2.push(s3);
1840
+ s3 = peg$parseprojection_rhs();
1841
+ }
1842
+ peg$savedPos = s0;
1843
+ s0 = peg$f13(s1, s2);
1844
+ } else {
1845
+ peg$currPos = s0;
1846
+ s0 = peg$FAILED;
1847
+ }
1848
+
1849
+ return s0;
1850
+ }
1851
+
1852
+ function peg$parseprojection_lhs() {
1853
+ var s0, s1;
1854
+
1855
+ s0 = peg$currPos;
1856
+ s1 = peg$parseprojection();
1857
+ if (s1 !== peg$FAILED) {
1858
+ peg$savedPos = s0;
1859
+ s1 = peg$f14(s1);
1860
+ }
1861
+ s0 = s1;
1862
+ if (s0 === peg$FAILED) {
1863
+ s0 = peg$parseindex_expression();
1864
+ }
1865
+
1866
+ return s0;
1867
+ }
1868
+
1869
+ function peg$parseprojection_rhs() {
1870
+ var s0, s1, s2, s3;
1871
+
1872
+ s0 = peg$currPos;
1873
+ s1 = peg$parseprojection();
1874
+ if (s1 !== peg$FAILED) {
1875
+ s2 = [];
1876
+ s3 = peg$parsefilter_rhs();
1877
+ while (s3 !== peg$FAILED) {
1878
+ s2.push(s3);
1879
+ s3 = peg$parsefilter_rhs();
1880
+ }
1881
+ peg$savedPos = s0;
1882
+ s0 = peg$f15(s1, s2);
1883
+ } else {
1884
+ peg$currPos = s0;
1885
+ s0 = peg$FAILED;
1886
+ }
1887
+ if (s0 === peg$FAILED) {
1888
+ s0 = peg$parseindex_rhs();
1889
+ }
1890
+
1891
+ return s0;
1892
+ }
1893
+
1894
+ function peg$parseprojection() {
1895
+ var s0, s2, s4, s6;
1896
+
1897
+ s0 = peg$currPos;
1898
+ peg$parsews();
1899
+ if (input.charCodeAt(peg$currPos) === 91) {
1900
+ s2 = peg$c13;
1901
+ peg$currPos++;
1902
+ } else {
1903
+ s2 = peg$FAILED;
1904
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1905
+ }
1906
+ if (s2 !== peg$FAILED) {
1907
+ peg$parsews();
1908
+ if (input.charCodeAt(peg$currPos) === 42) {
1909
+ s4 = peg$c14;
1910
+ peg$currPos++;
1911
+ } else {
1912
+ s4 = peg$FAILED;
1913
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1914
+ }
1915
+ if (s4 !== peg$FAILED) {
1916
+ peg$parsews();
1917
+ if (input.charCodeAt(peg$currPos) === 93) {
1918
+ s6 = peg$c12;
1919
+ peg$currPos++;
1920
+ } else {
1921
+ s6 = peg$FAILED;
1922
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1923
+ }
1924
+ if (s6 !== peg$FAILED) {
1925
+ peg$savedPos = s0;
1926
+ s0 = peg$f16();
1927
+ } else {
1928
+ peg$currPos = s0;
1929
+ s0 = peg$FAILED;
1930
+ }
1931
+ } else {
1932
+ peg$currPos = s0;
1933
+ s0 = peg$FAILED;
1934
+ }
1935
+ } else {
1936
+ peg$currPos = s0;
1937
+ s0 = peg$FAILED;
1938
+ }
1939
+ if (s0 === peg$FAILED) {
1940
+ s0 = peg$currPos;
1941
+ peg$parsews();
1942
+ if (input.charCodeAt(peg$currPos) === 91) {
1943
+ s2 = peg$c13;
1944
+ peg$currPos++;
1945
+ } else {
1946
+ s2 = peg$FAILED;
1947
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1948
+ }
1949
+ if (s2 !== peg$FAILED) {
1950
+ peg$parsews();
1951
+ s4 = peg$parseslice();
1952
+ if (s4 !== peg$FAILED) {
1953
+ peg$parsews();
1954
+ if (input.charCodeAt(peg$currPos) === 93) {
1955
+ s6 = peg$c12;
1956
+ peg$currPos++;
1957
+ } else {
1958
+ s6 = peg$FAILED;
1959
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1960
+ }
1961
+ if (s6 !== peg$FAILED) {
1962
+ s0 = s4;
1963
+ } else {
1964
+ peg$currPos = s0;
1965
+ s0 = peg$FAILED;
1966
+ }
1967
+ } else {
1968
+ peg$currPos = s0;
1969
+ s0 = peg$FAILED;
1970
+ }
1971
+ } else {
1972
+ peg$currPos = s0;
1973
+ s0 = peg$FAILED;
1974
+ }
1975
+ }
1976
+
1977
+ return s0;
1978
+ }
1979
+
1980
+ function peg$parseslice() {
1981
+ var s0, s1, s3, s5, s9;
1982
+
1983
+ s0 = peg$currPos;
1984
+ s1 = peg$parsenumber();
1985
+ if (s1 === peg$FAILED) {
1986
+ s1 = null;
1987
+ }
1988
+ peg$parsews();
1989
+ if (input.charCodeAt(peg$currPos) === 58) {
1990
+ s3 = peg$c15;
1991
+ peg$currPos++;
1992
+ } else {
1993
+ s3 = peg$FAILED;
1994
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
1995
+ }
1996
+ if (s3 !== peg$FAILED) {
1997
+ peg$parsews();
1998
+ s5 = peg$parsenumber();
1999
+ if (s5 === peg$FAILED) {
2000
+ s5 = null;
2001
+ }
2002
+ peg$parsews();
2003
+ if (input.charCodeAt(peg$currPos) === 58) {
2004
+ peg$currPos++;
2005
+ } else {
2006
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
2007
+ }
2008
+ peg$parsews();
2009
+ s9 = peg$parsenumber();
2010
+ if (s9 === peg$FAILED) {
2011
+ s9 = null;
2012
+ }
2013
+ peg$savedPos = s0;
2014
+ s0 = peg$f17(s1, s5, s9);
2015
+ } else {
2016
+ peg$currPos = s0;
2017
+ s0 = peg$FAILED;
2018
+ }
2019
+
2020
+ return s0;
2021
+ }
2022
+
2023
+ function peg$parseindex_expression() {
2024
+ var s0, s1, s2, s3;
2025
+
2026
+ s0 = peg$currPos;
2027
+ s1 = peg$parseindex_lhs();
2028
+ if (s1 !== peg$FAILED) {
2029
+ s2 = [];
2030
+ s3 = peg$parseindex_rhs();
2031
+ while (s3 !== peg$FAILED) {
2032
+ s2.push(s3);
2033
+ s3 = peg$parseindex_rhs();
2034
+ }
2035
+ peg$savedPos = s0;
2036
+ s0 = peg$f18(s1, s2);
2037
+ } else {
2038
+ peg$currPos = s0;
2039
+ s0 = peg$FAILED;
2040
+ }
2041
+
2042
+ return s0;
2043
+ }
2044
+
2045
+ function peg$parseindex_lhs() {
2046
+ var s0, s1;
2047
+
2048
+ s0 = peg$currPos;
2049
+ s1 = peg$parseindex_rhs();
2050
+ if (s1 !== peg$FAILED) {
2051
+ peg$savedPos = s0;
2052
+ s1 = peg$f19(s1);
2053
+ }
2054
+ s0 = s1;
2055
+ if (s0 === peg$FAILED) {
2056
+ s0 = peg$parsemember_expression();
2057
+ }
2058
+
2059
+ return s0;
2060
+ }
2061
+
2062
+ function peg$parseindex_rhs() {
2063
+ var s0, s2, s4, s6;
2064
+
2065
+ s0 = peg$currPos;
2066
+ peg$parsews();
2067
+ if (input.charCodeAt(peg$currPos) === 91) {
2068
+ s2 = peg$c13;
2069
+ peg$currPos++;
2070
+ } else {
2071
+ s2 = peg$FAILED;
2072
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
2073
+ }
2074
+ if (s2 !== peg$FAILED) {
2075
+ peg$parsews();
2076
+ s4 = peg$parsenumber();
2077
+ if (s4 !== peg$FAILED) {
2078
+ peg$parsews();
2079
+ if (input.charCodeAt(peg$currPos) === 93) {
2080
+ s6 = peg$c12;
2081
+ peg$currPos++;
2082
+ } else {
2083
+ s6 = peg$FAILED;
2084
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
2085
+ }
2086
+ if (s6 !== peg$FAILED) {
2087
+ peg$savedPos = s0;
2088
+ s0 = peg$f20(s4);
2089
+ } else {
2090
+ peg$currPos = s0;
2091
+ s0 = peg$FAILED;
2092
+ }
2093
+ } else {
2094
+ peg$currPos = s0;
2095
+ s0 = peg$FAILED;
2096
+ }
2097
+ } else {
2098
+ peg$currPos = s0;
2099
+ s0 = peg$FAILED;
2100
+ }
2101
+ if (s0 === peg$FAILED) {
2102
+ s0 = peg$currPos;
2103
+ peg$parsews();
2104
+ if (input.charCodeAt(peg$currPos) === 91) {
2105
+ s2 = peg$c13;
2106
+ peg$currPos++;
2107
+ } else {
2108
+ s2 = peg$FAILED;
2109
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
2110
+ }
2111
+ if (s2 !== peg$FAILED) {
2112
+ peg$parsews();
2113
+ s4 = peg$parseraw_string();
2114
+ if (s4 !== peg$FAILED) {
2115
+ peg$parsews();
2116
+ if (input.charCodeAt(peg$currPos) === 93) {
2117
+ s6 = peg$c12;
2118
+ peg$currPos++;
2119
+ } else {
2120
+ s6 = peg$FAILED;
2121
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
2122
+ }
2123
+ if (s6 !== peg$FAILED) {
2124
+ peg$savedPos = s0;
2125
+ s0 = peg$f21(s4);
2126
+ } else {
2127
+ peg$currPos = s0;
2128
+ s0 = peg$FAILED;
2129
+ }
2130
+ } else {
2131
+ peg$currPos = s0;
2132
+ s0 = peg$FAILED;
2133
+ }
2134
+ } else {
2135
+ peg$currPos = s0;
2136
+ s0 = peg$FAILED;
2137
+ }
2138
+ }
2139
+
2140
+ return s0;
2141
+ }
2142
+
2143
+ function peg$parsedot_rhs() {
2144
+ var s0, s2, s4;
2145
+
2146
+ s0 = peg$currPos;
2147
+ peg$parsews();
2148
+ if (input.charCodeAt(peg$currPos) === 46) {
2149
+ s2 = peg$c16;
2150
+ peg$currPos++;
2151
+ } else {
2152
+ s2 = peg$FAILED;
2153
+ if (peg$silentFails === 0) { peg$fail(peg$e16); }
2154
+ }
2155
+ if (s2 !== peg$FAILED) {
2156
+ peg$parsews();
2157
+ s4 = peg$parseidentifier();
2158
+ if (s4 !== peg$FAILED) {
2159
+ peg$savedPos = s0;
2160
+ s0 = peg$f22(s4);
2161
+ } else {
2162
+ peg$currPos = s0;
2163
+ s0 = peg$FAILED;
2164
+ }
2165
+ } else {
2166
+ peg$currPos = s0;
2167
+ s0 = peg$FAILED;
2168
+ }
2169
+
2170
+ return s0;
2171
+ }
2172
+
2173
+ function peg$parsemember_expression() {
2174
+ var s0, s1, s2, s3;
2175
+
2176
+ s0 = peg$currPos;
2177
+ s1 = peg$parseprimary_expression();
2178
+ if (s1 !== peg$FAILED) {
2179
+ s2 = [];
2180
+ s3 = peg$parsedot_rhs();
2181
+ while (s3 !== peg$FAILED) {
2182
+ s2.push(s3);
2183
+ s3 = peg$parsedot_rhs();
2184
+ }
2185
+ peg$savedPos = s0;
2186
+ s0 = peg$f23(s1, s2);
2187
+ } else {
2188
+ peg$currPos = s0;
2189
+ s0 = peg$FAILED;
2190
+ }
2191
+
2192
+ return s0;
2193
+ }
2194
+
2195
+ function peg$parseprimary_expression() {
2196
+ var s0, s1, s2, s3;
2197
+
2198
+ s0 = peg$currPos;
2199
+ s1 = peg$parseidentifier();
2200
+ if (s1 !== peg$FAILED) {
2201
+ peg$savedPos = s0;
2202
+ s1 = peg$f24(s1);
2203
+ }
2204
+ s0 = s1;
2205
+ if (s0 === peg$FAILED) {
2206
+ s0 = peg$currPos;
2207
+ if (input.charCodeAt(peg$currPos) === 64) {
2208
+ s1 = peg$c17;
2209
+ peg$currPos++;
2210
+ } else {
2211
+ s1 = peg$FAILED;
2212
+ if (peg$silentFails === 0) { peg$fail(peg$e17); }
2213
+ }
2214
+ if (s1 !== peg$FAILED) {
2215
+ peg$savedPos = s0;
2216
+ s1 = peg$f25();
2217
+ }
2218
+ s0 = s1;
2219
+ if (s0 === peg$FAILED) {
2220
+ s0 = peg$parseliteral();
2221
+ if (s0 === peg$FAILED) {
2222
+ s0 = peg$currPos;
2223
+ s1 = peg$parseraw_string();
2224
+ if (s1 !== peg$FAILED) {
2225
+ peg$savedPos = s0;
2226
+ s1 = peg$f26(s1);
2227
+ }
2228
+ s0 = s1;
2229
+ if (s0 === peg$FAILED) {
2230
+ s0 = peg$currPos;
2231
+ if (input.charCodeAt(peg$currPos) === 40) {
2232
+ s1 = peg$c18;
2233
+ peg$currPos++;
2234
+ } else {
2235
+ s1 = peg$FAILED;
2236
+ if (peg$silentFails === 0) { peg$fail(peg$e18); }
2237
+ }
2238
+ if (s1 !== peg$FAILED) {
2239
+ s2 = peg$parseselector();
2240
+ if (s2 !== peg$FAILED) {
2241
+ if (input.charCodeAt(peg$currPos) === 41) {
2242
+ s3 = peg$c19;
2243
+ peg$currPos++;
2244
+ } else {
2245
+ s3 = peg$FAILED;
2246
+ if (peg$silentFails === 0) { peg$fail(peg$e19); }
2247
+ }
2248
+ if (s3 !== peg$FAILED) {
2249
+ s0 = s2;
2250
+ } else {
2251
+ peg$currPos = s0;
2252
+ s0 = peg$FAILED;
2253
+ }
2254
+ } else {
2255
+ peg$currPos = s0;
2256
+ s0 = peg$FAILED;
2257
+ }
2258
+ } else {
2259
+ peg$currPos = s0;
2260
+ s0 = peg$FAILED;
2261
+ }
2262
+ }
2263
+ }
2264
+ }
2265
+ }
2266
+
2267
+ return s0;
2268
+ }
2269
+
2270
+ function peg$parseliteral() {
2271
+ var s0, s1, s3, s5;
2272
+
2273
+ s0 = peg$currPos;
2274
+ if (input.charCodeAt(peg$currPos) === 96) {
2275
+ s1 = peg$c20;
2276
+ peg$currPos++;
2277
+ } else {
2278
+ s1 = peg$FAILED;
2279
+ if (peg$silentFails === 0) { peg$fail(peg$e20); }
2280
+ }
2281
+ if (s1 !== peg$FAILED) {
2282
+ peg$parsews();
2283
+ s3 = peg$parsejson_value();
2284
+ if (s3 === peg$FAILED) {
2285
+ s3 = peg$parseunquoted_json_string();
2286
+ }
2287
+ if (s3 !== peg$FAILED) {
2288
+ peg$parsews();
2289
+ if (input.charCodeAt(peg$currPos) === 96) {
2290
+ s5 = peg$c20;
2291
+ peg$currPos++;
2292
+ } else {
2293
+ s5 = peg$FAILED;
2294
+ if (peg$silentFails === 0) { peg$fail(peg$e20); }
2295
+ }
2296
+ if (s5 !== peg$FAILED) {
2297
+ peg$savedPos = s0;
2298
+ s0 = peg$f27(s3);
2299
+ } else {
2300
+ peg$currPos = s0;
2301
+ s0 = peg$FAILED;
2302
+ }
2303
+ } else {
2304
+ peg$currPos = s0;
2305
+ s0 = peg$FAILED;
2306
+ }
2307
+ } else {
2308
+ peg$currPos = s0;
2309
+ s0 = peg$FAILED;
2310
+ }
2311
+
2312
+ return s0;
2313
+ }
2314
+
2315
+ function peg$parseidentifier() {
2316
+ var s0;
2317
+
2318
+ s0 = peg$parseunquoted_string();
2319
+ if (s0 === peg$FAILED) {
2320
+ s0 = peg$parsequoted_string();
2321
+ }
2322
+
2323
+ return s0;
2324
+ }
2325
+
2326
+ function peg$parseunquoted_string() {
2327
+ var s0, s1, s2, s3;
2328
+
2329
+ s0 = peg$currPos;
2330
+ if (peg$r0.test(input.charAt(peg$currPos))) {
2331
+ s1 = input.charAt(peg$currPos);
2332
+ peg$currPos++;
2333
+ } else {
2334
+ s1 = peg$FAILED;
2335
+ if (peg$silentFails === 0) { peg$fail(peg$e21); }
2336
+ }
2337
+ if (s1 !== peg$FAILED) {
2338
+ s2 = [];
2339
+ if (peg$r1.test(input.charAt(peg$currPos))) {
2340
+ s3 = input.charAt(peg$currPos);
2341
+ peg$currPos++;
2342
+ } else {
2343
+ s3 = peg$FAILED;
2344
+ if (peg$silentFails === 0) { peg$fail(peg$e22); }
2345
+ }
2346
+ while (s3 !== peg$FAILED) {
2347
+ s2.push(s3);
2348
+ if (peg$r1.test(input.charAt(peg$currPos))) {
2349
+ s3 = input.charAt(peg$currPos);
2350
+ peg$currPos++;
2351
+ } else {
2352
+ s3 = peg$FAILED;
2353
+ if (peg$silentFails === 0) { peg$fail(peg$e22); }
2354
+ }
2355
+ }
2356
+ peg$savedPos = s0;
2357
+ s0 = peg$f28(s1, s2);
2358
+ } else {
2359
+ peg$currPos = s0;
2360
+ s0 = peg$FAILED;
2361
+ }
2362
+
2363
+ return s0;
2364
+ }
2365
+
2366
+ function peg$parsequoted_string() {
2367
+ var s0, s1, s2, s3;
2368
+
2369
+ s0 = peg$currPos;
2370
+ if (input.charCodeAt(peg$currPos) === 34) {
2371
+ s1 = peg$c21;
2372
+ peg$currPos++;
2373
+ } else {
2374
+ s1 = peg$FAILED;
2375
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
2376
+ }
2377
+ if (s1 !== peg$FAILED) {
2378
+ s2 = [];
2379
+ s3 = peg$parsechar();
2380
+ while (s3 !== peg$FAILED) {
2381
+ s2.push(s3);
2382
+ s3 = peg$parsechar();
2383
+ }
2384
+ if (input.charCodeAt(peg$currPos) === 34) {
2385
+ s3 = peg$c21;
2386
+ peg$currPos++;
2387
+ } else {
2388
+ s3 = peg$FAILED;
2389
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
2390
+ }
2391
+ if (s3 !== peg$FAILED) {
2392
+ peg$savedPos = s0;
2393
+ s0 = peg$f29(s2);
2394
+ } else {
2395
+ peg$currPos = s0;
2396
+ s0 = peg$FAILED;
2397
+ }
2398
+ } else {
2399
+ peg$currPos = s0;
2400
+ s0 = peg$FAILED;
2401
+ }
2402
+
2403
+ return s0;
2404
+ }
2405
+
2406
+ function peg$parsechar() {
2407
+ var s0;
2408
+
2409
+ s0 = peg$parseunescaped_char();
2410
+ if (s0 === peg$FAILED) {
2411
+ s0 = peg$parseescaped_char();
2412
+ }
2413
+
2414
+ return s0;
2415
+ }
2416
+
2417
+ function peg$parseunescaped_char() {
2418
+ var s0;
2419
+
2420
+ if (peg$r2.test(input.charAt(peg$currPos))) {
2421
+ s0 = input.charAt(peg$currPos);
2422
+ peg$currPos++;
2423
+ } else {
2424
+ s0 = peg$FAILED;
2425
+ if (peg$silentFails === 0) { peg$fail(peg$e24); }
2426
+ }
2427
+
2428
+ return s0;
2429
+ }
2430
+
2431
+ function peg$parseescaped_char() {
2432
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
2433
+
2434
+ s0 = peg$currPos;
2435
+ if (input.charCodeAt(peg$currPos) === 92) {
2436
+ s1 = peg$c22;
2437
+ peg$currPos++;
2438
+ } else {
2439
+ s1 = peg$FAILED;
2440
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2441
+ }
2442
+ if (s1 !== peg$FAILED) {
2443
+ if (input.charCodeAt(peg$currPos) === 34) {
2444
+ s2 = peg$c21;
2445
+ peg$currPos++;
2446
+ } else {
2447
+ s2 = peg$FAILED;
2448
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
2449
+ }
2450
+ if (s2 === peg$FAILED) {
2451
+ if (input.charCodeAt(peg$currPos) === 92) {
2452
+ s2 = peg$c22;
2453
+ peg$currPos++;
2454
+ } else {
2455
+ s2 = peg$FAILED;
2456
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2457
+ }
2458
+ if (s2 === peg$FAILED) {
2459
+ if (input.charCodeAt(peg$currPos) === 47) {
2460
+ s2 = peg$c23;
2461
+ peg$currPos++;
2462
+ } else {
2463
+ s2 = peg$FAILED;
2464
+ if (peg$silentFails === 0) { peg$fail(peg$e26); }
2465
+ }
2466
+ if (s2 === peg$FAILED) {
2467
+ s2 = peg$currPos;
2468
+ if (input.charCodeAt(peg$currPos) === 98) {
2469
+ s3 = peg$c24;
2470
+ peg$currPos++;
2471
+ } else {
2472
+ s3 = peg$FAILED;
2473
+ if (peg$silentFails === 0) { peg$fail(peg$e27); }
2474
+ }
2475
+ if (s3 !== peg$FAILED) {
2476
+ peg$savedPos = s2;
2477
+ s3 = peg$f30();
2478
+ }
2479
+ s2 = s3;
2480
+ if (s2 === peg$FAILED) {
2481
+ s2 = peg$currPos;
2482
+ if (input.charCodeAt(peg$currPos) === 102) {
2483
+ s3 = peg$c25;
2484
+ peg$currPos++;
2485
+ } else {
2486
+ s3 = peg$FAILED;
2487
+ if (peg$silentFails === 0) { peg$fail(peg$e28); }
2488
+ }
2489
+ if (s3 !== peg$FAILED) {
2490
+ peg$savedPos = s2;
2491
+ s3 = peg$f31();
2492
+ }
2493
+ s2 = s3;
2494
+ if (s2 === peg$FAILED) {
2495
+ s2 = peg$currPos;
2496
+ if (input.charCodeAt(peg$currPos) === 110) {
2497
+ s3 = peg$c26;
2498
+ peg$currPos++;
2499
+ } else {
2500
+ s3 = peg$FAILED;
2501
+ if (peg$silentFails === 0) { peg$fail(peg$e29); }
2502
+ }
2503
+ if (s3 !== peg$FAILED) {
2504
+ peg$savedPos = s2;
2505
+ s3 = peg$f32();
2506
+ }
2507
+ s2 = s3;
2508
+ if (s2 === peg$FAILED) {
2509
+ s2 = peg$currPos;
2510
+ if (input.charCodeAt(peg$currPos) === 114) {
2511
+ s3 = peg$c27;
2512
+ peg$currPos++;
2513
+ } else {
2514
+ s3 = peg$FAILED;
2515
+ if (peg$silentFails === 0) { peg$fail(peg$e30); }
2516
+ }
2517
+ if (s3 !== peg$FAILED) {
2518
+ peg$savedPos = s2;
2519
+ s3 = peg$f33();
2520
+ }
2521
+ s2 = s3;
2522
+ if (s2 === peg$FAILED) {
2523
+ s2 = peg$currPos;
2524
+ if (input.charCodeAt(peg$currPos) === 116) {
2525
+ s3 = peg$c28;
2526
+ peg$currPos++;
2527
+ } else {
2528
+ s3 = peg$FAILED;
2529
+ if (peg$silentFails === 0) { peg$fail(peg$e31); }
2530
+ }
2531
+ if (s3 !== peg$FAILED) {
2532
+ peg$savedPos = s2;
2533
+ s3 = peg$f34();
2534
+ }
2535
+ s2 = s3;
2536
+ if (s2 === peg$FAILED) {
2537
+ s2 = peg$currPos;
2538
+ if (input.charCodeAt(peg$currPos) === 117) {
2539
+ s3 = peg$c29;
2540
+ peg$currPos++;
2541
+ } else {
2542
+ s3 = peg$FAILED;
2543
+ if (peg$silentFails === 0) { peg$fail(peg$e32); }
2544
+ }
2545
+ if (s3 !== peg$FAILED) {
2546
+ s4 = peg$currPos;
2547
+ s5 = peg$currPos;
2548
+ s6 = peg$parseHEXDIG();
2549
+ if (s6 !== peg$FAILED) {
2550
+ s7 = peg$parseHEXDIG();
2551
+ if (s7 !== peg$FAILED) {
2552
+ s8 = peg$parseHEXDIG();
2553
+ if (s8 !== peg$FAILED) {
2554
+ s9 = peg$parseHEXDIG();
2555
+ if (s9 !== peg$FAILED) {
2556
+ s6 = [s6, s7, s8, s9];
2557
+ s5 = s6;
2558
+ } else {
2559
+ peg$currPos = s5;
2560
+ s5 = peg$FAILED;
2561
+ }
2562
+ } else {
2563
+ peg$currPos = s5;
2564
+ s5 = peg$FAILED;
2565
+ }
2566
+ } else {
2567
+ peg$currPos = s5;
2568
+ s5 = peg$FAILED;
2569
+ }
2570
+ } else {
2571
+ peg$currPos = s5;
2572
+ s5 = peg$FAILED;
2573
+ }
2574
+ if (s5 !== peg$FAILED) {
2575
+ s4 = input.substring(s4, peg$currPos);
2576
+ } else {
2577
+ s4 = s5;
2578
+ }
2579
+ if (s4 !== peg$FAILED) {
2580
+ peg$savedPos = s2;
2581
+ s2 = peg$f35(s4);
2582
+ } else {
2583
+ peg$currPos = s2;
2584
+ s2 = peg$FAILED;
2585
+ }
2586
+ } else {
2587
+ peg$currPos = s2;
2588
+ s2 = peg$FAILED;
2589
+ }
2590
+ }
2591
+ }
2592
+ }
2593
+ }
2594
+ }
2595
+ }
2596
+ }
2597
+ }
2598
+ if (s2 !== peg$FAILED) {
2599
+ s0 = s2;
2600
+ } else {
2601
+ peg$currPos = s0;
2602
+ s0 = peg$FAILED;
2603
+ }
2604
+ } else {
2605
+ peg$currPos = s0;
2606
+ s0 = peg$FAILED;
2607
+ }
2608
+
2609
+ return s0;
2610
+ }
2611
+
2612
+ function peg$parseHEXDIG() {
2613
+ var s0;
2614
+
2615
+ if (peg$r3.test(input.charAt(peg$currPos))) {
2616
+ s0 = input.charAt(peg$currPos);
2617
+ peg$currPos++;
2618
+ } else {
2619
+ s0 = peg$FAILED;
2620
+ if (peg$silentFails === 0) { peg$fail(peg$e33); }
2621
+ }
2622
+
2623
+ return s0;
2624
+ }
2625
+
2626
+ function peg$parseraw_string() {
2627
+ var s0, s1, s2, s3;
2628
+
2629
+ s0 = peg$currPos;
2630
+ if (input.charCodeAt(peg$currPos) === 39) {
2631
+ s1 = peg$c30;
2632
+ peg$currPos++;
2633
+ } else {
2634
+ s1 = peg$FAILED;
2635
+ if (peg$silentFails === 0) { peg$fail(peg$e34); }
2636
+ }
2637
+ if (s1 !== peg$FAILED) {
2638
+ s2 = [];
2639
+ s3 = peg$parseraw_string_char();
2640
+ while (s3 !== peg$FAILED) {
2641
+ s2.push(s3);
2642
+ s3 = peg$parseraw_string_char();
2643
+ }
2644
+ if (input.charCodeAt(peg$currPos) === 39) {
2645
+ s3 = peg$c30;
2646
+ peg$currPos++;
2647
+ } else {
2648
+ s3 = peg$FAILED;
2649
+ if (peg$silentFails === 0) { peg$fail(peg$e34); }
2650
+ }
2651
+ if (s3 !== peg$FAILED) {
2652
+ peg$savedPos = s0;
2653
+ s0 = peg$f36(s2);
2654
+ } else {
2655
+ peg$currPos = s0;
2656
+ s0 = peg$FAILED;
2657
+ }
2658
+ } else {
2659
+ peg$currPos = s0;
2660
+ s0 = peg$FAILED;
2661
+ }
2662
+
2663
+ return s0;
2664
+ }
2665
+
2666
+ function peg$parseraw_string_char() {
2667
+ var s0;
2668
+
2669
+ s0 = peg$parseunescaped_raw_string_char();
2670
+ if (s0 === peg$FAILED) {
2671
+ s0 = peg$parsepreserved_escape();
2672
+ if (s0 === peg$FAILED) {
2673
+ s0 = peg$parseraw_string_escape();
2674
+ }
2675
+ }
2676
+
2677
+ return s0;
2678
+ }
2679
+
2680
+ function peg$parseunescaped_raw_string_char() {
2681
+ var s0;
2682
+
2683
+ if (peg$r4.test(input.charAt(peg$currPos))) {
2684
+ s0 = input.charAt(peg$currPos);
2685
+ peg$currPos++;
2686
+ } else {
2687
+ s0 = peg$FAILED;
2688
+ if (peg$silentFails === 0) { peg$fail(peg$e35); }
2689
+ }
2690
+
2691
+ return s0;
2692
+ }
2693
+
2694
+ function peg$parsepreserved_escape() {
2695
+ var s0, s1, s2;
2696
+
2697
+ s0 = peg$currPos;
2698
+ if (input.charCodeAt(peg$currPos) === 92) {
2699
+ s1 = peg$c22;
2700
+ peg$currPos++;
2701
+ } else {
2702
+ s1 = peg$FAILED;
2703
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2704
+ }
2705
+ if (s1 !== peg$FAILED) {
2706
+ if (peg$r5.test(input.charAt(peg$currPos))) {
2707
+ s2 = input.charAt(peg$currPos);
2708
+ peg$currPos++;
2709
+ } else {
2710
+ s2 = peg$FAILED;
2711
+ if (peg$silentFails === 0) { peg$fail(peg$e36); }
2712
+ }
2713
+ if (s2 !== peg$FAILED) {
2714
+ peg$savedPos = s0;
2715
+ s0 = peg$f37();
2716
+ } else {
2717
+ peg$currPos = s0;
2718
+ s0 = peg$FAILED;
2719
+ }
2720
+ } else {
2721
+ peg$currPos = s0;
2722
+ s0 = peg$FAILED;
2723
+ }
2724
+
2725
+ return s0;
2726
+ }
2727
+
2728
+ function peg$parseraw_string_escape() {
2729
+ var s0, s1, s2;
2730
+
2731
+ s0 = peg$currPos;
2732
+ if (input.charCodeAt(peg$currPos) === 92) {
2733
+ s1 = peg$c22;
2734
+ peg$currPos++;
2735
+ } else {
2736
+ s1 = peg$FAILED;
2737
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2738
+ }
2739
+ if (s1 !== peg$FAILED) {
2740
+ if (input.charCodeAt(peg$currPos) === 39) {
2741
+ s2 = peg$c30;
2742
+ peg$currPos++;
2743
+ } else {
2744
+ s2 = peg$FAILED;
2745
+ if (peg$silentFails === 0) { peg$fail(peg$e34); }
2746
+ }
2747
+ if (s2 !== peg$FAILED) {
2748
+ s0 = s2;
2749
+ } else {
2750
+ peg$currPos = s0;
2751
+ s0 = peg$FAILED;
2752
+ }
2753
+ } else {
2754
+ peg$currPos = s0;
2755
+ s0 = peg$FAILED;
2756
+ }
2757
+
2758
+ return s0;
2759
+ }
2760
+
2761
+ function peg$parsenumber() {
2762
+ var s0, s1;
2763
+
2764
+ s0 = peg$currPos;
2765
+ s1 = peg$parseint();
2766
+ if (s1 !== peg$FAILED) {
2767
+ peg$savedPos = s0;
2768
+ s1 = peg$f38();
2769
+ }
2770
+ s0 = s1;
2771
+
2772
+ return s0;
2773
+ }
2774
+
2775
+ function peg$parseint() {
2776
+ var s0, s1, s2, s3, s4, s5;
2777
+
2778
+ s0 = peg$currPos;
2779
+ if (input.charCodeAt(peg$currPos) === 45) {
2780
+ s1 = peg$c31;
2781
+ peg$currPos++;
2782
+ } else {
2783
+ s1 = peg$FAILED;
2784
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2785
+ }
2786
+ if (s1 === peg$FAILED) {
2787
+ s1 = null;
2788
+ }
2789
+ if (input.charCodeAt(peg$currPos) === 48) {
2790
+ s2 = peg$c32;
2791
+ peg$currPos++;
2792
+ } else {
2793
+ s2 = peg$FAILED;
2794
+ if (peg$silentFails === 0) { peg$fail(peg$e38); }
2795
+ }
2796
+ if (s2 === peg$FAILED) {
2797
+ s2 = peg$currPos;
2798
+ if (peg$r6.test(input.charAt(peg$currPos))) {
2799
+ s3 = input.charAt(peg$currPos);
2800
+ peg$currPos++;
2801
+ } else {
2802
+ s3 = peg$FAILED;
2803
+ if (peg$silentFails === 0) { peg$fail(peg$e39); }
2804
+ }
2805
+ if (s3 !== peg$FAILED) {
2806
+ s4 = [];
2807
+ if (peg$r7.test(input.charAt(peg$currPos))) {
2808
+ s5 = input.charAt(peg$currPos);
2809
+ peg$currPos++;
2810
+ } else {
2811
+ s5 = peg$FAILED;
2812
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2813
+ }
2814
+ while (s5 !== peg$FAILED) {
2815
+ s4.push(s5);
2816
+ if (peg$r7.test(input.charAt(peg$currPos))) {
2817
+ s5 = input.charAt(peg$currPos);
2818
+ peg$currPos++;
2819
+ } else {
2820
+ s5 = peg$FAILED;
2821
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2822
+ }
2823
+ }
2824
+ s3 = [s3, s4];
2825
+ s2 = s3;
2826
+ } else {
2827
+ peg$currPos = s2;
2828
+ s2 = peg$FAILED;
2829
+ }
2830
+ }
2831
+ if (s2 !== peg$FAILED) {
2832
+ s1 = [s1, s2];
2833
+ s0 = s1;
2834
+ } else {
2835
+ peg$currPos = s0;
2836
+ s0 = peg$FAILED;
2837
+ }
2838
+
2839
+ return s0;
2840
+ }
2841
+
2842
+ function peg$parsejson_value() {
2843
+ var s0, s1;
2844
+
2845
+ s0 = peg$currPos;
2846
+ if (input.substr(peg$currPos, 4) === peg$c33) {
2847
+ s1 = peg$c33;
2848
+ peg$currPos += 4;
2849
+ } else {
2850
+ s1 = peg$FAILED;
2851
+ if (peg$silentFails === 0) { peg$fail(peg$e41); }
2852
+ }
2853
+ if (s1 !== peg$FAILED) {
2854
+ peg$savedPos = s0;
2855
+ s1 = peg$f39();
2856
+ }
2857
+ s0 = s1;
2858
+ if (s0 === peg$FAILED) {
2859
+ s0 = peg$currPos;
2860
+ if (input.substr(peg$currPos, 5) === peg$c34) {
2861
+ s1 = peg$c34;
2862
+ peg$currPos += 5;
2863
+ } else {
2864
+ s1 = peg$FAILED;
2865
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
2866
+ }
2867
+ if (s1 !== peg$FAILED) {
2868
+ peg$savedPos = s0;
2869
+ s1 = peg$f40();
2870
+ }
2871
+ s0 = s1;
2872
+ if (s0 === peg$FAILED) {
2873
+ s0 = peg$currPos;
2874
+ if (input.substr(peg$currPos, 4) === peg$c35) {
2875
+ s1 = peg$c35;
2876
+ peg$currPos += 4;
2877
+ } else {
2878
+ s1 = peg$FAILED;
2879
+ if (peg$silentFails === 0) { peg$fail(peg$e43); }
2880
+ }
2881
+ if (s1 !== peg$FAILED) {
2882
+ peg$savedPos = s0;
2883
+ s1 = peg$f41();
2884
+ }
2885
+ s0 = s1;
2886
+ if (s0 === peg$FAILED) {
2887
+ s0 = peg$parsejson_number();
2888
+ if (s0 === peg$FAILED) {
2889
+ s0 = peg$parsejson_string();
2890
+ if (s0 === peg$FAILED) {
2891
+ s0 = peg$parsejson_object();
2892
+ if (s0 === peg$FAILED) {
2893
+ s0 = peg$parsejson_array();
2894
+ }
2895
+ }
2896
+ }
2897
+ }
2898
+ }
2899
+ }
2900
+
2901
+ return s0;
2902
+ }
2903
+
2904
+ function peg$parsejson_number() {
2905
+ var s0, s1, s2, s3, s4, s5, s6, s7;
2906
+
2907
+ s0 = peg$currPos;
2908
+ s1 = peg$parseint();
2909
+ if (s1 !== peg$FAILED) {
2910
+ s2 = peg$currPos;
2911
+ if (input.charCodeAt(peg$currPos) === 46) {
2912
+ s3 = peg$c16;
2913
+ peg$currPos++;
2914
+ } else {
2915
+ s3 = peg$FAILED;
2916
+ if (peg$silentFails === 0) { peg$fail(peg$e16); }
2917
+ }
2918
+ if (s3 !== peg$FAILED) {
2919
+ s4 = [];
2920
+ if (peg$r7.test(input.charAt(peg$currPos))) {
2921
+ s5 = input.charAt(peg$currPos);
2922
+ peg$currPos++;
2923
+ } else {
2924
+ s5 = peg$FAILED;
2925
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2926
+ }
2927
+ if (s5 !== peg$FAILED) {
2928
+ while (s5 !== peg$FAILED) {
2929
+ s4.push(s5);
2930
+ if (peg$r7.test(input.charAt(peg$currPos))) {
2931
+ s5 = input.charAt(peg$currPos);
2932
+ peg$currPos++;
2933
+ } else {
2934
+ s5 = peg$FAILED;
2935
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2936
+ }
2937
+ }
2938
+ } else {
2939
+ s4 = peg$FAILED;
2940
+ }
2941
+ if (s4 !== peg$FAILED) {
2942
+ s3 = [s3, s4];
2943
+ s2 = s3;
2944
+ } else {
2945
+ peg$currPos = s2;
2946
+ s2 = peg$FAILED;
2947
+ }
2948
+ } else {
2949
+ peg$currPos = s2;
2950
+ s2 = peg$FAILED;
2951
+ }
2952
+ if (s2 === peg$FAILED) {
2953
+ s2 = null;
2954
+ }
2955
+ s3 = peg$currPos;
2956
+ if (peg$r8.test(input.charAt(peg$currPos))) {
2957
+ s4 = input.charAt(peg$currPos);
2958
+ peg$currPos++;
2959
+ } else {
2960
+ s4 = peg$FAILED;
2961
+ if (peg$silentFails === 0) { peg$fail(peg$e44); }
2962
+ }
2963
+ if (s4 !== peg$FAILED) {
2964
+ if (peg$r9.test(input.charAt(peg$currPos))) {
2965
+ s5 = input.charAt(peg$currPos);
2966
+ peg$currPos++;
2967
+ } else {
2968
+ s5 = peg$FAILED;
2969
+ if (peg$silentFails === 0) { peg$fail(peg$e45); }
2970
+ }
2971
+ if (s5 === peg$FAILED) {
2972
+ s5 = null;
2973
+ }
2974
+ s6 = [];
2975
+ if (peg$r7.test(input.charAt(peg$currPos))) {
2976
+ s7 = input.charAt(peg$currPos);
2977
+ peg$currPos++;
2978
+ } else {
2979
+ s7 = peg$FAILED;
2980
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2981
+ }
2982
+ if (s7 !== peg$FAILED) {
2983
+ while (s7 !== peg$FAILED) {
2984
+ s6.push(s7);
2985
+ if (peg$r7.test(input.charAt(peg$currPos))) {
2986
+ s7 = input.charAt(peg$currPos);
2987
+ peg$currPos++;
2988
+ } else {
2989
+ s7 = peg$FAILED;
2990
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2991
+ }
2992
+ }
2993
+ } else {
2994
+ s6 = peg$FAILED;
2995
+ }
2996
+ if (s6 !== peg$FAILED) {
2997
+ s4 = [s4, s5, s6];
2998
+ s3 = s4;
2999
+ } else {
3000
+ peg$currPos = s3;
3001
+ s3 = peg$FAILED;
3002
+ }
3003
+ } else {
3004
+ peg$currPos = s3;
3005
+ s3 = peg$FAILED;
3006
+ }
3007
+ if (s3 === peg$FAILED) {
3008
+ s3 = null;
3009
+ }
3010
+ peg$savedPos = s0;
3011
+ s0 = peg$f42();
3012
+ } else {
3013
+ peg$currPos = s0;
3014
+ s0 = peg$FAILED;
3015
+ }
3016
+
3017
+ return s0;
3018
+ }
3019
+
3020
+ function peg$parsejson_string() {
3021
+ var s0, s1, s2, s3;
3022
+
3023
+ s0 = peg$currPos;
3024
+ if (input.charCodeAt(peg$currPos) === 34) {
3025
+ s1 = peg$c21;
3026
+ peg$currPos++;
3027
+ } else {
3028
+ s1 = peg$FAILED;
3029
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
3030
+ }
3031
+ if (s1 !== peg$FAILED) {
3032
+ s2 = peg$parseunquoted_json_string();
3033
+ if (input.charCodeAt(peg$currPos) === 34) {
3034
+ s3 = peg$c21;
3035
+ peg$currPos++;
3036
+ } else {
3037
+ s3 = peg$FAILED;
3038
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
3039
+ }
3040
+ if (s3 !== peg$FAILED) {
3041
+ s0 = s2;
3042
+ } else {
3043
+ peg$currPos = s0;
3044
+ s0 = peg$FAILED;
3045
+ }
3046
+ } else {
3047
+ peg$currPos = s0;
3048
+ s0 = peg$FAILED;
3049
+ }
3050
+
3051
+ return s0;
3052
+ }
3053
+
3054
+ function peg$parseunquoted_json_string() {
3055
+ var s0, s1, s2;
3056
+
3057
+ s0 = peg$currPos;
3058
+ s1 = [];
3059
+ s2 = peg$parseunescaped_literal();
3060
+ if (s2 === peg$FAILED) {
3061
+ s2 = peg$parseescaped_literal();
3062
+ }
3063
+ while (s2 !== peg$FAILED) {
3064
+ s1.push(s2);
3065
+ s2 = peg$parseunescaped_literal();
3066
+ if (s2 === peg$FAILED) {
3067
+ s2 = peg$parseescaped_literal();
3068
+ }
3069
+ }
3070
+ peg$savedPos = s0;
3071
+ s1 = peg$f43(s1);
3072
+ s0 = s1;
3073
+
3074
+ return s0;
3075
+ }
3076
+
3077
+ function peg$parseunescaped_literal() {
3078
+ var s0;
3079
+
3080
+ if (peg$r10.test(input.charAt(peg$currPos))) {
3081
+ s0 = input.charAt(peg$currPos);
3082
+ peg$currPos++;
3083
+ } else {
3084
+ s0 = peg$FAILED;
3085
+ if (peg$silentFails === 0) { peg$fail(peg$e46); }
3086
+ }
3087
+
3088
+ return s0;
3089
+ }
3090
+
3091
+ function peg$parseescaped_literal() {
3092
+ var s0, s1, s2;
3093
+
3094
+ s0 = peg$parseescaped_char();
3095
+ if (s0 === peg$FAILED) {
3096
+ s0 = peg$currPos;
3097
+ if (input.charCodeAt(peg$currPos) === 92) {
3098
+ s1 = peg$c22;
3099
+ peg$currPos++;
3100
+ } else {
3101
+ s1 = peg$FAILED;
3102
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
3103
+ }
3104
+ if (s1 !== peg$FAILED) {
3105
+ if (input.charCodeAt(peg$currPos) === 96) {
3106
+ s2 = peg$c20;
3107
+ peg$currPos++;
3108
+ } else {
3109
+ s2 = peg$FAILED;
3110
+ if (peg$silentFails === 0) { peg$fail(peg$e20); }
3111
+ }
3112
+ if (s2 !== peg$FAILED) {
3113
+ s0 = s2;
3114
+ } else {
3115
+ peg$currPos = s0;
3116
+ s0 = peg$FAILED;
3117
+ }
3118
+ } else {
3119
+ peg$currPos = s0;
3120
+ s0 = peg$FAILED;
3121
+ }
3122
+ }
3123
+
3124
+ return s0;
3125
+ }
3126
+
3127
+ function peg$parsejson_object() {
3128
+ var s0, s1, s3, s4, s5, s6, s8, s10;
3129
+
3130
+ s0 = peg$currPos;
3131
+ if (input.charCodeAt(peg$currPos) === 123) {
3132
+ s1 = peg$c36;
3133
+ peg$currPos++;
3134
+ } else {
3135
+ s1 = peg$FAILED;
3136
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
3137
+ }
3138
+ if (s1 !== peg$FAILED) {
3139
+ peg$parsews();
3140
+ s3 = peg$currPos;
3141
+ s4 = peg$parsejson_member();
3142
+ if (s4 !== peg$FAILED) {
3143
+ s5 = [];
3144
+ s6 = peg$currPos;
3145
+ peg$parsews();
3146
+ if (input.charCodeAt(peg$currPos) === 44) {
3147
+ s8 = peg$c37;
3148
+ peg$currPos++;
3149
+ } else {
3150
+ s8 = peg$FAILED;
3151
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
3152
+ }
3153
+ if (s8 !== peg$FAILED) {
3154
+ peg$parsews();
3155
+ s10 = peg$parsejson_member();
3156
+ if (s10 !== peg$FAILED) {
3157
+ s6 = s10;
3158
+ } else {
3159
+ peg$currPos = s6;
3160
+ s6 = peg$FAILED;
3161
+ }
3162
+ } else {
3163
+ peg$currPos = s6;
3164
+ s6 = peg$FAILED;
3165
+ }
3166
+ while (s6 !== peg$FAILED) {
3167
+ s5.push(s6);
3168
+ s6 = peg$currPos;
3169
+ peg$parsews();
3170
+ if (input.charCodeAt(peg$currPos) === 44) {
3171
+ s8 = peg$c37;
3172
+ peg$currPos++;
3173
+ } else {
3174
+ s8 = peg$FAILED;
3175
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
3176
+ }
3177
+ if (s8 !== peg$FAILED) {
3178
+ peg$parsews();
3179
+ s10 = peg$parsejson_member();
3180
+ if (s10 !== peg$FAILED) {
3181
+ s6 = s10;
3182
+ } else {
3183
+ peg$currPos = s6;
3184
+ s6 = peg$FAILED;
3185
+ }
3186
+ } else {
3187
+ peg$currPos = s6;
3188
+ s6 = peg$FAILED;
3189
+ }
3190
+ }
3191
+ peg$savedPos = s3;
3192
+ s3 = peg$f44(s4, s5);
3193
+ } else {
3194
+ peg$currPos = s3;
3195
+ s3 = peg$FAILED;
3196
+ }
3197
+ if (s3 === peg$FAILED) {
3198
+ s3 = null;
3199
+ }
3200
+ s4 = peg$parsews();
3201
+ if (input.charCodeAt(peg$currPos) === 125) {
3202
+ s5 = peg$c38;
3203
+ peg$currPos++;
3204
+ } else {
3205
+ s5 = peg$FAILED;
3206
+ if (peg$silentFails === 0) { peg$fail(peg$e49); }
3207
+ }
3208
+ if (s5 !== peg$FAILED) {
3209
+ peg$savedPos = s0;
3210
+ s0 = peg$f45(s3);
3211
+ } else {
3212
+ peg$currPos = s0;
3213
+ s0 = peg$FAILED;
3214
+ }
3215
+ } else {
3216
+ peg$currPos = s0;
3217
+ s0 = peg$FAILED;
3218
+ }
3219
+
3220
+ return s0;
3221
+ }
3222
+
3223
+ function peg$parsejson_member() {
3224
+ var s0, s1, s3, s5;
3225
+
3226
+ s0 = peg$currPos;
3227
+ s1 = peg$parsejson_string();
3228
+ if (s1 !== peg$FAILED) {
3229
+ peg$parsews();
3230
+ if (input.charCodeAt(peg$currPos) === 58) {
3231
+ s3 = peg$c15;
3232
+ peg$currPos++;
3233
+ } else {
3234
+ s3 = peg$FAILED;
3235
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
3236
+ }
3237
+ if (s3 !== peg$FAILED) {
3238
+ peg$parsews();
3239
+ s5 = peg$parsejson_value();
3240
+ if (s5 !== peg$FAILED) {
3241
+ peg$savedPos = s0;
3242
+ s0 = peg$f46(s1, s5);
3243
+ } else {
3244
+ peg$currPos = s0;
3245
+ s0 = peg$FAILED;
3246
+ }
3247
+ } else {
3248
+ peg$currPos = s0;
3249
+ s0 = peg$FAILED;
3250
+ }
3251
+ } else {
3252
+ peg$currPos = s0;
3253
+ s0 = peg$FAILED;
3254
+ }
3255
+
3256
+ return s0;
3257
+ }
3258
+
3259
+ function peg$parsejson_array() {
3260
+ var s0, s1, s3, s4, s5, s6, s8, s10;
3261
+
3262
+ s0 = peg$currPos;
3263
+ if (input.charCodeAt(peg$currPos) === 91) {
3264
+ s1 = peg$c13;
3265
+ peg$currPos++;
3266
+ } else {
3267
+ s1 = peg$FAILED;
3268
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
3269
+ }
3270
+ if (s1 !== peg$FAILED) {
3271
+ peg$parsews();
3272
+ s3 = peg$currPos;
3273
+ s4 = peg$parsejson_value();
3274
+ if (s4 !== peg$FAILED) {
3275
+ s5 = [];
3276
+ s6 = peg$currPos;
3277
+ peg$parsews();
3278
+ if (input.charCodeAt(peg$currPos) === 44) {
3279
+ s8 = peg$c37;
3280
+ peg$currPos++;
3281
+ } else {
3282
+ s8 = peg$FAILED;
3283
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
3284
+ }
3285
+ if (s8 !== peg$FAILED) {
3286
+ peg$parsews();
3287
+ s10 = peg$parsejson_value();
3288
+ if (s10 !== peg$FAILED) {
3289
+ s6 = s10;
3290
+ } else {
3291
+ peg$currPos = s6;
3292
+ s6 = peg$FAILED;
3293
+ }
3294
+ } else {
3295
+ peg$currPos = s6;
3296
+ s6 = peg$FAILED;
3297
+ }
3298
+ while (s6 !== peg$FAILED) {
3299
+ s5.push(s6);
3300
+ s6 = peg$currPos;
3301
+ peg$parsews();
3302
+ if (input.charCodeAt(peg$currPos) === 44) {
3303
+ s8 = peg$c37;
3304
+ peg$currPos++;
3305
+ } else {
3306
+ s8 = peg$FAILED;
3307
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
3308
+ }
3309
+ if (s8 !== peg$FAILED) {
3310
+ peg$parsews();
3311
+ s10 = peg$parsejson_value();
3312
+ if (s10 !== peg$FAILED) {
3313
+ s6 = s10;
3314
+ } else {
3315
+ peg$currPos = s6;
3316
+ s6 = peg$FAILED;
3317
+ }
3318
+ } else {
3319
+ peg$currPos = s6;
3320
+ s6 = peg$FAILED;
3321
+ }
3322
+ }
3323
+ peg$savedPos = s3;
3324
+ s3 = peg$f47(s4, s5);
3325
+ } else {
3326
+ peg$currPos = s3;
3327
+ s3 = peg$FAILED;
3328
+ }
3329
+ if (s3 === peg$FAILED) {
3330
+ s3 = null;
3331
+ }
3332
+ s4 = peg$parsews();
3333
+ if (input.charCodeAt(peg$currPos) === 93) {
3334
+ s5 = peg$c12;
3335
+ peg$currPos++;
3336
+ } else {
3337
+ s5 = peg$FAILED;
3338
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
3339
+ }
3340
+ if (s5 !== peg$FAILED) {
3341
+ peg$savedPos = s0;
3342
+ s0 = peg$f48(s3);
3343
+ } else {
3344
+ peg$currPos = s0;
3345
+ s0 = peg$FAILED;
3346
+ }
3347
+ } else {
3348
+ peg$currPos = s0;
3349
+ s0 = peg$FAILED;
3350
+ }
3351
+
3352
+ return s0;
3353
+ }
3354
+
3355
+ function peg$parsews() {
3356
+ var s0, s1;
3357
+
3358
+ peg$silentFails++;
3359
+ s0 = [];
3360
+ if (peg$r11.test(input.charAt(peg$currPos))) {
3361
+ s1 = input.charAt(peg$currPos);
3362
+ peg$currPos++;
3363
+ } else {
3364
+ s1 = peg$FAILED;
3365
+ if (peg$silentFails === 0) { peg$fail(peg$e51); }
3366
+ }
3367
+ while (s1 !== peg$FAILED) {
3368
+ s0.push(s1);
3369
+ if (peg$r11.test(input.charAt(peg$currPos))) {
3370
+ s1 = input.charAt(peg$currPos);
3371
+ peg$currPos++;
3372
+ } else {
3373
+ s1 = peg$FAILED;
3374
+ if (peg$silentFails === 0) { peg$fail(peg$e51); }
3375
+ }
3376
+ }
3377
+ peg$silentFails--;
3378
+ s1 = peg$FAILED;
3379
+ if (peg$silentFails === 0) { peg$fail(peg$e50); }
3380
+
3381
+ return s0;
3382
+ }
3383
+
3384
+
3385
+ function binaryExpression(type, head, tail) {
3386
+ return tail.reduce((lhs, rhs) => (
3387
+ {
3388
+ type,
3389
+ lhs,
3390
+ rhs
3391
+ }
3392
+ ), head);
3393
+ }
3394
+
3395
+ function reduceProjection(lhs, rhs) {
3396
+ return rhs.reduce((result, fn) => fn(result), lhs);
3397
+ }
3398
+
3399
+ function maybeProject(expression, pfns) {
3400
+ return !pfns.length ? expression : (
3401
+ {
3402
+ type: "project",
3403
+ expression: unwrapTrivialProjection(expression),
3404
+ projection: pfns.reduce((result, pfn) => pfn(result), { type: "current" })
3405
+ });
3406
+ }
3407
+
3408
+ function unwrapTrivialProjection(expression) {
3409
+ const { type, projection } = expression;
3410
+ return type === "project" && (!projection || projection.type === "current") ? expression.expression : expression;
3411
+ }
3412
+
3413
+ peg$result = peg$startRuleFunction();
3414
+
3415
+ if (peg$result !== peg$FAILED && peg$currPos === input.length) {
3416
+ return peg$result;
3417
+ } else {
3418
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
3419
+ peg$fail(peg$endExpectation());
3420
+ }
3421
+
3422
+ throw peg$buildStructuredError(
3423
+ peg$maxFailExpected,
3424
+ peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
3425
+ peg$maxFailPos < input.length
3426
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
3427
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
3428
+ );
3429
+ }
3430
+ }
3431
+
3432
+ var parser = {
3433
+ SyntaxError: peg$SyntaxError,
3434
+ parse: peg$parse
3435
+ };
3436
+
3437
+ function parseJsonSelector(selectorExpression) {
3438
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
3439
+ return parser.parse(selectorExpression);
3440
+ }
3441
+
3442
+ function setWithJsonSelector(selector, context, value) {
3443
+ const accessor = accessWithJsonSelector(selector, context);
3444
+ const oldValue = accessor.get();
3445
+ accessor.set(value);
3446
+ return oldValue;
3447
+ }
3448
+
3449
+ export { accessWithJsonSelector, bindJsonSelectorAccessor, evaluateJsonSelector, formatJsonSelector, getWithJsonSelector, invertedSlice, makeJsonSelectorAccessor, parseJsonSelector, setWithJsonSelector };
3450
+ //# sourceMappingURL=json-selector.esm.js.map