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