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