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