tplm-lang 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +357 -0
  2. package/dist/compiler/grid-spec-builder.d.ts +30 -0
  3. package/dist/compiler/grid-spec-builder.js +1836 -0
  4. package/dist/compiler/index.d.ts +11 -0
  5. package/dist/compiler/index.js +13 -0
  6. package/dist/compiler/malloy-generator.d.ts +36 -0
  7. package/dist/compiler/malloy-generator.js +141 -0
  8. package/dist/compiler/multi-query-utils.d.ts +42 -0
  9. package/dist/compiler/multi-query-utils.js +185 -0
  10. package/dist/compiler/query-plan-generator.d.ts +77 -0
  11. package/dist/compiler/query-plan-generator.js +1456 -0
  12. package/dist/compiler/table-spec-builder.d.ts +11 -0
  13. package/dist/compiler/table-spec-builder.js +588 -0
  14. package/dist/compiler/table-spec.d.ts +434 -0
  15. package/dist/compiler/table-spec.js +274 -0
  16. package/dist/executor/index.d.ts +71 -0
  17. package/dist/executor/index.js +232 -0
  18. package/dist/index.d.ts +214 -0
  19. package/dist/index.js +220 -0
  20. package/dist/parser/ast.d.ts +253 -0
  21. package/dist/parser/ast.js +164 -0
  22. package/dist/parser/chevrotain-parser.d.ts +118 -0
  23. package/dist/parser/chevrotain-parser.js +1266 -0
  24. package/dist/parser/index.d.ts +30 -0
  25. package/dist/parser/index.js +36 -0
  26. package/dist/parser/parser.d.ts +4 -0
  27. package/dist/parser/parser.js +4354 -0
  28. package/dist/parser/prettifier.d.ts +14 -0
  29. package/dist/parser/prettifier.js +380 -0
  30. package/dist/renderer/grid-renderer.d.ts +19 -0
  31. package/dist/renderer/grid-renderer.js +541 -0
  32. package/dist/renderer/index.d.ts +4 -0
  33. package/dist/renderer/index.js +4 -0
  34. package/package.json +67 -0
  35. package/packages/parser/tpl.pegjs +568 -0
  36. package/packages/renderer/tpl-table.css +182 -0
@@ -0,0 +1,4354 @@
1
+ // @generated by Peggy 4.2.0.
2
+ //
3
+ // https://peggyjs.org/
4
+
5
+
6
+
7
+ // Helper functions available in the generated parser
8
+
9
+ function makeAxis(groups) {
10
+ return { type: 'axis', groups: groups };
11
+ }
12
+
13
+ function makeGroup(items) {
14
+ return { type: 'group', items: items };
15
+ }
16
+
17
+ function makeDimension(name, annotations) {
18
+ return { type: 'dimension', name, ...annotations };
19
+ }
20
+
21
+ function makeMeasure(name, annotations) {
22
+ return { type: 'measure', name, ...annotations };
23
+ }
24
+
25
+ function makeAggregation(method, annotations) {
26
+ return { type: 'aggregation', method, ...annotations };
27
+ }
28
+
29
+ function makeAll(annotations) {
30
+ return { type: 'all', ...annotations };
31
+ }
32
+
33
+ function makeBinding(measure, aggregations, annotations) {
34
+ return { type: 'binding', measure, aggregations, ...annotations };
35
+ }
36
+
37
+ function mergeAnnotations(list) {
38
+ return list.reduce((acc, ann) => ({ ...acc, ...ann }), {});
39
+ }
40
+
41
+ function makeAggregateExpr(field, func, ungroupedDims) {
42
+ return {
43
+ type: 'aggregateExpr',
44
+ field,
45
+ function: func,
46
+ ungroupedDimensions: ungroupedDims ?? []
47
+ };
48
+ }
49
+
50
+ function makeRatioExpr(numerator, denominator) {
51
+ return {
52
+ type: 'ratioExpr',
53
+ numerator,
54
+ denominator
55
+ };
56
+ }
57
+
58
+ function makePercentageAggregate(measure, method, scope, annotations) {
59
+ return {
60
+ type: 'percentageAggregate',
61
+ measure: measure ?? undefined,
62
+ method,
63
+ denominatorScope: scope,
64
+ ...annotations
65
+ };
66
+ }
67
+
68
+ function peg$subclass(child, parent) {
69
+ function C() { this.constructor = child; }
70
+ C.prototype = parent.prototype;
71
+ child.prototype = new C();
72
+ }
73
+
74
+ function peg$SyntaxError(message, expected, found, location) {
75
+ var self = Error.call(this, message);
76
+ // istanbul ignore next Check is a necessary evil to support older environments
77
+ if (Object.setPrototypeOf) {
78
+ Object.setPrototypeOf(self, peg$SyntaxError.prototype);
79
+ }
80
+ self.expected = expected;
81
+ self.found = found;
82
+ self.location = location;
83
+ self.name = "SyntaxError";
84
+ return self;
85
+ }
86
+
87
+ peg$subclass(peg$SyntaxError, Error);
88
+
89
+ function peg$padEnd(str, targetLength, padString) {
90
+ padString = padString || " ";
91
+ if (str.length > targetLength) { return str; }
92
+ targetLength -= str.length;
93
+ padString += padString.repeat(targetLength);
94
+ return str + padString.slice(0, targetLength);
95
+ }
96
+
97
+ peg$SyntaxError.prototype.format = function(sources) {
98
+ var str = "Error: " + this.message;
99
+ if (this.location) {
100
+ var src = null;
101
+ var k;
102
+ for (k = 0; k < sources.length; k++) {
103
+ if (sources[k].source === this.location.source) {
104
+ src = sources[k].text.split(/\r\n|\n|\r/g);
105
+ break;
106
+ }
107
+ }
108
+ var s = this.location.start;
109
+ var offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
110
+ ? this.location.source.offset(s)
111
+ : s;
112
+ var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
113
+ if (src) {
114
+ var e = this.location.end;
115
+ var filler = peg$padEnd("", offset_s.line.toString().length, ' ');
116
+ var line = src[s.line - 1];
117
+ var last = s.line === e.line ? e.column : line.length + 1;
118
+ var hatLen = (last - s.column) || 1;
119
+ str += "\n --> " + loc + "\n"
120
+ + filler + " |\n"
121
+ + offset_s.line + " | " + line + "\n"
122
+ + filler + " | " + peg$padEnd("", s.column - 1, ' ')
123
+ + peg$padEnd("", hatLen, "^");
124
+ } else {
125
+ str += "\n at " + loc;
126
+ }
127
+ }
128
+ return str;
129
+ };
130
+
131
+ peg$SyntaxError.buildMessage = function(expected, found) {
132
+ var DESCRIBE_EXPECTATION_FNS = {
133
+ literal: function(expectation) {
134
+ return "\"" + literalEscape(expectation.text) + "\"";
135
+ },
136
+
137
+ class: function(expectation) {
138
+ var escapedParts = expectation.parts.map(function(part) {
139
+ return Array.isArray(part)
140
+ ? classEscape(part[0]) + "-" + classEscape(part[1])
141
+ : classEscape(part);
142
+ });
143
+
144
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
145
+ },
146
+
147
+ any: function() {
148
+ return "any character";
149
+ },
150
+
151
+ end: function() {
152
+ return "end of input";
153
+ },
154
+
155
+ other: function(expectation) {
156
+ return expectation.description;
157
+ }
158
+ };
159
+
160
+ function hex(ch) {
161
+ return ch.charCodeAt(0).toString(16).toUpperCase();
162
+ }
163
+
164
+ function literalEscape(s) {
165
+ return s
166
+ .replace(/\\/g, "\\\\")
167
+ .replace(/"/g, "\\\"")
168
+ .replace(/\0/g, "\\0")
169
+ .replace(/\t/g, "\\t")
170
+ .replace(/\n/g, "\\n")
171
+ .replace(/\r/g, "\\r")
172
+ .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
173
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
174
+ }
175
+
176
+ function classEscape(s) {
177
+ return s
178
+ .replace(/\\/g, "\\\\")
179
+ .replace(/\]/g, "\\]")
180
+ .replace(/\^/g, "\\^")
181
+ .replace(/-/g, "\\-")
182
+ .replace(/\0/g, "\\0")
183
+ .replace(/\t/g, "\\t")
184
+ .replace(/\n/g, "\\n")
185
+ .replace(/\r/g, "\\r")
186
+ .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
187
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
188
+ }
189
+
190
+ function describeExpectation(expectation) {
191
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
192
+ }
193
+
194
+ function describeExpected(expected) {
195
+ var descriptions = expected.map(describeExpectation);
196
+ var i, j;
197
+
198
+ descriptions.sort();
199
+
200
+ if (descriptions.length > 0) {
201
+ for (i = 1, j = 1; i < descriptions.length; i++) {
202
+ if (descriptions[i - 1] !== descriptions[i]) {
203
+ descriptions[j] = descriptions[i];
204
+ j++;
205
+ }
206
+ }
207
+ descriptions.length = j;
208
+ }
209
+
210
+ switch (descriptions.length) {
211
+ case 1:
212
+ return descriptions[0];
213
+
214
+ case 2:
215
+ return descriptions[0] + " or " + descriptions[1];
216
+
217
+ default:
218
+ return descriptions.slice(0, -1).join(", ")
219
+ + ", or "
220
+ + descriptions[descriptions.length - 1];
221
+ }
222
+ }
223
+
224
+ function describeFound(found) {
225
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
226
+ }
227
+
228
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
229
+ };
230
+
231
+ function peg$parse(input, options) {
232
+ options = options !== undefined ? options : {};
233
+
234
+ var peg$FAILED = {};
235
+ var peg$source = options.grammarSource;
236
+
237
+ var peg$startRuleFunctions = { start: peg$parsestart };
238
+ var peg$startRuleFunction = peg$parsestart;
239
+
240
+ var peg$c0 = ";";
241
+ var peg$c1 = "rowheaders";
242
+ var peg$c2 = ":";
243
+ var peg$c3 = "above";
244
+ var peg$c4 = "left";
245
+ var peg$c5 = "includenulls";
246
+ var peg$c6 = "true";
247
+ var peg$c7 = "false";
248
+ var peg$c8 = ".";
249
+ var peg$c9 = "|";
250
+ var peg$c10 = "*";
251
+ var peg$c11 = "(";
252
+ var peg$c12 = ")";
253
+ var peg$c13 = "across";
254
+ var peg$c14 = "cols";
255
+ var peg$c15 = "rows";
256
+ var peg$c16 = "asc";
257
+ var peg$c17 = "desc";
258
+ var peg$c18 = "sum";
259
+ var peg$c19 = "mean";
260
+ var peg$c20 = "avg";
261
+ var peg$c21 = "count";
262
+ var peg$c22 = "min";
263
+ var peg$c23 = "max";
264
+ var peg$c24 = "median";
265
+ var peg$c25 = "stdev";
266
+ var peg$c26 = "pct";
267
+ var peg$c27 = "pctn";
268
+ var peg$c28 = "pctsum";
269
+ var peg$c29 = "n";
270
+ var peg$c30 = "all";
271
+ var peg$c31 = "currency";
272
+ var peg$c32 = "percent";
273
+ var peg$c33 = "integer";
274
+ var peg$c34 = "decimal";
275
+ var peg$c35 = "comma";
276
+ var peg$c36 = "[";
277
+ var peg$c37 = "-";
278
+ var peg$c38 = "]";
279
+ var peg$c39 = "@";
280
+ var peg$c40 = "/";
281
+ var peg$c41 = "~";
282
+ var peg$c42 = "table";
283
+ var peg$c43 = "options";
284
+ var peg$c44 = "from";
285
+ var peg$c45 = "where";
286
+ var peg$c46 = "columns";
287
+ var peg$c47 = "then";
288
+ var peg$c48 = "by";
289
+ var peg$c49 = "\"";
290
+ var peg$c50 = "'";
291
+
292
+ var peg$r0 = /^[a-zA-Z0-9_]/;
293
+ var peg$r1 = /^[0-9]/;
294
+ var peg$r2 = /^[a-zA-Z_]/;
295
+ var peg$r3 = /^[^"]/;
296
+ var peg$r4 = /^[^']/;
297
+ var peg$r5 = /^[ \t\n\r]/;
298
+
299
+ var peg$e0 = peg$literalExpectation(";", false);
300
+ var peg$e1 = peg$literalExpectation("rowHeaders", true);
301
+ var peg$e2 = peg$literalExpectation(":", false);
302
+ var peg$e3 = peg$literalExpectation("above", true);
303
+ var peg$e4 = peg$literalExpectation("left", true);
304
+ var peg$e5 = peg$literalExpectation("includeNulls", true);
305
+ var peg$e6 = peg$literalExpectation("true", true);
306
+ var peg$e7 = peg$literalExpectation("false", true);
307
+ var peg$e8 = peg$literalExpectation(".", false);
308
+ var peg$e9 = peg$anyExpectation();
309
+ var peg$e10 = peg$literalExpectation("|", false);
310
+ var peg$e11 = peg$literalExpectation("*", false);
311
+ var peg$e12 = peg$literalExpectation("(", false);
312
+ var peg$e13 = peg$literalExpectation(")", false);
313
+ var peg$e14 = peg$literalExpectation("ACROSS", true);
314
+ var peg$e15 = peg$literalExpectation("COLS", true);
315
+ var peg$e16 = peg$literalExpectation("ROWS", true);
316
+ var peg$e17 = peg$literalExpectation("ASC", true);
317
+ var peg$e18 = peg$literalExpectation("DESC", true);
318
+ var peg$e19 = peg$literalExpectation("sum", true);
319
+ var peg$e20 = peg$literalExpectation("mean", true);
320
+ var peg$e21 = peg$literalExpectation("avg", true);
321
+ var peg$e22 = peg$literalExpectation("count", true);
322
+ var peg$e23 = peg$literalExpectation("min", true);
323
+ var peg$e24 = peg$literalExpectation("max", true);
324
+ var peg$e25 = peg$literalExpectation("median", true);
325
+ var peg$e26 = peg$literalExpectation("stdev", true);
326
+ var peg$e27 = peg$literalExpectation("pct", true);
327
+ var peg$e28 = peg$literalExpectation("pctn", true);
328
+ var peg$e29 = peg$literalExpectation("pctsum", true);
329
+ var peg$e30 = peg$literalExpectation("n", true);
330
+ var peg$e31 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_"], false, false);
331
+ var peg$e32 = peg$literalExpectation("ALL", true);
332
+ var peg$e33 = peg$literalExpectation("currency", true);
333
+ var peg$e34 = peg$literalExpectation("percent", true);
334
+ var peg$e35 = peg$literalExpectation("integer", true);
335
+ var peg$e36 = peg$literalExpectation("decimal", true);
336
+ var peg$e37 = peg$classExpectation([["0", "9"]], false, false);
337
+ var peg$e38 = peg$literalExpectation("comma", true);
338
+ var peg$e39 = peg$literalExpectation("[", false);
339
+ var peg$e40 = peg$literalExpectation("-", false);
340
+ var peg$e41 = peg$literalExpectation("]", false);
341
+ var peg$e42 = peg$literalExpectation("@", false);
342
+ var peg$e43 = peg$literalExpectation("/", false);
343
+ var peg$e44 = peg$literalExpectation("~", false);
344
+ var peg$e45 = peg$classExpectation([["a", "z"], ["A", "Z"], "_"], false, false);
345
+ var peg$e46 = peg$literalExpectation("TABLE", true);
346
+ var peg$e47 = peg$literalExpectation("OPTIONS", true);
347
+ var peg$e48 = peg$literalExpectation("FROM", true);
348
+ var peg$e49 = peg$literalExpectation("WHERE", true);
349
+ var peg$e50 = peg$literalExpectation("COLUMNS", true);
350
+ var peg$e51 = peg$literalExpectation("THEN", true);
351
+ var peg$e52 = peg$literalExpectation("BY", true);
352
+ var peg$e53 = peg$literalExpectation("\"", false);
353
+ var peg$e54 = peg$classExpectation(["\""], true, false);
354
+ var peg$e55 = peg$literalExpectation("'", false);
355
+ var peg$e56 = peg$classExpectation(["'"], true, false);
356
+ var peg$e57 = peg$otherExpectation("whitespace");
357
+ var peg$e58 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false);
358
+ var peg$e59 = peg$otherExpectation("mandatory whitespace");
359
+
360
+ var peg$f0 = function(stmt) { return stmt; };
361
+ var peg$f1 = function(optionsClause, fromClause, whereClause, rowAxis, colAxis) {
362
+ // ROWS declared first - row limits take priority
363
+ return {
364
+ type: 'table',
365
+ source: fromClause ?? null,
366
+ where: whereClause ?? null,
367
+ options: optionsClause ?? {},
368
+ rowAxis: rowAxis,
369
+ colAxis: colAxis,
370
+ firstAxis: 'row'
371
+ };
372
+ };
373
+ var peg$f2 = function(optionsClause, fromClause, whereClause, colAxis, rowAxis) {
374
+ // COLS declared first - column limits take priority
375
+ return {
376
+ type: 'table',
377
+ source: fromClause ?? null,
378
+ where: whereClause ?? null,
379
+ options: optionsClause ?? {},
380
+ rowAxis: rowAxis,
381
+ colAxis: colAxis,
382
+ firstAxis: 'col'
383
+ };
384
+ };
385
+ var peg$f3 = function(optionsClause, fromClause, whereClause, rowAxis) {
386
+ // Single axis form (row only, for lists)
387
+ return {
388
+ type: 'table',
389
+ source: fromClause ?? null,
390
+ where: whereClause ?? null,
391
+ options: optionsClause ?? {},
392
+ rowAxis: rowAxis,
393
+ colAxis: null,
394
+ firstAxis: 'row'
395
+ };
396
+ };
397
+ var peg$f4 = function(options) {
398
+ return options.reduce((acc, opt) => ({ ...acc, ...opt }), {});
399
+ };
400
+ var peg$f5 = function(value) {
401
+ return { rowHeaders: value.toLowerCase() };
402
+ };
403
+ var peg$f6 = function(value) {
404
+ return { includeNulls: value.toLowerCase() === 'true' };
405
+ };
406
+ var peg$f7 = function(source) { return source; };
407
+ var peg$f8 = function(condition) { return condition; };
408
+ var peg$f9 = function(schema, table) { return schema + '.' + table; };
409
+ var peg$f10 = function(table) { return table; };
410
+ var peg$f11 = function(expr) { return expr.trim(); };
411
+ var peg$f12 = function(head, tail) {
412
+ const groups = [head, ...tail.map(t => t[1])];
413
+ return makeAxis(groups);
414
+ };
415
+ var peg$f13 = function() { return '|'; };
416
+ var peg$f14 = function() { return 'THEN'; };
417
+ var peg$f15 = function(head, tail) {
418
+ const items = [head, ...tail.map(t => t[1])];
419
+ return makeGroup(items);
420
+ };
421
+ var peg$f16 = function() { return '*'; };
422
+ var peg$f17 = function() { return 'BY'; };
423
+ var peg$f18 = function(inner, aggs, annotations, label) {
424
+ // (revenue | cost).(sum | mean) - group binding with multiple aggregations
425
+ const ann = mergeAnnotations(annotations);
426
+ if (label) ann.label = label;
427
+ return { type: 'annotatedGroup', inner: inner, aggregations: aggs, ...ann };
428
+ };
429
+ var peg$f19 = function(inner, agg, annotations, label) {
430
+ // (revenue cost).sum - group binding with single aggregation
431
+ const ann = mergeAnnotations(annotations);
432
+ if (label) ann.label = label;
433
+ return { type: 'annotatedGroup', inner: inner, aggregations: [agg], ...ann };
434
+ };
435
+ var peg$f20 = function(inner, annotations, label) {
436
+ const ann = mergeAnnotations(annotations);
437
+ if (label) ann.label = label;
438
+ // If annotations present, wrap in annotated group for compiler to distribute
439
+ if (Object.keys(ann).length > 0) {
440
+ return { type: 'annotatedGroup', inner: inner, ...ann };
441
+ }
442
+ return inner;
443
+ };
444
+ var peg$f21 = function(label) { return label; };
445
+ var peg$f22 = function(measure, method, scope, annotations, label) {
446
+ // measure.agg ACROSS [scope] - measure binding percentage (no enclosing parens required)
447
+ const ann = mergeAnnotations(annotations);
448
+ if (label) ann.label = label;
449
+ return makePercentageAggregate(measure, method, scope ?? 'all', ann);
450
+ };
451
+ var peg$f23 = function(method, scope, annotations, label) {
452
+ // agg ACROSS [scope] - standalone aggregation percentage (e.g., count ACROSS)
453
+ const ann = mergeAnnotations(annotations);
454
+ if (label) ann.label = label;
455
+ return makePercentageAggregate(null, method, scope ?? 'all', ann);
456
+ };
457
+ var peg$f24 = function() { return 'cols'; };
458
+ var peg$f25 = function() { return 'rows'; };
459
+ var peg$f26 = function(dims) { return dims; };
460
+ var peg$f27 = function(name, aggs, annotations, label) {
461
+ // measure.(sum | mean) - binding with multiple aggregations
462
+ const ann = mergeAnnotations(annotations);
463
+ if (label) ann.label = label;
464
+ return makeBinding(name, aggs, ann);
465
+ };
466
+ var peg$f28 = function(name, agg, annotations, label) {
467
+ // measure.sum or measure.sum:currency - binding with single aggregation
468
+ const ann = mergeAnnotations(annotations);
469
+ if (label) ann.label = label;
470
+ return makeBinding(name, [agg], ann);
471
+ };
472
+ var peg$f29 = function(name, preAnn, orderDir, postAnn, label) {
473
+ const ann = mergeAnnotations([...preAnn, ...postAnn]);
474
+ if (label) ann.label = label;
475
+
476
+ // Forbid redundant limit + ASC/DESC combinations
477
+ // If there's a limit, the direction comes from [-N] vs [N], not ASC/DESC
478
+ if (ann.limit && orderDir) {
479
+ error('Cannot combine limit [N] with ASC/DESC keyword. Use [-N] for descending or [N] for ascending.');
480
+ }
481
+
482
+ // Merge order direction with order annotation if both present
483
+ if (orderDir) {
484
+ if (ann.order) {
485
+ // Merge direction into existing order (from @field.agg annotation)
486
+ ann.order.direction = orderDir;
487
+ } else {
488
+ // Create new order with just direction
489
+ ann.order = { direction: orderDir };
490
+ }
491
+ } else if (ann.order && !ann.order.direction) {
492
+ // Default direction is DESC when using @field.agg without explicit ASC/DESC
493
+ ann.order.direction = 'desc';
494
+ }
495
+
496
+ // If it has a format, it's likely a measure; otherwise dimension
497
+ // The compiler will resolve this based on schema
498
+ if (ann.format) {
499
+ return makeMeasure(name, ann);
500
+ }
501
+ return makeDimension(name, ann);
502
+ };
503
+ var peg$f30 = function(dir) { return dir.toLowerCase(); };
504
+ var peg$f31 = function(head, tail) {
505
+ return [head, ...tail.map(t => t[1])];
506
+ };
507
+ var peg$f32 = function() { return '|'; };
508
+ var peg$f33 = function() { return 'THEN'; };
509
+ var peg$f34 = function(method, format, label) {
510
+ const result = { method };
511
+ if (format && format.format) result.format = format.format;
512
+ if (label) result.label = label;
513
+ return result;
514
+ };
515
+ var peg$f35 = function(method, annotations, label) {
516
+ const ann = mergeAnnotations(annotations);
517
+ if (label) ann.label = label;
518
+ return makeAggregation(method, ann);
519
+ };
520
+ var peg$f36 = function() { return 'sum'; };
521
+ var peg$f37 = function() { return 'mean'; };
522
+ var peg$f38 = function() { return 'mean'; };
523
+ var peg$f39 = function() { return 'count'; };
524
+ var peg$f40 = function() { return 'min'; };
525
+ var peg$f41 = function() { return 'max'; };
526
+ var peg$f42 = function() { return 'median'; };
527
+ var peg$f43 = function() { return 'stdev'; };
528
+ var peg$f44 = function() { return 'pct'; };
529
+ var peg$f45 = function() { return 'pctn'; };
530
+ var peg$f46 = function() { return 'pctsum'; };
531
+ var peg$f47 = function() { return 'count'; };
532
+ var peg$f48 = function(annotations, label) {
533
+ const ann = mergeAnnotations(annotations);
534
+ if (label) ann.label = label;
535
+ return makeAll(ann);
536
+ };
537
+ var peg$f49 = function(ann) { return ann; };
538
+ var peg$f50 = function(ann) { return ann; };
539
+ var peg$f51 = function(ann) { return ann; };
540
+ var peg$f52 = function(format) {
541
+ return { format: format };
542
+ };
543
+ var peg$f53 = function() { return { type: 'currency' }; };
544
+ var peg$f54 = function() { return { type: 'percent' }; };
545
+ var peg$f55 = function() { return { type: 'integer' }; };
546
+ var peg$f56 = function(digits) { return { type: 'decimal', precision: parseInt(digits, 10) }; };
547
+ var peg$f57 = function(digits) { return { type: 'comma', precision: parseInt(digits, 10) }; };
548
+ var peg$f58 = function(str) { return { type: 'custom', pattern: str }; };
549
+ var peg$f59 = function(sign, count, orderBy) {
550
+ const direction = sign ? 'desc' : 'asc';
551
+ const limit = {
552
+ count: parseInt(count, 10),
553
+ direction
554
+ };
555
+ if (orderBy) {
556
+ limit.orderBy = orderBy;
557
+ }
558
+ return { limit };
559
+ };
560
+ var peg$f60 = function(expr) { return expr; };
561
+ var peg$f61 = function(expr) { return expr; };
562
+ var peg$f62 = function(agg) {
563
+ // Standalone count/n (or other aggregation keywords) - use empty field
564
+ return makeAggregateExpr('', agg, null);
565
+ };
566
+ var peg$f63 = function(field, agg) { return field + '.' + agg; };
567
+ var peg$f64 = function(field) { return field; };
568
+ var peg$f65 = function(left, right) {
569
+ // Explicit ratio: births.sum / births.sum ACROSS name
570
+ return makeRatioExpr(left, right);
571
+ };
572
+ var peg$f66 = function(expr) {
573
+ // Implicit ratio: births.sum ACROSS name -> births.sum / births.sum ACROSS name
574
+ if (expr.ungroupedDimensions && expr.ungroupedDimensions.length > 0) {
575
+ // Create implicit ratio: same measure/agg as numerator and denominator
576
+ const numerator = makeAggregateExpr(expr.field, expr.function, null);
577
+ return makeRatioExpr(numerator, expr);
578
+ }
579
+ // No ACROSS, just a simple aggregate
580
+ return expr;
581
+ };
582
+ var peg$f67 = function(field, agg, ungrouped) {
583
+ return makeAggregateExpr(field, agg, ungrouped);
584
+ };
585
+ var peg$f68 = function(field, agg) {
586
+ return makeAggregateExpr(field, agg, null);
587
+ };
588
+ var peg$f69 = function(dims) { return dims; };
589
+ var peg$f70 = function(dims) { return dims; };
590
+ var peg$f71 = function(head, tail) {
591
+ return [head, ...tail.map(t => t[1])];
592
+ };
593
+ var peg$f72 = function(expr) {
594
+ return { order: { orderBy: expr } };
595
+ };
596
+ var peg$f73 = function(expr) {
597
+ return { order: { orderBy: expr } };
598
+ };
599
+ var peg$f74 = function(agg) {
600
+ // Standalone count/n (or other aggregation keywords) - use empty field
601
+ return { order: { orderBy: makeAggregateExpr('', agg, null) } };
602
+ };
603
+ var peg$f75 = function(field, agg) {
604
+ return { order: { orderBy: field + '.' + agg } };
605
+ };
606
+ var peg$f76 = function(field) {
607
+ return { order: { orderBy: field } };
608
+ };
609
+ var peg$f77 = function(baseline) {
610
+ return { diff: baseline };
611
+ };
612
+ var peg$f78 = function(dimension) {
613
+ return { over: dimension };
614
+ };
615
+ var peg$f79 = function() {
616
+ return { over: 'ALL' };
617
+ };
618
+ var peg$f80 = function(id) { return id; };
619
+ var peg$f81 = function(chars) { return chars; };
620
+ var peg$f82 = function(chars) { return chars; };
621
+ var peg$currPos = options.peg$currPos | 0;
622
+ var peg$savedPos = peg$currPos;
623
+ var peg$posDetailsCache = [{ line: 1, column: 1 }];
624
+ var peg$maxFailPos = peg$currPos;
625
+ var peg$maxFailExpected = options.peg$maxFailExpected || [];
626
+ var peg$silentFails = options.peg$silentFails | 0;
627
+
628
+ var peg$result;
629
+
630
+ if (options.startRule) {
631
+ if (!(options.startRule in peg$startRuleFunctions)) {
632
+ throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
633
+ }
634
+
635
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
636
+ }
637
+
638
+ function text() {
639
+ return input.substring(peg$savedPos, peg$currPos);
640
+ }
641
+
642
+ function offset() {
643
+ return peg$savedPos;
644
+ }
645
+
646
+ function range() {
647
+ return {
648
+ source: peg$source,
649
+ start: peg$savedPos,
650
+ end: peg$currPos
651
+ };
652
+ }
653
+
654
+ function location() {
655
+ return peg$computeLocation(peg$savedPos, peg$currPos);
656
+ }
657
+
658
+ function expected(description, location) {
659
+ location = location !== undefined
660
+ ? location
661
+ : peg$computeLocation(peg$savedPos, peg$currPos);
662
+
663
+ throw peg$buildStructuredError(
664
+ [peg$otherExpectation(description)],
665
+ input.substring(peg$savedPos, peg$currPos),
666
+ location
667
+ );
668
+ }
669
+
670
+ function error(message, location) {
671
+ location = location !== undefined
672
+ ? location
673
+ : peg$computeLocation(peg$savedPos, peg$currPos);
674
+
675
+ throw peg$buildSimpleError(message, location);
676
+ }
677
+
678
+ function peg$literalExpectation(text, ignoreCase) {
679
+ return { type: "literal", text: text, ignoreCase: ignoreCase };
680
+ }
681
+
682
+ function peg$classExpectation(parts, inverted, ignoreCase) {
683
+ return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
684
+ }
685
+
686
+ function peg$anyExpectation() {
687
+ return { type: "any" };
688
+ }
689
+
690
+ function peg$endExpectation() {
691
+ return { type: "end" };
692
+ }
693
+
694
+ function peg$otherExpectation(description) {
695
+ return { type: "other", description: description };
696
+ }
697
+
698
+ function peg$computePosDetails(pos) {
699
+ var details = peg$posDetailsCache[pos];
700
+ var p;
701
+
702
+ if (details) {
703
+ return details;
704
+ } else {
705
+ if (pos >= peg$posDetailsCache.length) {
706
+ p = peg$posDetailsCache.length - 1;
707
+ } else {
708
+ p = pos;
709
+ while (!peg$posDetailsCache[--p]) {}
710
+ }
711
+
712
+ details = peg$posDetailsCache[p];
713
+ details = {
714
+ line: details.line,
715
+ column: details.column
716
+ };
717
+
718
+ while (p < pos) {
719
+ if (input.charCodeAt(p) === 10) {
720
+ details.line++;
721
+ details.column = 1;
722
+ } else {
723
+ details.column++;
724
+ }
725
+
726
+ p++;
727
+ }
728
+
729
+ peg$posDetailsCache[pos] = details;
730
+
731
+ return details;
732
+ }
733
+ }
734
+
735
+ function peg$computeLocation(startPos, endPos, offset) {
736
+ var startPosDetails = peg$computePosDetails(startPos);
737
+ var endPosDetails = peg$computePosDetails(endPos);
738
+
739
+ var res = {
740
+ source: peg$source,
741
+ start: {
742
+ offset: startPos,
743
+ line: startPosDetails.line,
744
+ column: startPosDetails.column
745
+ },
746
+ end: {
747
+ offset: endPos,
748
+ line: endPosDetails.line,
749
+ column: endPosDetails.column
750
+ }
751
+ };
752
+ if (offset && peg$source && (typeof peg$source.offset === "function")) {
753
+ res.start = peg$source.offset(res.start);
754
+ res.end = peg$source.offset(res.end);
755
+ }
756
+ return res;
757
+ }
758
+
759
+ function peg$fail(expected) {
760
+ if (peg$currPos < peg$maxFailPos) { return; }
761
+
762
+ if (peg$currPos > peg$maxFailPos) {
763
+ peg$maxFailPos = peg$currPos;
764
+ peg$maxFailExpected = [];
765
+ }
766
+
767
+ peg$maxFailExpected.push(expected);
768
+ }
769
+
770
+ function peg$buildSimpleError(message, location) {
771
+ return new peg$SyntaxError(message, null, null, location);
772
+ }
773
+
774
+ function peg$buildStructuredError(expected, found, location) {
775
+ return new peg$SyntaxError(
776
+ peg$SyntaxError.buildMessage(expected, found),
777
+ expected,
778
+ found,
779
+ location
780
+ );
781
+ }
782
+
783
+ function peg$parsestart() {
784
+ var s0, s1, s2, s3;
785
+
786
+ s0 = peg$currPos;
787
+ s1 = peg$parse_();
788
+ s2 = peg$parsetableStatement();
789
+ if (s2 !== peg$FAILED) {
790
+ s3 = peg$parse_();
791
+ peg$savedPos = s0;
792
+ s0 = peg$f0(s2);
793
+ } else {
794
+ peg$currPos = s0;
795
+ s0 = peg$FAILED;
796
+ }
797
+
798
+ return s0;
799
+ }
800
+
801
+ function peg$parsetableStatement() {
802
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
803
+
804
+ s0 = peg$currPos;
805
+ s1 = peg$parseTABLE();
806
+ if (s1 !== peg$FAILED) {
807
+ s2 = peg$parseoptionsClause();
808
+ if (s2 === peg$FAILED) {
809
+ s2 = null;
810
+ }
811
+ s3 = peg$parsefromClause();
812
+ if (s3 === peg$FAILED) {
813
+ s3 = null;
814
+ }
815
+ s4 = peg$parsewhereClause();
816
+ if (s4 === peg$FAILED) {
817
+ s4 = null;
818
+ }
819
+ s5 = peg$parse__();
820
+ if (s5 !== peg$FAILED) {
821
+ s6 = peg$parseROWS();
822
+ if (s6 !== peg$FAILED) {
823
+ s7 = peg$parse__();
824
+ if (s7 !== peg$FAILED) {
825
+ s8 = peg$parseaxis();
826
+ if (s8 !== peg$FAILED) {
827
+ s9 = peg$parse__();
828
+ if (s9 !== peg$FAILED) {
829
+ s10 = peg$parseCOLS();
830
+ if (s10 !== peg$FAILED) {
831
+ s11 = peg$parse__();
832
+ if (s11 !== peg$FAILED) {
833
+ s12 = peg$parseaxis();
834
+ if (s12 !== peg$FAILED) {
835
+ s13 = peg$parse_();
836
+ if (input.charCodeAt(peg$currPos) === 59) {
837
+ s14 = peg$c0;
838
+ peg$currPos++;
839
+ } else {
840
+ s14 = peg$FAILED;
841
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
842
+ }
843
+ if (s14 !== peg$FAILED) {
844
+ peg$savedPos = s0;
845
+ s0 = peg$f1(s2, s3, s4, s8, s12);
846
+ } else {
847
+ peg$currPos = s0;
848
+ s0 = peg$FAILED;
849
+ }
850
+ } else {
851
+ peg$currPos = s0;
852
+ s0 = peg$FAILED;
853
+ }
854
+ } else {
855
+ peg$currPos = s0;
856
+ s0 = peg$FAILED;
857
+ }
858
+ } else {
859
+ peg$currPos = s0;
860
+ s0 = peg$FAILED;
861
+ }
862
+ } else {
863
+ peg$currPos = s0;
864
+ s0 = peg$FAILED;
865
+ }
866
+ } else {
867
+ peg$currPos = s0;
868
+ s0 = peg$FAILED;
869
+ }
870
+ } else {
871
+ peg$currPos = s0;
872
+ s0 = peg$FAILED;
873
+ }
874
+ } else {
875
+ peg$currPos = s0;
876
+ s0 = peg$FAILED;
877
+ }
878
+ } else {
879
+ peg$currPos = s0;
880
+ s0 = peg$FAILED;
881
+ }
882
+ } else {
883
+ peg$currPos = s0;
884
+ s0 = peg$FAILED;
885
+ }
886
+ if (s0 === peg$FAILED) {
887
+ s0 = peg$currPos;
888
+ s1 = peg$parseTABLE();
889
+ if (s1 !== peg$FAILED) {
890
+ s2 = peg$parseoptionsClause();
891
+ if (s2 === peg$FAILED) {
892
+ s2 = null;
893
+ }
894
+ s3 = peg$parsefromClause();
895
+ if (s3 === peg$FAILED) {
896
+ s3 = null;
897
+ }
898
+ s4 = peg$parsewhereClause();
899
+ if (s4 === peg$FAILED) {
900
+ s4 = null;
901
+ }
902
+ s5 = peg$parse__();
903
+ if (s5 !== peg$FAILED) {
904
+ s6 = peg$parseCOLS();
905
+ if (s6 !== peg$FAILED) {
906
+ s7 = peg$parse__();
907
+ if (s7 !== peg$FAILED) {
908
+ s8 = peg$parseaxis();
909
+ if (s8 !== peg$FAILED) {
910
+ s9 = peg$parse__();
911
+ if (s9 !== peg$FAILED) {
912
+ s10 = peg$parseROWS();
913
+ if (s10 !== peg$FAILED) {
914
+ s11 = peg$parse__();
915
+ if (s11 !== peg$FAILED) {
916
+ s12 = peg$parseaxis();
917
+ if (s12 !== peg$FAILED) {
918
+ s13 = peg$parse_();
919
+ if (input.charCodeAt(peg$currPos) === 59) {
920
+ s14 = peg$c0;
921
+ peg$currPos++;
922
+ } else {
923
+ s14 = peg$FAILED;
924
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
925
+ }
926
+ if (s14 !== peg$FAILED) {
927
+ peg$savedPos = s0;
928
+ s0 = peg$f2(s2, s3, s4, s8, s12);
929
+ } else {
930
+ peg$currPos = s0;
931
+ s0 = peg$FAILED;
932
+ }
933
+ } else {
934
+ peg$currPos = s0;
935
+ s0 = peg$FAILED;
936
+ }
937
+ } else {
938
+ peg$currPos = s0;
939
+ s0 = peg$FAILED;
940
+ }
941
+ } else {
942
+ peg$currPos = s0;
943
+ s0 = peg$FAILED;
944
+ }
945
+ } else {
946
+ peg$currPos = s0;
947
+ s0 = peg$FAILED;
948
+ }
949
+ } else {
950
+ peg$currPos = s0;
951
+ s0 = peg$FAILED;
952
+ }
953
+ } else {
954
+ peg$currPos = s0;
955
+ s0 = peg$FAILED;
956
+ }
957
+ } else {
958
+ peg$currPos = s0;
959
+ s0 = peg$FAILED;
960
+ }
961
+ } else {
962
+ peg$currPos = s0;
963
+ s0 = peg$FAILED;
964
+ }
965
+ } else {
966
+ peg$currPos = s0;
967
+ s0 = peg$FAILED;
968
+ }
969
+ if (s0 === peg$FAILED) {
970
+ s0 = peg$currPos;
971
+ s1 = peg$parseTABLE();
972
+ if (s1 !== peg$FAILED) {
973
+ s2 = peg$parseoptionsClause();
974
+ if (s2 === peg$FAILED) {
975
+ s2 = null;
976
+ }
977
+ s3 = peg$parsefromClause();
978
+ if (s3 === peg$FAILED) {
979
+ s3 = null;
980
+ }
981
+ s4 = peg$parsewhereClause();
982
+ if (s4 === peg$FAILED) {
983
+ s4 = null;
984
+ }
985
+ s5 = peg$parse__();
986
+ if (s5 !== peg$FAILED) {
987
+ s6 = peg$parseROWS();
988
+ if (s6 !== peg$FAILED) {
989
+ s7 = peg$parse__();
990
+ if (s7 !== peg$FAILED) {
991
+ s8 = peg$parseaxis();
992
+ if (s8 !== peg$FAILED) {
993
+ s9 = peg$parse_();
994
+ if (input.charCodeAt(peg$currPos) === 59) {
995
+ s10 = peg$c0;
996
+ peg$currPos++;
997
+ } else {
998
+ s10 = peg$FAILED;
999
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
1000
+ }
1001
+ if (s10 !== peg$FAILED) {
1002
+ peg$savedPos = s0;
1003
+ s0 = peg$f3(s2, s3, s4, s8);
1004
+ } else {
1005
+ peg$currPos = s0;
1006
+ s0 = peg$FAILED;
1007
+ }
1008
+ } else {
1009
+ peg$currPos = s0;
1010
+ s0 = peg$FAILED;
1011
+ }
1012
+ } else {
1013
+ peg$currPos = s0;
1014
+ s0 = peg$FAILED;
1015
+ }
1016
+ } else {
1017
+ peg$currPos = s0;
1018
+ s0 = peg$FAILED;
1019
+ }
1020
+ } else {
1021
+ peg$currPos = s0;
1022
+ s0 = peg$FAILED;
1023
+ }
1024
+ } else {
1025
+ peg$currPos = s0;
1026
+ s0 = peg$FAILED;
1027
+ }
1028
+ }
1029
+ }
1030
+
1031
+ return s0;
1032
+ }
1033
+
1034
+ function peg$parseoptionsClause() {
1035
+ var s0, s1, s2, s3, s4, s5;
1036
+
1037
+ s0 = peg$currPos;
1038
+ s1 = peg$parse__();
1039
+ if (s1 !== peg$FAILED) {
1040
+ s2 = peg$parseOPTIONS();
1041
+ if (s2 !== peg$FAILED) {
1042
+ s3 = peg$parse__();
1043
+ if (s3 !== peg$FAILED) {
1044
+ s4 = [];
1045
+ s5 = peg$parsetableOption();
1046
+ if (s5 !== peg$FAILED) {
1047
+ while (s5 !== peg$FAILED) {
1048
+ s4.push(s5);
1049
+ s5 = peg$parsetableOption();
1050
+ }
1051
+ } else {
1052
+ s4 = peg$FAILED;
1053
+ }
1054
+ if (s4 !== peg$FAILED) {
1055
+ peg$savedPos = s0;
1056
+ s0 = peg$f4(s4);
1057
+ } else {
1058
+ peg$currPos = s0;
1059
+ s0 = peg$FAILED;
1060
+ }
1061
+ } else {
1062
+ peg$currPos = s0;
1063
+ s0 = peg$FAILED;
1064
+ }
1065
+ } else {
1066
+ peg$currPos = s0;
1067
+ s0 = peg$FAILED;
1068
+ }
1069
+ } else {
1070
+ peg$currPos = s0;
1071
+ s0 = peg$FAILED;
1072
+ }
1073
+
1074
+ return s0;
1075
+ }
1076
+
1077
+ function peg$parsetableOption() {
1078
+ var s0, s1, s2, s3, s4;
1079
+
1080
+ s0 = peg$currPos;
1081
+ s1 = peg$parse_();
1082
+ s2 = input.substr(peg$currPos, 10);
1083
+ if (s2.toLowerCase() === peg$c1) {
1084
+ peg$currPos += 10;
1085
+ } else {
1086
+ s2 = peg$FAILED;
1087
+ if (peg$silentFails === 0) { peg$fail(peg$e1); }
1088
+ }
1089
+ if (s2 !== peg$FAILED) {
1090
+ if (input.charCodeAt(peg$currPos) === 58) {
1091
+ s3 = peg$c2;
1092
+ peg$currPos++;
1093
+ } else {
1094
+ s3 = peg$FAILED;
1095
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1096
+ }
1097
+ if (s3 !== peg$FAILED) {
1098
+ s4 = input.substr(peg$currPos, 5);
1099
+ if (s4.toLowerCase() === peg$c3) {
1100
+ peg$currPos += 5;
1101
+ } else {
1102
+ s4 = peg$FAILED;
1103
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
1104
+ }
1105
+ if (s4 === peg$FAILED) {
1106
+ s4 = input.substr(peg$currPos, 4);
1107
+ if (s4.toLowerCase() === peg$c4) {
1108
+ peg$currPos += 4;
1109
+ } else {
1110
+ s4 = peg$FAILED;
1111
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
1112
+ }
1113
+ }
1114
+ if (s4 !== peg$FAILED) {
1115
+ peg$savedPos = s0;
1116
+ s0 = peg$f5(s4);
1117
+ } else {
1118
+ peg$currPos = s0;
1119
+ s0 = peg$FAILED;
1120
+ }
1121
+ } else {
1122
+ peg$currPos = s0;
1123
+ s0 = peg$FAILED;
1124
+ }
1125
+ } else {
1126
+ peg$currPos = s0;
1127
+ s0 = peg$FAILED;
1128
+ }
1129
+ if (s0 === peg$FAILED) {
1130
+ s0 = peg$currPos;
1131
+ s1 = peg$parse_();
1132
+ s2 = input.substr(peg$currPos, 12);
1133
+ if (s2.toLowerCase() === peg$c5) {
1134
+ peg$currPos += 12;
1135
+ } else {
1136
+ s2 = peg$FAILED;
1137
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
1138
+ }
1139
+ if (s2 !== peg$FAILED) {
1140
+ if (input.charCodeAt(peg$currPos) === 58) {
1141
+ s3 = peg$c2;
1142
+ peg$currPos++;
1143
+ } else {
1144
+ s3 = peg$FAILED;
1145
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
1146
+ }
1147
+ if (s3 !== peg$FAILED) {
1148
+ s4 = input.substr(peg$currPos, 4);
1149
+ if (s4.toLowerCase() === peg$c6) {
1150
+ peg$currPos += 4;
1151
+ } else {
1152
+ s4 = peg$FAILED;
1153
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
1154
+ }
1155
+ if (s4 === peg$FAILED) {
1156
+ s4 = input.substr(peg$currPos, 5);
1157
+ if (s4.toLowerCase() === peg$c7) {
1158
+ peg$currPos += 5;
1159
+ } else {
1160
+ s4 = peg$FAILED;
1161
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
1162
+ }
1163
+ }
1164
+ if (s4 !== peg$FAILED) {
1165
+ peg$savedPos = s0;
1166
+ s0 = peg$f6(s4);
1167
+ } else {
1168
+ peg$currPos = s0;
1169
+ s0 = peg$FAILED;
1170
+ }
1171
+ } else {
1172
+ peg$currPos = s0;
1173
+ s0 = peg$FAILED;
1174
+ }
1175
+ } else {
1176
+ peg$currPos = s0;
1177
+ s0 = peg$FAILED;
1178
+ }
1179
+ }
1180
+
1181
+ return s0;
1182
+ }
1183
+
1184
+ function peg$parsefromClause() {
1185
+ var s0, s1, s2, s3, s4;
1186
+
1187
+ s0 = peg$currPos;
1188
+ s1 = peg$parse__();
1189
+ if (s1 !== peg$FAILED) {
1190
+ s2 = peg$parseFROM();
1191
+ if (s2 !== peg$FAILED) {
1192
+ s3 = peg$parse__();
1193
+ if (s3 !== peg$FAILED) {
1194
+ s4 = peg$parsesourceIdentifier();
1195
+ if (s4 !== peg$FAILED) {
1196
+ peg$savedPos = s0;
1197
+ s0 = peg$f7(s4);
1198
+ } else {
1199
+ peg$currPos = s0;
1200
+ s0 = peg$FAILED;
1201
+ }
1202
+ } else {
1203
+ peg$currPos = s0;
1204
+ s0 = peg$FAILED;
1205
+ }
1206
+ } else {
1207
+ peg$currPos = s0;
1208
+ s0 = peg$FAILED;
1209
+ }
1210
+ } else {
1211
+ peg$currPos = s0;
1212
+ s0 = peg$FAILED;
1213
+ }
1214
+
1215
+ return s0;
1216
+ }
1217
+
1218
+ function peg$parsewhereClause() {
1219
+ var s0, s1, s2, s3, s4;
1220
+
1221
+ s0 = peg$currPos;
1222
+ s1 = peg$parse__();
1223
+ if (s1 !== peg$FAILED) {
1224
+ s2 = peg$parseWHERE();
1225
+ if (s2 !== peg$FAILED) {
1226
+ s3 = peg$parse__();
1227
+ if (s3 !== peg$FAILED) {
1228
+ s4 = peg$parsewhereExpression();
1229
+ if (s4 !== peg$FAILED) {
1230
+ peg$savedPos = s0;
1231
+ s0 = peg$f8(s4);
1232
+ } else {
1233
+ peg$currPos = s0;
1234
+ s0 = peg$FAILED;
1235
+ }
1236
+ } else {
1237
+ peg$currPos = s0;
1238
+ s0 = peg$FAILED;
1239
+ }
1240
+ } else {
1241
+ peg$currPos = s0;
1242
+ s0 = peg$FAILED;
1243
+ }
1244
+ } else {
1245
+ peg$currPos = s0;
1246
+ s0 = peg$FAILED;
1247
+ }
1248
+
1249
+ return s0;
1250
+ }
1251
+
1252
+ function peg$parsesourceIdentifier() {
1253
+ var s0, s1, s2, s3;
1254
+
1255
+ s0 = peg$currPos;
1256
+ s1 = peg$parseidentifier();
1257
+ if (s1 !== peg$FAILED) {
1258
+ if (input.charCodeAt(peg$currPos) === 46) {
1259
+ s2 = peg$c8;
1260
+ peg$currPos++;
1261
+ } else {
1262
+ s2 = peg$FAILED;
1263
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
1264
+ }
1265
+ if (s2 !== peg$FAILED) {
1266
+ s3 = peg$parseidentifier();
1267
+ if (s3 !== peg$FAILED) {
1268
+ peg$savedPos = s0;
1269
+ s0 = peg$f9(s1, s3);
1270
+ } else {
1271
+ peg$currPos = s0;
1272
+ s0 = peg$FAILED;
1273
+ }
1274
+ } else {
1275
+ peg$currPos = s0;
1276
+ s0 = peg$FAILED;
1277
+ }
1278
+ } else {
1279
+ peg$currPos = s0;
1280
+ s0 = peg$FAILED;
1281
+ }
1282
+ if (s0 === peg$FAILED) {
1283
+ s0 = peg$currPos;
1284
+ s1 = peg$parseidentifier();
1285
+ if (s1 !== peg$FAILED) {
1286
+ peg$savedPos = s0;
1287
+ s1 = peg$f10(s1);
1288
+ }
1289
+ s0 = s1;
1290
+ }
1291
+
1292
+ return s0;
1293
+ }
1294
+
1295
+ function peg$parsewhereExpression() {
1296
+ var s0, s1, s2, s3;
1297
+
1298
+ s0 = peg$currPos;
1299
+ s1 = peg$currPos;
1300
+ s2 = [];
1301
+ s3 = peg$parsewhereChar();
1302
+ if (s3 !== peg$FAILED) {
1303
+ while (s3 !== peg$FAILED) {
1304
+ s2.push(s3);
1305
+ s3 = peg$parsewhereChar();
1306
+ }
1307
+ } else {
1308
+ s2 = peg$FAILED;
1309
+ }
1310
+ if (s2 !== peg$FAILED) {
1311
+ s1 = input.substring(s1, peg$currPos);
1312
+ } else {
1313
+ s1 = s2;
1314
+ }
1315
+ if (s1 !== peg$FAILED) {
1316
+ peg$savedPos = s0;
1317
+ s1 = peg$f11(s1);
1318
+ }
1319
+ s0 = s1;
1320
+
1321
+ return s0;
1322
+ }
1323
+
1324
+ function peg$parsewhereChar() {
1325
+ var s0, s1, s2, s3, s4;
1326
+
1327
+ s0 = peg$currPos;
1328
+ s1 = peg$currPos;
1329
+ peg$silentFails++;
1330
+ s2 = peg$currPos;
1331
+ s3 = peg$parse_();
1332
+ s4 = peg$parseROWS();
1333
+ if (s4 !== peg$FAILED) {
1334
+ s3 = [s3, s4];
1335
+ s2 = s3;
1336
+ } else {
1337
+ peg$currPos = s2;
1338
+ s2 = peg$FAILED;
1339
+ }
1340
+ peg$silentFails--;
1341
+ if (s2 === peg$FAILED) {
1342
+ s1 = undefined;
1343
+ } else {
1344
+ peg$currPos = s1;
1345
+ s1 = peg$FAILED;
1346
+ }
1347
+ if (s1 !== peg$FAILED) {
1348
+ if (input.length > peg$currPos) {
1349
+ s2 = input.charAt(peg$currPos);
1350
+ peg$currPos++;
1351
+ } else {
1352
+ s2 = peg$FAILED;
1353
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
1354
+ }
1355
+ if (s2 !== peg$FAILED) {
1356
+ s1 = [s1, s2];
1357
+ s0 = s1;
1358
+ } else {
1359
+ peg$currPos = s0;
1360
+ s0 = peg$FAILED;
1361
+ }
1362
+ } else {
1363
+ peg$currPos = s0;
1364
+ s0 = peg$FAILED;
1365
+ }
1366
+
1367
+ return s0;
1368
+ }
1369
+
1370
+ function peg$parseaxis() {
1371
+ var s0, s1, s2, s3, s4, s5;
1372
+
1373
+ s0 = peg$currPos;
1374
+ s1 = peg$parsegroup();
1375
+ if (s1 !== peg$FAILED) {
1376
+ s2 = [];
1377
+ s3 = peg$currPos;
1378
+ s4 = peg$parseconcatOp();
1379
+ if (s4 !== peg$FAILED) {
1380
+ s5 = peg$parsegroup();
1381
+ if (s5 !== peg$FAILED) {
1382
+ s4 = [s4, s5];
1383
+ s3 = s4;
1384
+ } else {
1385
+ peg$currPos = s3;
1386
+ s3 = peg$FAILED;
1387
+ }
1388
+ } else {
1389
+ peg$currPos = s3;
1390
+ s3 = peg$FAILED;
1391
+ }
1392
+ while (s3 !== peg$FAILED) {
1393
+ s2.push(s3);
1394
+ s3 = peg$currPos;
1395
+ s4 = peg$parseconcatOp();
1396
+ if (s4 !== peg$FAILED) {
1397
+ s5 = peg$parsegroup();
1398
+ if (s5 !== peg$FAILED) {
1399
+ s4 = [s4, s5];
1400
+ s3 = s4;
1401
+ } else {
1402
+ peg$currPos = s3;
1403
+ s3 = peg$FAILED;
1404
+ }
1405
+ } else {
1406
+ peg$currPos = s3;
1407
+ s3 = peg$FAILED;
1408
+ }
1409
+ }
1410
+ peg$savedPos = s0;
1411
+ s0 = peg$f12(s1, s2);
1412
+ } else {
1413
+ peg$currPos = s0;
1414
+ s0 = peg$FAILED;
1415
+ }
1416
+
1417
+ return s0;
1418
+ }
1419
+
1420
+ function peg$parseconcatOp() {
1421
+ var s0, s1, s2, s3;
1422
+
1423
+ s0 = peg$currPos;
1424
+ s1 = peg$parse_();
1425
+ if (input.charCodeAt(peg$currPos) === 124) {
1426
+ s2 = peg$c9;
1427
+ peg$currPos++;
1428
+ } else {
1429
+ s2 = peg$FAILED;
1430
+ if (peg$silentFails === 0) { peg$fail(peg$e10); }
1431
+ }
1432
+ if (s2 !== peg$FAILED) {
1433
+ s3 = peg$parse_();
1434
+ peg$savedPos = s0;
1435
+ s0 = peg$f13();
1436
+ } else {
1437
+ peg$currPos = s0;
1438
+ s0 = peg$FAILED;
1439
+ }
1440
+ if (s0 === peg$FAILED) {
1441
+ s0 = peg$currPos;
1442
+ s1 = peg$parse__();
1443
+ if (s1 !== peg$FAILED) {
1444
+ s2 = peg$parseTHEN();
1445
+ if (s2 !== peg$FAILED) {
1446
+ s3 = peg$parse__();
1447
+ if (s3 !== peg$FAILED) {
1448
+ peg$savedPos = s0;
1449
+ s0 = peg$f14();
1450
+ } else {
1451
+ peg$currPos = s0;
1452
+ s0 = peg$FAILED;
1453
+ }
1454
+ } else {
1455
+ peg$currPos = s0;
1456
+ s0 = peg$FAILED;
1457
+ }
1458
+ } else {
1459
+ peg$currPos = s0;
1460
+ s0 = peg$FAILED;
1461
+ }
1462
+ }
1463
+
1464
+ return s0;
1465
+ }
1466
+
1467
+ function peg$parsegroup() {
1468
+ var s0, s1, s2, s3, s4, s5;
1469
+
1470
+ s0 = peg$currPos;
1471
+ s1 = peg$parseitem();
1472
+ if (s1 !== peg$FAILED) {
1473
+ s2 = [];
1474
+ s3 = peg$currPos;
1475
+ s4 = peg$parsenestOp();
1476
+ if (s4 !== peg$FAILED) {
1477
+ s5 = peg$parseitem();
1478
+ if (s5 !== peg$FAILED) {
1479
+ s4 = [s4, s5];
1480
+ s3 = s4;
1481
+ } else {
1482
+ peg$currPos = s3;
1483
+ s3 = peg$FAILED;
1484
+ }
1485
+ } else {
1486
+ peg$currPos = s3;
1487
+ s3 = peg$FAILED;
1488
+ }
1489
+ while (s3 !== peg$FAILED) {
1490
+ s2.push(s3);
1491
+ s3 = peg$currPos;
1492
+ s4 = peg$parsenestOp();
1493
+ if (s4 !== peg$FAILED) {
1494
+ s5 = peg$parseitem();
1495
+ if (s5 !== peg$FAILED) {
1496
+ s4 = [s4, s5];
1497
+ s3 = s4;
1498
+ } else {
1499
+ peg$currPos = s3;
1500
+ s3 = peg$FAILED;
1501
+ }
1502
+ } else {
1503
+ peg$currPos = s3;
1504
+ s3 = peg$FAILED;
1505
+ }
1506
+ }
1507
+ peg$savedPos = s0;
1508
+ s0 = peg$f15(s1, s2);
1509
+ } else {
1510
+ peg$currPos = s0;
1511
+ s0 = peg$FAILED;
1512
+ }
1513
+
1514
+ return s0;
1515
+ }
1516
+
1517
+ function peg$parsenestOp() {
1518
+ var s0, s1, s2, s3;
1519
+
1520
+ s0 = peg$currPos;
1521
+ s1 = peg$parse_();
1522
+ if (input.charCodeAt(peg$currPos) === 42) {
1523
+ s2 = peg$c10;
1524
+ peg$currPos++;
1525
+ } else {
1526
+ s2 = peg$FAILED;
1527
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
1528
+ }
1529
+ if (s2 !== peg$FAILED) {
1530
+ s3 = peg$parse_();
1531
+ peg$savedPos = s0;
1532
+ s0 = peg$f16();
1533
+ } else {
1534
+ peg$currPos = s0;
1535
+ s0 = peg$FAILED;
1536
+ }
1537
+ if (s0 === peg$FAILED) {
1538
+ s0 = peg$currPos;
1539
+ s1 = peg$parse__();
1540
+ if (s1 !== peg$FAILED) {
1541
+ s2 = peg$parseBY();
1542
+ if (s2 !== peg$FAILED) {
1543
+ s3 = peg$parse__();
1544
+ if (s3 !== peg$FAILED) {
1545
+ peg$savedPos = s0;
1546
+ s0 = peg$f17();
1547
+ } else {
1548
+ peg$currPos = s0;
1549
+ s0 = peg$FAILED;
1550
+ }
1551
+ } else {
1552
+ peg$currPos = s0;
1553
+ s0 = peg$FAILED;
1554
+ }
1555
+ } else {
1556
+ peg$currPos = s0;
1557
+ s0 = peg$FAILED;
1558
+ }
1559
+ }
1560
+
1561
+ return s0;
1562
+ }
1563
+
1564
+ function peg$parseitem() {
1565
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
1566
+
1567
+ s0 = peg$parsepercentageAggregateRef();
1568
+ if (s0 === peg$FAILED) {
1569
+ s0 = peg$currPos;
1570
+ if (input.charCodeAt(peg$currPos) === 40) {
1571
+ s1 = peg$c11;
1572
+ peg$currPos++;
1573
+ } else {
1574
+ s1 = peg$FAILED;
1575
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1576
+ }
1577
+ if (s1 !== peg$FAILED) {
1578
+ s2 = peg$parse_();
1579
+ s3 = peg$parseaxis();
1580
+ if (s3 !== peg$FAILED) {
1581
+ s4 = peg$parse_();
1582
+ if (input.charCodeAt(peg$currPos) === 41) {
1583
+ s5 = peg$c12;
1584
+ peg$currPos++;
1585
+ } else {
1586
+ s5 = peg$FAILED;
1587
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1588
+ }
1589
+ if (s5 !== peg$FAILED) {
1590
+ if (input.charCodeAt(peg$currPos) === 46) {
1591
+ s6 = peg$c8;
1592
+ peg$currPos++;
1593
+ } else {
1594
+ s6 = peg$FAILED;
1595
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
1596
+ }
1597
+ if (s6 !== peg$FAILED) {
1598
+ if (input.charCodeAt(peg$currPos) === 40) {
1599
+ s7 = peg$c11;
1600
+ peg$currPos++;
1601
+ } else {
1602
+ s7 = peg$FAILED;
1603
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1604
+ }
1605
+ if (s7 !== peg$FAILED) {
1606
+ s8 = peg$parse_();
1607
+ s9 = peg$parseaggregationList();
1608
+ if (s9 !== peg$FAILED) {
1609
+ s10 = peg$parse_();
1610
+ if (input.charCodeAt(peg$currPos) === 41) {
1611
+ s11 = peg$c12;
1612
+ peg$currPos++;
1613
+ } else {
1614
+ s11 = peg$FAILED;
1615
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1616
+ }
1617
+ if (s11 !== peg$FAILED) {
1618
+ s12 = peg$parseannotations();
1619
+ s13 = peg$parseinlineLabel();
1620
+ if (s13 === peg$FAILED) {
1621
+ s13 = null;
1622
+ }
1623
+ peg$savedPos = s0;
1624
+ s0 = peg$f18(s3, s9, s12, s13);
1625
+ } else {
1626
+ peg$currPos = s0;
1627
+ s0 = peg$FAILED;
1628
+ }
1629
+ } else {
1630
+ peg$currPos = s0;
1631
+ s0 = peg$FAILED;
1632
+ }
1633
+ } else {
1634
+ peg$currPos = s0;
1635
+ s0 = peg$FAILED;
1636
+ }
1637
+ } else {
1638
+ peg$currPos = s0;
1639
+ s0 = peg$FAILED;
1640
+ }
1641
+ } else {
1642
+ peg$currPos = s0;
1643
+ s0 = peg$FAILED;
1644
+ }
1645
+ } else {
1646
+ peg$currPos = s0;
1647
+ s0 = peg$FAILED;
1648
+ }
1649
+ } else {
1650
+ peg$currPos = s0;
1651
+ s0 = peg$FAILED;
1652
+ }
1653
+ if (s0 === peg$FAILED) {
1654
+ s0 = peg$currPos;
1655
+ if (input.charCodeAt(peg$currPos) === 40) {
1656
+ s1 = peg$c11;
1657
+ peg$currPos++;
1658
+ } else {
1659
+ s1 = peg$FAILED;
1660
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1661
+ }
1662
+ if (s1 !== peg$FAILED) {
1663
+ s2 = peg$parse_();
1664
+ s3 = peg$parseaxis();
1665
+ if (s3 !== peg$FAILED) {
1666
+ s4 = peg$parse_();
1667
+ if (input.charCodeAt(peg$currPos) === 41) {
1668
+ s5 = peg$c12;
1669
+ peg$currPos++;
1670
+ } else {
1671
+ s5 = peg$FAILED;
1672
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1673
+ }
1674
+ if (s5 !== peg$FAILED) {
1675
+ if (input.charCodeAt(peg$currPos) === 46) {
1676
+ s6 = peg$c8;
1677
+ peg$currPos++;
1678
+ } else {
1679
+ s6 = peg$FAILED;
1680
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
1681
+ }
1682
+ if (s6 !== peg$FAILED) {
1683
+ s7 = peg$parseaggregationSpec();
1684
+ if (s7 !== peg$FAILED) {
1685
+ s8 = peg$parseannotations();
1686
+ s9 = peg$parseinlineLabel();
1687
+ if (s9 === peg$FAILED) {
1688
+ s9 = null;
1689
+ }
1690
+ peg$savedPos = s0;
1691
+ s0 = peg$f19(s3, s7, s8, s9);
1692
+ } else {
1693
+ peg$currPos = s0;
1694
+ s0 = peg$FAILED;
1695
+ }
1696
+ } else {
1697
+ peg$currPos = s0;
1698
+ s0 = peg$FAILED;
1699
+ }
1700
+ } else {
1701
+ peg$currPos = s0;
1702
+ s0 = peg$FAILED;
1703
+ }
1704
+ } else {
1705
+ peg$currPos = s0;
1706
+ s0 = peg$FAILED;
1707
+ }
1708
+ } else {
1709
+ peg$currPos = s0;
1710
+ s0 = peg$FAILED;
1711
+ }
1712
+ if (s0 === peg$FAILED) {
1713
+ s0 = peg$currPos;
1714
+ if (input.charCodeAt(peg$currPos) === 40) {
1715
+ s1 = peg$c11;
1716
+ peg$currPos++;
1717
+ } else {
1718
+ s1 = peg$FAILED;
1719
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1720
+ }
1721
+ if (s1 !== peg$FAILED) {
1722
+ s2 = peg$parse_();
1723
+ s3 = peg$parseaxis();
1724
+ if (s3 !== peg$FAILED) {
1725
+ s4 = peg$parse_();
1726
+ if (input.charCodeAt(peg$currPos) === 41) {
1727
+ s5 = peg$c12;
1728
+ peg$currPos++;
1729
+ } else {
1730
+ s5 = peg$FAILED;
1731
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1732
+ }
1733
+ if (s5 !== peg$FAILED) {
1734
+ s6 = peg$parseannotations();
1735
+ s7 = peg$parseinlineLabel();
1736
+ if (s7 === peg$FAILED) {
1737
+ s7 = null;
1738
+ }
1739
+ peg$savedPos = s0;
1740
+ s0 = peg$f20(s3, s6, s7);
1741
+ } else {
1742
+ peg$currPos = s0;
1743
+ s0 = peg$FAILED;
1744
+ }
1745
+ } else {
1746
+ peg$currPos = s0;
1747
+ s0 = peg$FAILED;
1748
+ }
1749
+ } else {
1750
+ peg$currPos = s0;
1751
+ s0 = peg$FAILED;
1752
+ }
1753
+ if (s0 === peg$FAILED) {
1754
+ s0 = peg$parseallRef();
1755
+ if (s0 === peg$FAILED) {
1756
+ s0 = peg$parseaggregationRef();
1757
+ if (s0 === peg$FAILED) {
1758
+ s0 = peg$parsefieldRef();
1759
+ }
1760
+ }
1761
+ }
1762
+ }
1763
+ }
1764
+ }
1765
+
1766
+ return s0;
1767
+ }
1768
+
1769
+ function peg$parseinlineLabel() {
1770
+ var s0, s1, s2;
1771
+
1772
+ s0 = peg$currPos;
1773
+ s1 = peg$parse__();
1774
+ if (s1 !== peg$FAILED) {
1775
+ s2 = peg$parsestringLiteral();
1776
+ if (s2 !== peg$FAILED) {
1777
+ peg$savedPos = s0;
1778
+ s0 = peg$f21(s2);
1779
+ } else {
1780
+ peg$currPos = s0;
1781
+ s0 = peg$FAILED;
1782
+ }
1783
+ } else {
1784
+ peg$currPos = s0;
1785
+ s0 = peg$FAILED;
1786
+ }
1787
+
1788
+ return s0;
1789
+ }
1790
+
1791
+ function peg$parsepercentageAggregateRef() {
1792
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8;
1793
+
1794
+ s0 = peg$currPos;
1795
+ s1 = peg$parseidentifier();
1796
+ if (s1 !== peg$FAILED) {
1797
+ if (input.charCodeAt(peg$currPos) === 46) {
1798
+ s2 = peg$c8;
1799
+ peg$currPos++;
1800
+ } else {
1801
+ s2 = peg$FAILED;
1802
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
1803
+ }
1804
+ if (s2 !== peg$FAILED) {
1805
+ s3 = peg$parseaggregationKeyword();
1806
+ if (s3 !== peg$FAILED) {
1807
+ s4 = peg$parse__();
1808
+ if (s4 !== peg$FAILED) {
1809
+ s5 = input.substr(peg$currPos, 6);
1810
+ if (s5.toLowerCase() === peg$c13) {
1811
+ peg$currPos += 6;
1812
+ } else {
1813
+ s5 = peg$FAILED;
1814
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1815
+ }
1816
+ if (s5 !== peg$FAILED) {
1817
+ s6 = peg$parsepercentageScope();
1818
+ if (s6 === peg$FAILED) {
1819
+ s6 = null;
1820
+ }
1821
+ s7 = peg$parseannotations();
1822
+ s8 = peg$parseinlineLabel();
1823
+ if (s8 === peg$FAILED) {
1824
+ s8 = null;
1825
+ }
1826
+ peg$savedPos = s0;
1827
+ s0 = peg$f22(s1, s3, s6, s7, s8);
1828
+ } else {
1829
+ peg$currPos = s0;
1830
+ s0 = peg$FAILED;
1831
+ }
1832
+ } else {
1833
+ peg$currPos = s0;
1834
+ s0 = peg$FAILED;
1835
+ }
1836
+ } else {
1837
+ peg$currPos = s0;
1838
+ s0 = peg$FAILED;
1839
+ }
1840
+ } else {
1841
+ peg$currPos = s0;
1842
+ s0 = peg$FAILED;
1843
+ }
1844
+ } else {
1845
+ peg$currPos = s0;
1846
+ s0 = peg$FAILED;
1847
+ }
1848
+ if (s0 === peg$FAILED) {
1849
+ s0 = peg$currPos;
1850
+ s1 = peg$parseaggregationKeyword();
1851
+ if (s1 !== peg$FAILED) {
1852
+ s2 = peg$parse__();
1853
+ if (s2 !== peg$FAILED) {
1854
+ s3 = input.substr(peg$currPos, 6);
1855
+ if (s3.toLowerCase() === peg$c13) {
1856
+ peg$currPos += 6;
1857
+ } else {
1858
+ s3 = peg$FAILED;
1859
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1860
+ }
1861
+ if (s3 !== peg$FAILED) {
1862
+ s4 = peg$parsepercentageScope();
1863
+ if (s4 === peg$FAILED) {
1864
+ s4 = null;
1865
+ }
1866
+ s5 = peg$parseannotations();
1867
+ s6 = peg$parseinlineLabel();
1868
+ if (s6 === peg$FAILED) {
1869
+ s6 = null;
1870
+ }
1871
+ peg$savedPos = s0;
1872
+ s0 = peg$f23(s1, s4, s5, s6);
1873
+ } else {
1874
+ peg$currPos = s0;
1875
+ s0 = peg$FAILED;
1876
+ }
1877
+ } else {
1878
+ peg$currPos = s0;
1879
+ s0 = peg$FAILED;
1880
+ }
1881
+ } else {
1882
+ peg$currPos = s0;
1883
+ s0 = peg$FAILED;
1884
+ }
1885
+ }
1886
+
1887
+ return s0;
1888
+ }
1889
+
1890
+ function peg$parsepercentageScope() {
1891
+ var s0, s1, s2, s3, s4;
1892
+
1893
+ s0 = peg$currPos;
1894
+ s1 = peg$parse__();
1895
+ if (s1 !== peg$FAILED) {
1896
+ s2 = input.substr(peg$currPos, 4);
1897
+ if (s2.toLowerCase() === peg$c14) {
1898
+ peg$currPos += 4;
1899
+ } else {
1900
+ s2 = peg$FAILED;
1901
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
1902
+ }
1903
+ if (s2 !== peg$FAILED) {
1904
+ s3 = peg$currPos;
1905
+ peg$silentFails++;
1906
+ s4 = peg$parseidentifierChar();
1907
+ peg$silentFails--;
1908
+ if (s4 === peg$FAILED) {
1909
+ s3 = undefined;
1910
+ } else {
1911
+ peg$currPos = s3;
1912
+ s3 = peg$FAILED;
1913
+ }
1914
+ if (s3 !== peg$FAILED) {
1915
+ peg$savedPos = s0;
1916
+ s0 = peg$f24();
1917
+ } else {
1918
+ peg$currPos = s0;
1919
+ s0 = peg$FAILED;
1920
+ }
1921
+ } else {
1922
+ peg$currPos = s0;
1923
+ s0 = peg$FAILED;
1924
+ }
1925
+ } else {
1926
+ peg$currPos = s0;
1927
+ s0 = peg$FAILED;
1928
+ }
1929
+ if (s0 === peg$FAILED) {
1930
+ s0 = peg$currPos;
1931
+ s1 = peg$parse__();
1932
+ if (s1 !== peg$FAILED) {
1933
+ s2 = input.substr(peg$currPos, 4);
1934
+ if (s2.toLowerCase() === peg$c15) {
1935
+ peg$currPos += 4;
1936
+ } else {
1937
+ s2 = peg$FAILED;
1938
+ if (peg$silentFails === 0) { peg$fail(peg$e16); }
1939
+ }
1940
+ if (s2 !== peg$FAILED) {
1941
+ s3 = peg$currPos;
1942
+ peg$silentFails++;
1943
+ s4 = peg$parseidentifierChar();
1944
+ peg$silentFails--;
1945
+ if (s4 === peg$FAILED) {
1946
+ s3 = undefined;
1947
+ } else {
1948
+ peg$currPos = s3;
1949
+ s3 = peg$FAILED;
1950
+ }
1951
+ if (s3 !== peg$FAILED) {
1952
+ peg$savedPos = s0;
1953
+ s0 = peg$f25();
1954
+ } else {
1955
+ peg$currPos = s0;
1956
+ s0 = peg$FAILED;
1957
+ }
1958
+ } else {
1959
+ peg$currPos = s0;
1960
+ s0 = peg$FAILED;
1961
+ }
1962
+ } else {
1963
+ peg$currPos = s0;
1964
+ s0 = peg$FAILED;
1965
+ }
1966
+ if (s0 === peg$FAILED) {
1967
+ s0 = peg$currPos;
1968
+ s1 = peg$parse__();
1969
+ if (s1 !== peg$FAILED) {
1970
+ s2 = peg$parsedimensionList();
1971
+ if (s2 !== peg$FAILED) {
1972
+ peg$savedPos = s0;
1973
+ s0 = peg$f26(s2);
1974
+ } else {
1975
+ peg$currPos = s0;
1976
+ s0 = peg$FAILED;
1977
+ }
1978
+ } else {
1979
+ peg$currPos = s0;
1980
+ s0 = peg$FAILED;
1981
+ }
1982
+ }
1983
+ }
1984
+
1985
+ return s0;
1986
+ }
1987
+
1988
+ function peg$parsefieldRef() {
1989
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
1990
+
1991
+ s0 = peg$currPos;
1992
+ s1 = peg$parseidentifier();
1993
+ if (s1 !== peg$FAILED) {
1994
+ if (input.charCodeAt(peg$currPos) === 46) {
1995
+ s2 = peg$c8;
1996
+ peg$currPos++;
1997
+ } else {
1998
+ s2 = peg$FAILED;
1999
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
2000
+ }
2001
+ if (s2 !== peg$FAILED) {
2002
+ if (input.charCodeAt(peg$currPos) === 40) {
2003
+ s3 = peg$c11;
2004
+ peg$currPos++;
2005
+ } else {
2006
+ s3 = peg$FAILED;
2007
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
2008
+ }
2009
+ if (s3 !== peg$FAILED) {
2010
+ s4 = peg$parse_();
2011
+ s5 = peg$parseaggregationList();
2012
+ if (s5 !== peg$FAILED) {
2013
+ s6 = peg$parse_();
2014
+ if (input.charCodeAt(peg$currPos) === 41) {
2015
+ s7 = peg$c12;
2016
+ peg$currPos++;
2017
+ } else {
2018
+ s7 = peg$FAILED;
2019
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
2020
+ }
2021
+ if (s7 !== peg$FAILED) {
2022
+ s8 = peg$parseannotations();
2023
+ s9 = peg$parseinlineLabel();
2024
+ if (s9 === peg$FAILED) {
2025
+ s9 = null;
2026
+ }
2027
+ peg$savedPos = s0;
2028
+ s0 = peg$f27(s1, s5, s8, s9);
2029
+ } else {
2030
+ peg$currPos = s0;
2031
+ s0 = peg$FAILED;
2032
+ }
2033
+ } else {
2034
+ peg$currPos = s0;
2035
+ s0 = peg$FAILED;
2036
+ }
2037
+ } else {
2038
+ peg$currPos = s0;
2039
+ s0 = peg$FAILED;
2040
+ }
2041
+ } else {
2042
+ peg$currPos = s0;
2043
+ s0 = peg$FAILED;
2044
+ }
2045
+ } else {
2046
+ peg$currPos = s0;
2047
+ s0 = peg$FAILED;
2048
+ }
2049
+ if (s0 === peg$FAILED) {
2050
+ s0 = peg$currPos;
2051
+ s1 = peg$parseidentifier();
2052
+ if (s1 !== peg$FAILED) {
2053
+ if (input.charCodeAt(peg$currPos) === 46) {
2054
+ s2 = peg$c8;
2055
+ peg$currPos++;
2056
+ } else {
2057
+ s2 = peg$FAILED;
2058
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
2059
+ }
2060
+ if (s2 !== peg$FAILED) {
2061
+ s3 = peg$parseaggregationSpec();
2062
+ if (s3 !== peg$FAILED) {
2063
+ s4 = peg$parseannotations();
2064
+ s5 = peg$parseinlineLabel();
2065
+ if (s5 === peg$FAILED) {
2066
+ s5 = null;
2067
+ }
2068
+ peg$savedPos = s0;
2069
+ s0 = peg$f28(s1, s3, s4, s5);
2070
+ } else {
2071
+ peg$currPos = s0;
2072
+ s0 = peg$FAILED;
2073
+ }
2074
+ } else {
2075
+ peg$currPos = s0;
2076
+ s0 = peg$FAILED;
2077
+ }
2078
+ } else {
2079
+ peg$currPos = s0;
2080
+ s0 = peg$FAILED;
2081
+ }
2082
+ if (s0 === peg$FAILED) {
2083
+ s0 = peg$currPos;
2084
+ s1 = peg$parseidentifier();
2085
+ if (s1 !== peg$FAILED) {
2086
+ s2 = peg$parsepreAnnotations();
2087
+ s3 = peg$parseorderDirection();
2088
+ if (s3 === peg$FAILED) {
2089
+ s3 = null;
2090
+ }
2091
+ s4 = peg$parsepostAnnotations();
2092
+ s5 = peg$parseinlineLabel();
2093
+ if (s5 === peg$FAILED) {
2094
+ s5 = null;
2095
+ }
2096
+ peg$savedPos = s0;
2097
+ s0 = peg$f29(s1, s2, s3, s4, s5);
2098
+ } else {
2099
+ peg$currPos = s0;
2100
+ s0 = peg$FAILED;
2101
+ }
2102
+ }
2103
+ }
2104
+
2105
+ return s0;
2106
+ }
2107
+
2108
+ function peg$parseorderDirection() {
2109
+ var s0, s1, s2, s3, s4;
2110
+
2111
+ s0 = peg$currPos;
2112
+ s1 = peg$parse__();
2113
+ if (s1 !== peg$FAILED) {
2114
+ s2 = input.substr(peg$currPos, 3);
2115
+ if (s2.toLowerCase() === peg$c16) {
2116
+ peg$currPos += 3;
2117
+ } else {
2118
+ s2 = peg$FAILED;
2119
+ if (peg$silentFails === 0) { peg$fail(peg$e17); }
2120
+ }
2121
+ if (s2 === peg$FAILED) {
2122
+ s2 = input.substr(peg$currPos, 4);
2123
+ if (s2.toLowerCase() === peg$c17) {
2124
+ peg$currPos += 4;
2125
+ } else {
2126
+ s2 = peg$FAILED;
2127
+ if (peg$silentFails === 0) { peg$fail(peg$e18); }
2128
+ }
2129
+ }
2130
+ if (s2 !== peg$FAILED) {
2131
+ s3 = peg$currPos;
2132
+ peg$silentFails++;
2133
+ s4 = peg$parseidentifierChar();
2134
+ peg$silentFails--;
2135
+ if (s4 === peg$FAILED) {
2136
+ s3 = undefined;
2137
+ } else {
2138
+ peg$currPos = s3;
2139
+ s3 = peg$FAILED;
2140
+ }
2141
+ if (s3 !== peg$FAILED) {
2142
+ peg$savedPos = s0;
2143
+ s0 = peg$f30(s2);
2144
+ } else {
2145
+ peg$currPos = s0;
2146
+ s0 = peg$FAILED;
2147
+ }
2148
+ } else {
2149
+ peg$currPos = s0;
2150
+ s0 = peg$FAILED;
2151
+ }
2152
+ } else {
2153
+ peg$currPos = s0;
2154
+ s0 = peg$FAILED;
2155
+ }
2156
+
2157
+ return s0;
2158
+ }
2159
+
2160
+ function peg$parseaggregationList() {
2161
+ var s0, s1, s2, s3, s4, s5;
2162
+
2163
+ s0 = peg$currPos;
2164
+ s1 = peg$parseaggregationSpec();
2165
+ if (s1 !== peg$FAILED) {
2166
+ s2 = [];
2167
+ s3 = peg$currPos;
2168
+ s4 = peg$parseaggListSep();
2169
+ if (s4 !== peg$FAILED) {
2170
+ s5 = peg$parseaggregationSpec();
2171
+ if (s5 !== peg$FAILED) {
2172
+ s4 = [s4, s5];
2173
+ s3 = s4;
2174
+ } else {
2175
+ peg$currPos = s3;
2176
+ s3 = peg$FAILED;
2177
+ }
2178
+ } else {
2179
+ peg$currPos = s3;
2180
+ s3 = peg$FAILED;
2181
+ }
2182
+ while (s3 !== peg$FAILED) {
2183
+ s2.push(s3);
2184
+ s3 = peg$currPos;
2185
+ s4 = peg$parseaggListSep();
2186
+ if (s4 !== peg$FAILED) {
2187
+ s5 = peg$parseaggregationSpec();
2188
+ if (s5 !== peg$FAILED) {
2189
+ s4 = [s4, s5];
2190
+ s3 = s4;
2191
+ } else {
2192
+ peg$currPos = s3;
2193
+ s3 = peg$FAILED;
2194
+ }
2195
+ } else {
2196
+ peg$currPos = s3;
2197
+ s3 = peg$FAILED;
2198
+ }
2199
+ }
2200
+ peg$savedPos = s0;
2201
+ s0 = peg$f31(s1, s2);
2202
+ } else {
2203
+ peg$currPos = s0;
2204
+ s0 = peg$FAILED;
2205
+ }
2206
+
2207
+ return s0;
2208
+ }
2209
+
2210
+ function peg$parseaggListSep() {
2211
+ var s0, s1, s2, s3;
2212
+
2213
+ s0 = peg$currPos;
2214
+ s1 = peg$parse_();
2215
+ if (input.charCodeAt(peg$currPos) === 124) {
2216
+ s2 = peg$c9;
2217
+ peg$currPos++;
2218
+ } else {
2219
+ s2 = peg$FAILED;
2220
+ if (peg$silentFails === 0) { peg$fail(peg$e10); }
2221
+ }
2222
+ if (s2 !== peg$FAILED) {
2223
+ s3 = peg$parse_();
2224
+ peg$savedPos = s0;
2225
+ s0 = peg$f32();
2226
+ } else {
2227
+ peg$currPos = s0;
2228
+ s0 = peg$FAILED;
2229
+ }
2230
+ if (s0 === peg$FAILED) {
2231
+ s0 = peg$currPos;
2232
+ s1 = peg$parse__();
2233
+ if (s1 !== peg$FAILED) {
2234
+ s2 = peg$parseTHEN();
2235
+ if (s2 !== peg$FAILED) {
2236
+ s3 = peg$parse__();
2237
+ if (s3 !== peg$FAILED) {
2238
+ peg$savedPos = s0;
2239
+ s0 = peg$f33();
2240
+ } else {
2241
+ peg$currPos = s0;
2242
+ s0 = peg$FAILED;
2243
+ }
2244
+ } else {
2245
+ peg$currPos = s0;
2246
+ s0 = peg$FAILED;
2247
+ }
2248
+ } else {
2249
+ peg$currPos = s0;
2250
+ s0 = peg$FAILED;
2251
+ }
2252
+ }
2253
+
2254
+ return s0;
2255
+ }
2256
+
2257
+ function peg$parseaggregationSpec() {
2258
+ var s0, s1, s2, s3;
2259
+
2260
+ s0 = peg$currPos;
2261
+ s1 = peg$parseaggregationKeyword();
2262
+ if (s1 !== peg$FAILED) {
2263
+ s2 = peg$parseformatAnnotation();
2264
+ if (s2 === peg$FAILED) {
2265
+ s2 = null;
2266
+ }
2267
+ s3 = peg$parseinlineLabel();
2268
+ if (s3 === peg$FAILED) {
2269
+ s3 = null;
2270
+ }
2271
+ peg$savedPos = s0;
2272
+ s0 = peg$f34(s1, s2, s3);
2273
+ } else {
2274
+ peg$currPos = s0;
2275
+ s0 = peg$FAILED;
2276
+ }
2277
+
2278
+ return s0;
2279
+ }
2280
+
2281
+ function peg$parseaggregationRef() {
2282
+ var s0, s1, s2, s3;
2283
+
2284
+ s0 = peg$currPos;
2285
+ s1 = peg$parseaggregationKeyword();
2286
+ if (s1 !== peg$FAILED) {
2287
+ s2 = peg$parseannotations();
2288
+ s3 = peg$parseinlineLabel();
2289
+ if (s3 === peg$FAILED) {
2290
+ s3 = null;
2291
+ }
2292
+ peg$savedPos = s0;
2293
+ s0 = peg$f35(s1, s2, s3);
2294
+ } else {
2295
+ peg$currPos = s0;
2296
+ s0 = peg$FAILED;
2297
+ }
2298
+
2299
+ return s0;
2300
+ }
2301
+
2302
+ function peg$parseaggregationKeyword() {
2303
+ var s0, s1, s2, s3;
2304
+
2305
+ s0 = peg$currPos;
2306
+ s1 = input.substr(peg$currPos, 3);
2307
+ if (s1.toLowerCase() === peg$c18) {
2308
+ peg$currPos += 3;
2309
+ } else {
2310
+ s1 = peg$FAILED;
2311
+ if (peg$silentFails === 0) { peg$fail(peg$e19); }
2312
+ }
2313
+ if (s1 !== peg$FAILED) {
2314
+ s2 = peg$currPos;
2315
+ peg$silentFails++;
2316
+ s3 = peg$parseidentifierChar();
2317
+ peg$silentFails--;
2318
+ if (s3 === peg$FAILED) {
2319
+ s2 = undefined;
2320
+ } else {
2321
+ peg$currPos = s2;
2322
+ s2 = peg$FAILED;
2323
+ }
2324
+ if (s2 !== peg$FAILED) {
2325
+ peg$savedPos = s0;
2326
+ s0 = peg$f36();
2327
+ } else {
2328
+ peg$currPos = s0;
2329
+ s0 = peg$FAILED;
2330
+ }
2331
+ } else {
2332
+ peg$currPos = s0;
2333
+ s0 = peg$FAILED;
2334
+ }
2335
+ if (s0 === peg$FAILED) {
2336
+ s0 = peg$currPos;
2337
+ s1 = input.substr(peg$currPos, 4);
2338
+ if (s1.toLowerCase() === peg$c19) {
2339
+ peg$currPos += 4;
2340
+ } else {
2341
+ s1 = peg$FAILED;
2342
+ if (peg$silentFails === 0) { peg$fail(peg$e20); }
2343
+ }
2344
+ if (s1 !== peg$FAILED) {
2345
+ s2 = peg$currPos;
2346
+ peg$silentFails++;
2347
+ s3 = peg$parseidentifierChar();
2348
+ peg$silentFails--;
2349
+ if (s3 === peg$FAILED) {
2350
+ s2 = undefined;
2351
+ } else {
2352
+ peg$currPos = s2;
2353
+ s2 = peg$FAILED;
2354
+ }
2355
+ if (s2 !== peg$FAILED) {
2356
+ peg$savedPos = s0;
2357
+ s0 = peg$f37();
2358
+ } else {
2359
+ peg$currPos = s0;
2360
+ s0 = peg$FAILED;
2361
+ }
2362
+ } else {
2363
+ peg$currPos = s0;
2364
+ s0 = peg$FAILED;
2365
+ }
2366
+ if (s0 === peg$FAILED) {
2367
+ s0 = peg$currPos;
2368
+ s1 = input.substr(peg$currPos, 3);
2369
+ if (s1.toLowerCase() === peg$c20) {
2370
+ peg$currPos += 3;
2371
+ } else {
2372
+ s1 = peg$FAILED;
2373
+ if (peg$silentFails === 0) { peg$fail(peg$e21); }
2374
+ }
2375
+ if (s1 !== peg$FAILED) {
2376
+ s2 = peg$currPos;
2377
+ peg$silentFails++;
2378
+ s3 = peg$parseidentifierChar();
2379
+ peg$silentFails--;
2380
+ if (s3 === peg$FAILED) {
2381
+ s2 = undefined;
2382
+ } else {
2383
+ peg$currPos = s2;
2384
+ s2 = peg$FAILED;
2385
+ }
2386
+ if (s2 !== peg$FAILED) {
2387
+ peg$savedPos = s0;
2388
+ s0 = peg$f38();
2389
+ } else {
2390
+ peg$currPos = s0;
2391
+ s0 = peg$FAILED;
2392
+ }
2393
+ } else {
2394
+ peg$currPos = s0;
2395
+ s0 = peg$FAILED;
2396
+ }
2397
+ if (s0 === peg$FAILED) {
2398
+ s0 = peg$currPos;
2399
+ s1 = input.substr(peg$currPos, 5);
2400
+ if (s1.toLowerCase() === peg$c21) {
2401
+ peg$currPos += 5;
2402
+ } else {
2403
+ s1 = peg$FAILED;
2404
+ if (peg$silentFails === 0) { peg$fail(peg$e22); }
2405
+ }
2406
+ if (s1 !== peg$FAILED) {
2407
+ s2 = peg$currPos;
2408
+ peg$silentFails++;
2409
+ s3 = peg$parseidentifierChar();
2410
+ peg$silentFails--;
2411
+ if (s3 === peg$FAILED) {
2412
+ s2 = undefined;
2413
+ } else {
2414
+ peg$currPos = s2;
2415
+ s2 = peg$FAILED;
2416
+ }
2417
+ if (s2 !== peg$FAILED) {
2418
+ peg$savedPos = s0;
2419
+ s0 = peg$f39();
2420
+ } else {
2421
+ peg$currPos = s0;
2422
+ s0 = peg$FAILED;
2423
+ }
2424
+ } else {
2425
+ peg$currPos = s0;
2426
+ s0 = peg$FAILED;
2427
+ }
2428
+ if (s0 === peg$FAILED) {
2429
+ s0 = peg$currPos;
2430
+ s1 = input.substr(peg$currPos, 3);
2431
+ if (s1.toLowerCase() === peg$c22) {
2432
+ peg$currPos += 3;
2433
+ } else {
2434
+ s1 = peg$FAILED;
2435
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
2436
+ }
2437
+ if (s1 !== peg$FAILED) {
2438
+ s2 = peg$currPos;
2439
+ peg$silentFails++;
2440
+ s3 = peg$parseidentifierChar();
2441
+ peg$silentFails--;
2442
+ if (s3 === peg$FAILED) {
2443
+ s2 = undefined;
2444
+ } else {
2445
+ peg$currPos = s2;
2446
+ s2 = peg$FAILED;
2447
+ }
2448
+ if (s2 !== peg$FAILED) {
2449
+ peg$savedPos = s0;
2450
+ s0 = peg$f40();
2451
+ } else {
2452
+ peg$currPos = s0;
2453
+ s0 = peg$FAILED;
2454
+ }
2455
+ } else {
2456
+ peg$currPos = s0;
2457
+ s0 = peg$FAILED;
2458
+ }
2459
+ if (s0 === peg$FAILED) {
2460
+ s0 = peg$currPos;
2461
+ s1 = input.substr(peg$currPos, 3);
2462
+ if (s1.toLowerCase() === peg$c23) {
2463
+ peg$currPos += 3;
2464
+ } else {
2465
+ s1 = peg$FAILED;
2466
+ if (peg$silentFails === 0) { peg$fail(peg$e24); }
2467
+ }
2468
+ if (s1 !== peg$FAILED) {
2469
+ s2 = peg$currPos;
2470
+ peg$silentFails++;
2471
+ s3 = peg$parseidentifierChar();
2472
+ peg$silentFails--;
2473
+ if (s3 === peg$FAILED) {
2474
+ s2 = undefined;
2475
+ } else {
2476
+ peg$currPos = s2;
2477
+ s2 = peg$FAILED;
2478
+ }
2479
+ if (s2 !== peg$FAILED) {
2480
+ peg$savedPos = s0;
2481
+ s0 = peg$f41();
2482
+ } else {
2483
+ peg$currPos = s0;
2484
+ s0 = peg$FAILED;
2485
+ }
2486
+ } else {
2487
+ peg$currPos = s0;
2488
+ s0 = peg$FAILED;
2489
+ }
2490
+ if (s0 === peg$FAILED) {
2491
+ s0 = peg$currPos;
2492
+ s1 = input.substr(peg$currPos, 6);
2493
+ if (s1.toLowerCase() === peg$c24) {
2494
+ peg$currPos += 6;
2495
+ } else {
2496
+ s1 = peg$FAILED;
2497
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2498
+ }
2499
+ if (s1 !== peg$FAILED) {
2500
+ s2 = peg$currPos;
2501
+ peg$silentFails++;
2502
+ s3 = peg$parseidentifierChar();
2503
+ peg$silentFails--;
2504
+ if (s3 === peg$FAILED) {
2505
+ s2 = undefined;
2506
+ } else {
2507
+ peg$currPos = s2;
2508
+ s2 = peg$FAILED;
2509
+ }
2510
+ if (s2 !== peg$FAILED) {
2511
+ peg$savedPos = s0;
2512
+ s0 = peg$f42();
2513
+ } else {
2514
+ peg$currPos = s0;
2515
+ s0 = peg$FAILED;
2516
+ }
2517
+ } else {
2518
+ peg$currPos = s0;
2519
+ s0 = peg$FAILED;
2520
+ }
2521
+ if (s0 === peg$FAILED) {
2522
+ s0 = peg$currPos;
2523
+ s1 = input.substr(peg$currPos, 5);
2524
+ if (s1.toLowerCase() === peg$c25) {
2525
+ peg$currPos += 5;
2526
+ } else {
2527
+ s1 = peg$FAILED;
2528
+ if (peg$silentFails === 0) { peg$fail(peg$e26); }
2529
+ }
2530
+ if (s1 !== peg$FAILED) {
2531
+ s2 = peg$currPos;
2532
+ peg$silentFails++;
2533
+ s3 = peg$parseidentifierChar();
2534
+ peg$silentFails--;
2535
+ if (s3 === peg$FAILED) {
2536
+ s2 = undefined;
2537
+ } else {
2538
+ peg$currPos = s2;
2539
+ s2 = peg$FAILED;
2540
+ }
2541
+ if (s2 !== peg$FAILED) {
2542
+ peg$savedPos = s0;
2543
+ s0 = peg$f43();
2544
+ } else {
2545
+ peg$currPos = s0;
2546
+ s0 = peg$FAILED;
2547
+ }
2548
+ } else {
2549
+ peg$currPos = s0;
2550
+ s0 = peg$FAILED;
2551
+ }
2552
+ if (s0 === peg$FAILED) {
2553
+ s0 = peg$currPos;
2554
+ s1 = input.substr(peg$currPos, 3);
2555
+ if (s1.toLowerCase() === peg$c26) {
2556
+ peg$currPos += 3;
2557
+ } else {
2558
+ s1 = peg$FAILED;
2559
+ if (peg$silentFails === 0) { peg$fail(peg$e27); }
2560
+ }
2561
+ if (s1 !== peg$FAILED) {
2562
+ s2 = peg$currPos;
2563
+ peg$silentFails++;
2564
+ s3 = peg$parseidentifierChar();
2565
+ peg$silentFails--;
2566
+ if (s3 === peg$FAILED) {
2567
+ s2 = undefined;
2568
+ } else {
2569
+ peg$currPos = s2;
2570
+ s2 = peg$FAILED;
2571
+ }
2572
+ if (s2 !== peg$FAILED) {
2573
+ peg$savedPos = s0;
2574
+ s0 = peg$f44();
2575
+ } else {
2576
+ peg$currPos = s0;
2577
+ s0 = peg$FAILED;
2578
+ }
2579
+ } else {
2580
+ peg$currPos = s0;
2581
+ s0 = peg$FAILED;
2582
+ }
2583
+ if (s0 === peg$FAILED) {
2584
+ s0 = peg$currPos;
2585
+ s1 = input.substr(peg$currPos, 4);
2586
+ if (s1.toLowerCase() === peg$c27) {
2587
+ peg$currPos += 4;
2588
+ } else {
2589
+ s1 = peg$FAILED;
2590
+ if (peg$silentFails === 0) { peg$fail(peg$e28); }
2591
+ }
2592
+ if (s1 !== peg$FAILED) {
2593
+ s2 = peg$currPos;
2594
+ peg$silentFails++;
2595
+ s3 = peg$parseidentifierChar();
2596
+ peg$silentFails--;
2597
+ if (s3 === peg$FAILED) {
2598
+ s2 = undefined;
2599
+ } else {
2600
+ peg$currPos = s2;
2601
+ s2 = peg$FAILED;
2602
+ }
2603
+ if (s2 !== peg$FAILED) {
2604
+ peg$savedPos = s0;
2605
+ s0 = peg$f45();
2606
+ } else {
2607
+ peg$currPos = s0;
2608
+ s0 = peg$FAILED;
2609
+ }
2610
+ } else {
2611
+ peg$currPos = s0;
2612
+ s0 = peg$FAILED;
2613
+ }
2614
+ if (s0 === peg$FAILED) {
2615
+ s0 = peg$currPos;
2616
+ s1 = input.substr(peg$currPos, 6);
2617
+ if (s1.toLowerCase() === peg$c28) {
2618
+ peg$currPos += 6;
2619
+ } else {
2620
+ s1 = peg$FAILED;
2621
+ if (peg$silentFails === 0) { peg$fail(peg$e29); }
2622
+ }
2623
+ if (s1 !== peg$FAILED) {
2624
+ s2 = peg$currPos;
2625
+ peg$silentFails++;
2626
+ s3 = peg$parseidentifierChar();
2627
+ peg$silentFails--;
2628
+ if (s3 === peg$FAILED) {
2629
+ s2 = undefined;
2630
+ } else {
2631
+ peg$currPos = s2;
2632
+ s2 = peg$FAILED;
2633
+ }
2634
+ if (s2 !== peg$FAILED) {
2635
+ peg$savedPos = s0;
2636
+ s0 = peg$f46();
2637
+ } else {
2638
+ peg$currPos = s0;
2639
+ s0 = peg$FAILED;
2640
+ }
2641
+ } else {
2642
+ peg$currPos = s0;
2643
+ s0 = peg$FAILED;
2644
+ }
2645
+ if (s0 === peg$FAILED) {
2646
+ s0 = peg$currPos;
2647
+ s1 = input.charAt(peg$currPos);
2648
+ if (s1.toLowerCase() === peg$c29) {
2649
+ peg$currPos++;
2650
+ } else {
2651
+ s1 = peg$FAILED;
2652
+ if (peg$silentFails === 0) { peg$fail(peg$e30); }
2653
+ }
2654
+ if (s1 !== peg$FAILED) {
2655
+ s2 = peg$currPos;
2656
+ peg$silentFails++;
2657
+ s3 = peg$parseidentifierChar();
2658
+ peg$silentFails--;
2659
+ if (s3 === peg$FAILED) {
2660
+ s2 = undefined;
2661
+ } else {
2662
+ peg$currPos = s2;
2663
+ s2 = peg$FAILED;
2664
+ }
2665
+ if (s2 !== peg$FAILED) {
2666
+ peg$savedPos = s0;
2667
+ s0 = peg$f47();
2668
+ } else {
2669
+ peg$currPos = s0;
2670
+ s0 = peg$FAILED;
2671
+ }
2672
+ } else {
2673
+ peg$currPos = s0;
2674
+ s0 = peg$FAILED;
2675
+ }
2676
+ }
2677
+ }
2678
+ }
2679
+ }
2680
+ }
2681
+ }
2682
+ }
2683
+ }
2684
+ }
2685
+ }
2686
+ }
2687
+
2688
+ return s0;
2689
+ }
2690
+
2691
+ function peg$parseidentifierChar() {
2692
+ var s0;
2693
+
2694
+ s0 = input.charAt(peg$currPos);
2695
+ if (peg$r0.test(s0)) {
2696
+ peg$currPos++;
2697
+ } else {
2698
+ s0 = peg$FAILED;
2699
+ if (peg$silentFails === 0) { peg$fail(peg$e31); }
2700
+ }
2701
+
2702
+ return s0;
2703
+ }
2704
+
2705
+ function peg$parseallRef() {
2706
+ var s0, s1, s2, s3;
2707
+
2708
+ s0 = peg$currPos;
2709
+ s1 = input.substr(peg$currPos, 3);
2710
+ if (s1.toLowerCase() === peg$c30) {
2711
+ peg$currPos += 3;
2712
+ } else {
2713
+ s1 = peg$FAILED;
2714
+ if (peg$silentFails === 0) { peg$fail(peg$e32); }
2715
+ }
2716
+ if (s1 !== peg$FAILED) {
2717
+ s2 = peg$parseannotations();
2718
+ s3 = peg$parseinlineLabel();
2719
+ if (s3 === peg$FAILED) {
2720
+ s3 = null;
2721
+ }
2722
+ peg$savedPos = s0;
2723
+ s0 = peg$f48(s2, s3);
2724
+ } else {
2725
+ peg$currPos = s0;
2726
+ s0 = peg$FAILED;
2727
+ }
2728
+
2729
+ return s0;
2730
+ }
2731
+
2732
+ function peg$parseannotations() {
2733
+ var s0, s1, s2;
2734
+
2735
+ s0 = peg$currPos;
2736
+ s1 = [];
2737
+ s2 = peg$parseannotation();
2738
+ while (s2 !== peg$FAILED) {
2739
+ s1.push(s2);
2740
+ s2 = peg$parseannotation();
2741
+ }
2742
+ peg$savedPos = s0;
2743
+ s1 = peg$f49(s1);
2744
+ s0 = s1;
2745
+
2746
+ return s0;
2747
+ }
2748
+
2749
+ function peg$parsepreAnnotations() {
2750
+ var s0, s1, s2;
2751
+
2752
+ s0 = peg$currPos;
2753
+ s1 = [];
2754
+ s2 = peg$parsepreAnnotation();
2755
+ while (s2 !== peg$FAILED) {
2756
+ s1.push(s2);
2757
+ s2 = peg$parsepreAnnotation();
2758
+ }
2759
+ peg$savedPos = s0;
2760
+ s1 = peg$f50(s1);
2761
+ s0 = s1;
2762
+
2763
+ return s0;
2764
+ }
2765
+
2766
+ function peg$parsepostAnnotations() {
2767
+ var s0, s1, s2;
2768
+
2769
+ s0 = peg$currPos;
2770
+ s1 = [];
2771
+ s2 = peg$parseorderAnnotation();
2772
+ while (s2 !== peg$FAILED) {
2773
+ s1.push(s2);
2774
+ s2 = peg$parseorderAnnotation();
2775
+ }
2776
+ peg$savedPos = s0;
2777
+ s1 = peg$f51(s1);
2778
+ s0 = s1;
2779
+
2780
+ return s0;
2781
+ }
2782
+
2783
+ function peg$parseannotation() {
2784
+ var s0;
2785
+
2786
+ s0 = peg$parseformatAnnotation();
2787
+ if (s0 === peg$FAILED) {
2788
+ s0 = peg$parselimitAnnotation();
2789
+ if (s0 === peg$FAILED) {
2790
+ s0 = peg$parseorderAnnotation();
2791
+ if (s0 === peg$FAILED) {
2792
+ s0 = peg$parsediffAnnotation();
2793
+ if (s0 === peg$FAILED) {
2794
+ s0 = peg$parseoverAnnotation();
2795
+ }
2796
+ }
2797
+ }
2798
+ }
2799
+
2800
+ return s0;
2801
+ }
2802
+
2803
+ function peg$parsepreAnnotation() {
2804
+ var s0;
2805
+
2806
+ s0 = peg$parseformatAnnotation();
2807
+ if (s0 === peg$FAILED) {
2808
+ s0 = peg$parselimitAnnotation();
2809
+ if (s0 === peg$FAILED) {
2810
+ s0 = peg$parsediffAnnotation();
2811
+ if (s0 === peg$FAILED) {
2812
+ s0 = peg$parseoverAnnotation();
2813
+ }
2814
+ }
2815
+ }
2816
+
2817
+ return s0;
2818
+ }
2819
+
2820
+ function peg$parseformatAnnotation() {
2821
+ var s0, s1, s2, s3, s4;
2822
+
2823
+ s0 = peg$currPos;
2824
+ s1 = peg$parse_();
2825
+ if (input.charCodeAt(peg$currPos) === 58) {
2826
+ s2 = peg$c2;
2827
+ peg$currPos++;
2828
+ } else {
2829
+ s2 = peg$FAILED;
2830
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
2831
+ }
2832
+ if (s2 !== peg$FAILED) {
2833
+ s3 = peg$parse_();
2834
+ s4 = peg$parseformatSpec();
2835
+ if (s4 !== peg$FAILED) {
2836
+ peg$savedPos = s0;
2837
+ s0 = peg$f52(s4);
2838
+ } else {
2839
+ peg$currPos = s0;
2840
+ s0 = peg$FAILED;
2841
+ }
2842
+ } else {
2843
+ peg$currPos = s0;
2844
+ s0 = peg$FAILED;
2845
+ }
2846
+
2847
+ return s0;
2848
+ }
2849
+
2850
+ function peg$parseformatSpec() {
2851
+ var s0, s1, s2, s3, s4, s5;
2852
+
2853
+ s0 = peg$currPos;
2854
+ s1 = input.substr(peg$currPos, 8);
2855
+ if (s1.toLowerCase() === peg$c31) {
2856
+ peg$currPos += 8;
2857
+ } else {
2858
+ s1 = peg$FAILED;
2859
+ if (peg$silentFails === 0) { peg$fail(peg$e33); }
2860
+ }
2861
+ if (s1 !== peg$FAILED) {
2862
+ peg$savedPos = s0;
2863
+ s1 = peg$f53();
2864
+ }
2865
+ s0 = s1;
2866
+ if (s0 === peg$FAILED) {
2867
+ s0 = peg$currPos;
2868
+ s1 = input.substr(peg$currPos, 7);
2869
+ if (s1.toLowerCase() === peg$c32) {
2870
+ peg$currPos += 7;
2871
+ } else {
2872
+ s1 = peg$FAILED;
2873
+ if (peg$silentFails === 0) { peg$fail(peg$e34); }
2874
+ }
2875
+ if (s1 !== peg$FAILED) {
2876
+ peg$savedPos = s0;
2877
+ s1 = peg$f54();
2878
+ }
2879
+ s0 = s1;
2880
+ if (s0 === peg$FAILED) {
2881
+ s0 = peg$currPos;
2882
+ s1 = input.substr(peg$currPos, 7);
2883
+ if (s1.toLowerCase() === peg$c33) {
2884
+ peg$currPos += 7;
2885
+ } else {
2886
+ s1 = peg$FAILED;
2887
+ if (peg$silentFails === 0) { peg$fail(peg$e35); }
2888
+ }
2889
+ if (s1 !== peg$FAILED) {
2890
+ peg$savedPos = s0;
2891
+ s1 = peg$f55();
2892
+ }
2893
+ s0 = s1;
2894
+ if (s0 === peg$FAILED) {
2895
+ s0 = peg$currPos;
2896
+ s1 = input.substr(peg$currPos, 7);
2897
+ if (s1.toLowerCase() === peg$c34) {
2898
+ peg$currPos += 7;
2899
+ } else {
2900
+ s1 = peg$FAILED;
2901
+ if (peg$silentFails === 0) { peg$fail(peg$e36); }
2902
+ }
2903
+ if (s1 !== peg$FAILED) {
2904
+ if (input.charCodeAt(peg$currPos) === 46) {
2905
+ s2 = peg$c8;
2906
+ peg$currPos++;
2907
+ } else {
2908
+ s2 = peg$FAILED;
2909
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
2910
+ }
2911
+ if (s2 !== peg$FAILED) {
2912
+ s3 = peg$currPos;
2913
+ s4 = [];
2914
+ s5 = input.charAt(peg$currPos);
2915
+ if (peg$r1.test(s5)) {
2916
+ peg$currPos++;
2917
+ } else {
2918
+ s5 = peg$FAILED;
2919
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2920
+ }
2921
+ if (s5 !== peg$FAILED) {
2922
+ while (s5 !== peg$FAILED) {
2923
+ s4.push(s5);
2924
+ s5 = input.charAt(peg$currPos);
2925
+ if (peg$r1.test(s5)) {
2926
+ peg$currPos++;
2927
+ } else {
2928
+ s5 = peg$FAILED;
2929
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2930
+ }
2931
+ }
2932
+ } else {
2933
+ s4 = peg$FAILED;
2934
+ }
2935
+ if (s4 !== peg$FAILED) {
2936
+ s3 = input.substring(s3, peg$currPos);
2937
+ } else {
2938
+ s3 = s4;
2939
+ }
2940
+ if (s3 !== peg$FAILED) {
2941
+ peg$savedPos = s0;
2942
+ s0 = peg$f56(s3);
2943
+ } else {
2944
+ peg$currPos = s0;
2945
+ s0 = peg$FAILED;
2946
+ }
2947
+ } else {
2948
+ peg$currPos = s0;
2949
+ s0 = peg$FAILED;
2950
+ }
2951
+ } else {
2952
+ peg$currPos = s0;
2953
+ s0 = peg$FAILED;
2954
+ }
2955
+ if (s0 === peg$FAILED) {
2956
+ s0 = peg$currPos;
2957
+ s1 = input.substr(peg$currPos, 5);
2958
+ if (s1.toLowerCase() === peg$c35) {
2959
+ peg$currPos += 5;
2960
+ } else {
2961
+ s1 = peg$FAILED;
2962
+ if (peg$silentFails === 0) { peg$fail(peg$e38); }
2963
+ }
2964
+ if (s1 !== peg$FAILED) {
2965
+ if (input.charCodeAt(peg$currPos) === 46) {
2966
+ s2 = peg$c8;
2967
+ peg$currPos++;
2968
+ } else {
2969
+ s2 = peg$FAILED;
2970
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
2971
+ }
2972
+ if (s2 !== peg$FAILED) {
2973
+ s3 = peg$currPos;
2974
+ s4 = [];
2975
+ s5 = input.charAt(peg$currPos);
2976
+ if (peg$r1.test(s5)) {
2977
+ peg$currPos++;
2978
+ } else {
2979
+ s5 = peg$FAILED;
2980
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2981
+ }
2982
+ if (s5 !== peg$FAILED) {
2983
+ while (s5 !== peg$FAILED) {
2984
+ s4.push(s5);
2985
+ s5 = input.charAt(peg$currPos);
2986
+ if (peg$r1.test(s5)) {
2987
+ peg$currPos++;
2988
+ } else {
2989
+ s5 = peg$FAILED;
2990
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2991
+ }
2992
+ }
2993
+ } else {
2994
+ s4 = peg$FAILED;
2995
+ }
2996
+ if (s4 !== peg$FAILED) {
2997
+ s3 = input.substring(s3, peg$currPos);
2998
+ } else {
2999
+ s3 = s4;
3000
+ }
3001
+ if (s3 !== peg$FAILED) {
3002
+ peg$savedPos = s0;
3003
+ s0 = peg$f57(s3);
3004
+ } else {
3005
+ peg$currPos = s0;
3006
+ s0 = peg$FAILED;
3007
+ }
3008
+ } else {
3009
+ peg$currPos = s0;
3010
+ s0 = peg$FAILED;
3011
+ }
3012
+ } else {
3013
+ peg$currPos = s0;
3014
+ s0 = peg$FAILED;
3015
+ }
3016
+ if (s0 === peg$FAILED) {
3017
+ s0 = peg$currPos;
3018
+ s1 = peg$parsestringLiteral();
3019
+ if (s1 !== peg$FAILED) {
3020
+ peg$savedPos = s0;
3021
+ s1 = peg$f58(s1);
3022
+ }
3023
+ s0 = s1;
3024
+ }
3025
+ }
3026
+ }
3027
+ }
3028
+ }
3029
+
3030
+ return s0;
3031
+ }
3032
+
3033
+ function peg$parselimitAnnotation() {
3034
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
3035
+
3036
+ s0 = peg$currPos;
3037
+ s1 = peg$parse_();
3038
+ if (input.charCodeAt(peg$currPos) === 91) {
3039
+ s2 = peg$c36;
3040
+ peg$currPos++;
3041
+ } else {
3042
+ s2 = peg$FAILED;
3043
+ if (peg$silentFails === 0) { peg$fail(peg$e39); }
3044
+ }
3045
+ if (s2 !== peg$FAILED) {
3046
+ s3 = peg$parse_();
3047
+ if (input.charCodeAt(peg$currPos) === 45) {
3048
+ s4 = peg$c37;
3049
+ peg$currPos++;
3050
+ } else {
3051
+ s4 = peg$FAILED;
3052
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
3053
+ }
3054
+ if (s4 === peg$FAILED) {
3055
+ s4 = null;
3056
+ }
3057
+ s5 = peg$parse_();
3058
+ s6 = peg$currPos;
3059
+ s7 = [];
3060
+ s8 = input.charAt(peg$currPos);
3061
+ if (peg$r1.test(s8)) {
3062
+ peg$currPos++;
3063
+ } else {
3064
+ s8 = peg$FAILED;
3065
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
3066
+ }
3067
+ if (s8 !== peg$FAILED) {
3068
+ while (s8 !== peg$FAILED) {
3069
+ s7.push(s8);
3070
+ s8 = input.charAt(peg$currPos);
3071
+ if (peg$r1.test(s8)) {
3072
+ peg$currPos++;
3073
+ } else {
3074
+ s8 = peg$FAILED;
3075
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
3076
+ }
3077
+ }
3078
+ } else {
3079
+ s7 = peg$FAILED;
3080
+ }
3081
+ if (s7 !== peg$FAILED) {
3082
+ s6 = input.substring(s6, peg$currPos);
3083
+ } else {
3084
+ s6 = s7;
3085
+ }
3086
+ if (s6 !== peg$FAILED) {
3087
+ s7 = peg$parse_();
3088
+ s8 = peg$parselimitOrderBy();
3089
+ if (s8 === peg$FAILED) {
3090
+ s8 = null;
3091
+ }
3092
+ s9 = peg$parse_();
3093
+ if (input.charCodeAt(peg$currPos) === 93) {
3094
+ s10 = peg$c38;
3095
+ peg$currPos++;
3096
+ } else {
3097
+ s10 = peg$FAILED;
3098
+ if (peg$silentFails === 0) { peg$fail(peg$e41); }
3099
+ }
3100
+ if (s10 !== peg$FAILED) {
3101
+ peg$savedPos = s0;
3102
+ s0 = peg$f59(s4, s6, s8);
3103
+ } else {
3104
+ peg$currPos = s0;
3105
+ s0 = peg$FAILED;
3106
+ }
3107
+ } else {
3108
+ peg$currPos = s0;
3109
+ s0 = peg$FAILED;
3110
+ }
3111
+ } else {
3112
+ peg$currPos = s0;
3113
+ s0 = peg$FAILED;
3114
+ }
3115
+
3116
+ return s0;
3117
+ }
3118
+
3119
+ function peg$parselimitOrderBy() {
3120
+ var s0, s1, s2, s3, s4, s5, s6;
3121
+
3122
+ s0 = peg$currPos;
3123
+ if (input.charCodeAt(peg$currPos) === 64) {
3124
+ s1 = peg$c39;
3125
+ peg$currPos++;
3126
+ } else {
3127
+ s1 = peg$FAILED;
3128
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3129
+ }
3130
+ if (s1 !== peg$FAILED) {
3131
+ if (input.charCodeAt(peg$currPos) === 40) {
3132
+ s2 = peg$c11;
3133
+ peg$currPos++;
3134
+ } else {
3135
+ s2 = peg$FAILED;
3136
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
3137
+ }
3138
+ if (s2 !== peg$FAILED) {
3139
+ s3 = peg$parse_();
3140
+ s4 = peg$parseorderByExpressionInParens();
3141
+ if (s4 !== peg$FAILED) {
3142
+ s5 = peg$parse_();
3143
+ if (input.charCodeAt(peg$currPos) === 41) {
3144
+ s6 = peg$c12;
3145
+ peg$currPos++;
3146
+ } else {
3147
+ s6 = peg$FAILED;
3148
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
3149
+ }
3150
+ if (s6 !== peg$FAILED) {
3151
+ peg$savedPos = s0;
3152
+ s0 = peg$f60(s4);
3153
+ } else {
3154
+ peg$currPos = s0;
3155
+ s0 = peg$FAILED;
3156
+ }
3157
+ } else {
3158
+ peg$currPos = s0;
3159
+ s0 = peg$FAILED;
3160
+ }
3161
+ } else {
3162
+ peg$currPos = s0;
3163
+ s0 = peg$FAILED;
3164
+ }
3165
+ } else {
3166
+ peg$currPos = s0;
3167
+ s0 = peg$FAILED;
3168
+ }
3169
+ if (s0 === peg$FAILED) {
3170
+ s0 = peg$currPos;
3171
+ if (input.charCodeAt(peg$currPos) === 64) {
3172
+ s1 = peg$c39;
3173
+ peg$currPos++;
3174
+ } else {
3175
+ s1 = peg$FAILED;
3176
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3177
+ }
3178
+ if (s1 !== peg$FAILED) {
3179
+ s2 = peg$parseaggregateExpressionWithAcross();
3180
+ if (s2 !== peg$FAILED) {
3181
+ peg$savedPos = s0;
3182
+ s0 = peg$f61(s2);
3183
+ } else {
3184
+ peg$currPos = s0;
3185
+ s0 = peg$FAILED;
3186
+ }
3187
+ } else {
3188
+ peg$currPos = s0;
3189
+ s0 = peg$FAILED;
3190
+ }
3191
+ if (s0 === peg$FAILED) {
3192
+ s0 = peg$currPos;
3193
+ if (input.charCodeAt(peg$currPos) === 64) {
3194
+ s1 = peg$c39;
3195
+ peg$currPos++;
3196
+ } else {
3197
+ s1 = peg$FAILED;
3198
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3199
+ }
3200
+ if (s1 !== peg$FAILED) {
3201
+ s2 = peg$parseaggregationKeyword();
3202
+ if (s2 !== peg$FAILED) {
3203
+ peg$savedPos = s0;
3204
+ s0 = peg$f62(s2);
3205
+ } else {
3206
+ peg$currPos = s0;
3207
+ s0 = peg$FAILED;
3208
+ }
3209
+ } else {
3210
+ peg$currPos = s0;
3211
+ s0 = peg$FAILED;
3212
+ }
3213
+ if (s0 === peg$FAILED) {
3214
+ s0 = peg$currPos;
3215
+ if (input.charCodeAt(peg$currPos) === 64) {
3216
+ s1 = peg$c39;
3217
+ peg$currPos++;
3218
+ } else {
3219
+ s1 = peg$FAILED;
3220
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3221
+ }
3222
+ if (s1 !== peg$FAILED) {
3223
+ s2 = peg$parseidentifier();
3224
+ if (s2 !== peg$FAILED) {
3225
+ if (input.charCodeAt(peg$currPos) === 46) {
3226
+ s3 = peg$c8;
3227
+ peg$currPos++;
3228
+ } else {
3229
+ s3 = peg$FAILED;
3230
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
3231
+ }
3232
+ if (s3 !== peg$FAILED) {
3233
+ s4 = peg$parseaggregationKeyword();
3234
+ if (s4 !== peg$FAILED) {
3235
+ peg$savedPos = s0;
3236
+ s0 = peg$f63(s2, s4);
3237
+ } else {
3238
+ peg$currPos = s0;
3239
+ s0 = peg$FAILED;
3240
+ }
3241
+ } else {
3242
+ peg$currPos = s0;
3243
+ s0 = peg$FAILED;
3244
+ }
3245
+ } else {
3246
+ peg$currPos = s0;
3247
+ s0 = peg$FAILED;
3248
+ }
3249
+ } else {
3250
+ peg$currPos = s0;
3251
+ s0 = peg$FAILED;
3252
+ }
3253
+ if (s0 === peg$FAILED) {
3254
+ s0 = peg$currPos;
3255
+ if (input.charCodeAt(peg$currPos) === 64) {
3256
+ s1 = peg$c39;
3257
+ peg$currPos++;
3258
+ } else {
3259
+ s1 = peg$FAILED;
3260
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3261
+ }
3262
+ if (s1 !== peg$FAILED) {
3263
+ s2 = peg$parseidentifier();
3264
+ if (s2 !== peg$FAILED) {
3265
+ peg$savedPos = s0;
3266
+ s0 = peg$f64(s2);
3267
+ } else {
3268
+ peg$currPos = s0;
3269
+ s0 = peg$FAILED;
3270
+ }
3271
+ } else {
3272
+ peg$currPos = s0;
3273
+ s0 = peg$FAILED;
3274
+ }
3275
+ }
3276
+ }
3277
+ }
3278
+ }
3279
+
3280
+ return s0;
3281
+ }
3282
+
3283
+ function peg$parseorderByExpressionInParens() {
3284
+ var s0, s1, s2, s3, s4, s5;
3285
+
3286
+ s0 = peg$currPos;
3287
+ s1 = peg$parseaggregateExpression();
3288
+ if (s1 !== peg$FAILED) {
3289
+ s2 = peg$parse_();
3290
+ if (input.charCodeAt(peg$currPos) === 47) {
3291
+ s3 = peg$c40;
3292
+ peg$currPos++;
3293
+ } else {
3294
+ s3 = peg$FAILED;
3295
+ if (peg$silentFails === 0) { peg$fail(peg$e43); }
3296
+ }
3297
+ if (s3 !== peg$FAILED) {
3298
+ s4 = peg$parse_();
3299
+ s5 = peg$parseaggregateExpressionWithAcross();
3300
+ if (s5 !== peg$FAILED) {
3301
+ peg$savedPos = s0;
3302
+ s0 = peg$f65(s1, s5);
3303
+ } else {
3304
+ peg$currPos = s0;
3305
+ s0 = peg$FAILED;
3306
+ }
3307
+ } else {
3308
+ peg$currPos = s0;
3309
+ s0 = peg$FAILED;
3310
+ }
3311
+ } else {
3312
+ peg$currPos = s0;
3313
+ s0 = peg$FAILED;
3314
+ }
3315
+ if (s0 === peg$FAILED) {
3316
+ s0 = peg$currPos;
3317
+ s1 = peg$parseaggregateExpressionWithAcross();
3318
+ if (s1 !== peg$FAILED) {
3319
+ peg$savedPos = s0;
3320
+ s1 = peg$f66(s1);
3321
+ }
3322
+ s0 = s1;
3323
+ }
3324
+
3325
+ return s0;
3326
+ }
3327
+
3328
+ function peg$parseaggregateExpressionWithAcross() {
3329
+ var s0, s1, s2, s3, s4;
3330
+
3331
+ s0 = peg$currPos;
3332
+ s1 = peg$parseidentifier();
3333
+ if (s1 !== peg$FAILED) {
3334
+ if (input.charCodeAt(peg$currPos) === 46) {
3335
+ s2 = peg$c8;
3336
+ peg$currPos++;
3337
+ } else {
3338
+ s2 = peg$FAILED;
3339
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
3340
+ }
3341
+ if (s2 !== peg$FAILED) {
3342
+ s3 = peg$parseaggregationKeyword();
3343
+ if (s3 !== peg$FAILED) {
3344
+ s4 = peg$parseungroupedSpec();
3345
+ if (s4 === peg$FAILED) {
3346
+ s4 = null;
3347
+ }
3348
+ peg$savedPos = s0;
3349
+ s0 = peg$f67(s1, s3, s4);
3350
+ } else {
3351
+ peg$currPos = s0;
3352
+ s0 = peg$FAILED;
3353
+ }
3354
+ } else {
3355
+ peg$currPos = s0;
3356
+ s0 = peg$FAILED;
3357
+ }
3358
+ } else {
3359
+ peg$currPos = s0;
3360
+ s0 = peg$FAILED;
3361
+ }
3362
+
3363
+ return s0;
3364
+ }
3365
+
3366
+ function peg$parseaggregateExpression() {
3367
+ var s0, s1, s2, s3;
3368
+
3369
+ s0 = peg$currPos;
3370
+ s1 = peg$parseidentifier();
3371
+ if (s1 !== peg$FAILED) {
3372
+ if (input.charCodeAt(peg$currPos) === 46) {
3373
+ s2 = peg$c8;
3374
+ peg$currPos++;
3375
+ } else {
3376
+ s2 = peg$FAILED;
3377
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
3378
+ }
3379
+ if (s2 !== peg$FAILED) {
3380
+ s3 = peg$parseaggregationKeyword();
3381
+ if (s3 !== peg$FAILED) {
3382
+ peg$savedPos = s0;
3383
+ s0 = peg$f68(s1, s3);
3384
+ } else {
3385
+ peg$currPos = s0;
3386
+ s0 = peg$FAILED;
3387
+ }
3388
+ } else {
3389
+ peg$currPos = s0;
3390
+ s0 = peg$FAILED;
3391
+ }
3392
+ } else {
3393
+ peg$currPos = s0;
3394
+ s0 = peg$FAILED;
3395
+ }
3396
+
3397
+ return s0;
3398
+ }
3399
+
3400
+ function peg$parseungroupedSpec() {
3401
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8;
3402
+
3403
+ s0 = peg$currPos;
3404
+ s1 = peg$parse__();
3405
+ if (s1 !== peg$FAILED) {
3406
+ s2 = input.substr(peg$currPos, 6);
3407
+ if (s2.toLowerCase() === peg$c13) {
3408
+ peg$currPos += 6;
3409
+ } else {
3410
+ s2 = peg$FAILED;
3411
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
3412
+ }
3413
+ if (s2 !== peg$FAILED) {
3414
+ s3 = peg$parse__();
3415
+ if (s3 !== peg$FAILED) {
3416
+ if (input.charCodeAt(peg$currPos) === 40) {
3417
+ s4 = peg$c11;
3418
+ peg$currPos++;
3419
+ } else {
3420
+ s4 = peg$FAILED;
3421
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
3422
+ }
3423
+ if (s4 !== peg$FAILED) {
3424
+ s5 = peg$parse_();
3425
+ s6 = peg$parsedimensionList();
3426
+ if (s6 !== peg$FAILED) {
3427
+ s7 = peg$parse_();
3428
+ if (input.charCodeAt(peg$currPos) === 41) {
3429
+ s8 = peg$c12;
3430
+ peg$currPos++;
3431
+ } else {
3432
+ s8 = peg$FAILED;
3433
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
3434
+ }
3435
+ if (s8 !== peg$FAILED) {
3436
+ peg$savedPos = s0;
3437
+ s0 = peg$f69(s6);
3438
+ } else {
3439
+ peg$currPos = s0;
3440
+ s0 = peg$FAILED;
3441
+ }
3442
+ } else {
3443
+ peg$currPos = s0;
3444
+ s0 = peg$FAILED;
3445
+ }
3446
+ } else {
3447
+ peg$currPos = s0;
3448
+ s0 = peg$FAILED;
3449
+ }
3450
+ } else {
3451
+ peg$currPos = s0;
3452
+ s0 = peg$FAILED;
3453
+ }
3454
+ } else {
3455
+ peg$currPos = s0;
3456
+ s0 = peg$FAILED;
3457
+ }
3458
+ } else {
3459
+ peg$currPos = s0;
3460
+ s0 = peg$FAILED;
3461
+ }
3462
+ if (s0 === peg$FAILED) {
3463
+ s0 = peg$currPos;
3464
+ s1 = peg$parse__();
3465
+ if (s1 !== peg$FAILED) {
3466
+ s2 = input.substr(peg$currPos, 6);
3467
+ if (s2.toLowerCase() === peg$c13) {
3468
+ peg$currPos += 6;
3469
+ } else {
3470
+ s2 = peg$FAILED;
3471
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
3472
+ }
3473
+ if (s2 !== peg$FAILED) {
3474
+ s3 = peg$parse__();
3475
+ if (s3 !== peg$FAILED) {
3476
+ s4 = peg$parsedimensionList();
3477
+ if (s4 !== peg$FAILED) {
3478
+ peg$savedPos = s0;
3479
+ s0 = peg$f70(s4);
3480
+ } else {
3481
+ peg$currPos = s0;
3482
+ s0 = peg$FAILED;
3483
+ }
3484
+ } else {
3485
+ peg$currPos = s0;
3486
+ s0 = peg$FAILED;
3487
+ }
3488
+ } else {
3489
+ peg$currPos = s0;
3490
+ s0 = peg$FAILED;
3491
+ }
3492
+ } else {
3493
+ peg$currPos = s0;
3494
+ s0 = peg$FAILED;
3495
+ }
3496
+ }
3497
+
3498
+ return s0;
3499
+ }
3500
+
3501
+ function peg$parsedimensionList() {
3502
+ var s0, s1, s2, s3, s4, s5;
3503
+
3504
+ s0 = peg$currPos;
3505
+ s1 = peg$parseidentifier();
3506
+ if (s1 !== peg$FAILED) {
3507
+ s2 = [];
3508
+ s3 = peg$currPos;
3509
+ s4 = peg$parse__();
3510
+ if (s4 !== peg$FAILED) {
3511
+ s5 = peg$parseidentifier();
3512
+ if (s5 !== peg$FAILED) {
3513
+ s4 = [s4, s5];
3514
+ s3 = s4;
3515
+ } else {
3516
+ peg$currPos = s3;
3517
+ s3 = peg$FAILED;
3518
+ }
3519
+ } else {
3520
+ peg$currPos = s3;
3521
+ s3 = peg$FAILED;
3522
+ }
3523
+ while (s3 !== peg$FAILED) {
3524
+ s2.push(s3);
3525
+ s3 = peg$currPos;
3526
+ s4 = peg$parse__();
3527
+ if (s4 !== peg$FAILED) {
3528
+ s5 = peg$parseidentifier();
3529
+ if (s5 !== peg$FAILED) {
3530
+ s4 = [s4, s5];
3531
+ s3 = s4;
3532
+ } else {
3533
+ peg$currPos = s3;
3534
+ s3 = peg$FAILED;
3535
+ }
3536
+ } else {
3537
+ peg$currPos = s3;
3538
+ s3 = peg$FAILED;
3539
+ }
3540
+ }
3541
+ peg$savedPos = s0;
3542
+ s0 = peg$f71(s1, s2);
3543
+ } else {
3544
+ peg$currPos = s0;
3545
+ s0 = peg$FAILED;
3546
+ }
3547
+
3548
+ return s0;
3549
+ }
3550
+
3551
+ function peg$parseorderAnnotation() {
3552
+ var s0, s1, s2, s3, s4, s5, s6, s7, s8;
3553
+
3554
+ s0 = peg$currPos;
3555
+ s1 = peg$parse_();
3556
+ if (input.charCodeAt(peg$currPos) === 64) {
3557
+ s2 = peg$c39;
3558
+ peg$currPos++;
3559
+ } else {
3560
+ s2 = peg$FAILED;
3561
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3562
+ }
3563
+ if (s2 !== peg$FAILED) {
3564
+ s3 = peg$parse_();
3565
+ if (input.charCodeAt(peg$currPos) === 40) {
3566
+ s4 = peg$c11;
3567
+ peg$currPos++;
3568
+ } else {
3569
+ s4 = peg$FAILED;
3570
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
3571
+ }
3572
+ if (s4 !== peg$FAILED) {
3573
+ s5 = peg$parse_();
3574
+ s6 = peg$parseorderByExpressionInParens();
3575
+ if (s6 !== peg$FAILED) {
3576
+ s7 = peg$parse_();
3577
+ if (input.charCodeAt(peg$currPos) === 41) {
3578
+ s8 = peg$c12;
3579
+ peg$currPos++;
3580
+ } else {
3581
+ s8 = peg$FAILED;
3582
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
3583
+ }
3584
+ if (s8 !== peg$FAILED) {
3585
+ peg$savedPos = s0;
3586
+ s0 = peg$f72(s6);
3587
+ } else {
3588
+ peg$currPos = s0;
3589
+ s0 = peg$FAILED;
3590
+ }
3591
+ } else {
3592
+ peg$currPos = s0;
3593
+ s0 = peg$FAILED;
3594
+ }
3595
+ } else {
3596
+ peg$currPos = s0;
3597
+ s0 = peg$FAILED;
3598
+ }
3599
+ } else {
3600
+ peg$currPos = s0;
3601
+ s0 = peg$FAILED;
3602
+ }
3603
+ if (s0 === peg$FAILED) {
3604
+ s0 = peg$currPos;
3605
+ s1 = peg$parse_();
3606
+ if (input.charCodeAt(peg$currPos) === 64) {
3607
+ s2 = peg$c39;
3608
+ peg$currPos++;
3609
+ } else {
3610
+ s2 = peg$FAILED;
3611
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3612
+ }
3613
+ if (s2 !== peg$FAILED) {
3614
+ s3 = peg$parse_();
3615
+ s4 = peg$parseaggregateExpressionWithAcross();
3616
+ if (s4 !== peg$FAILED) {
3617
+ peg$savedPos = s0;
3618
+ s0 = peg$f73(s4);
3619
+ } else {
3620
+ peg$currPos = s0;
3621
+ s0 = peg$FAILED;
3622
+ }
3623
+ } else {
3624
+ peg$currPos = s0;
3625
+ s0 = peg$FAILED;
3626
+ }
3627
+ if (s0 === peg$FAILED) {
3628
+ s0 = peg$currPos;
3629
+ s1 = peg$parse_();
3630
+ if (input.charCodeAt(peg$currPos) === 64) {
3631
+ s2 = peg$c39;
3632
+ peg$currPos++;
3633
+ } else {
3634
+ s2 = peg$FAILED;
3635
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3636
+ }
3637
+ if (s2 !== peg$FAILED) {
3638
+ s3 = peg$parse_();
3639
+ s4 = peg$parseaggregationKeyword();
3640
+ if (s4 !== peg$FAILED) {
3641
+ peg$savedPos = s0;
3642
+ s0 = peg$f74(s4);
3643
+ } else {
3644
+ peg$currPos = s0;
3645
+ s0 = peg$FAILED;
3646
+ }
3647
+ } else {
3648
+ peg$currPos = s0;
3649
+ s0 = peg$FAILED;
3650
+ }
3651
+ if (s0 === peg$FAILED) {
3652
+ s0 = peg$currPos;
3653
+ s1 = peg$parse_();
3654
+ if (input.charCodeAt(peg$currPos) === 64) {
3655
+ s2 = peg$c39;
3656
+ peg$currPos++;
3657
+ } else {
3658
+ s2 = peg$FAILED;
3659
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3660
+ }
3661
+ if (s2 !== peg$FAILED) {
3662
+ s3 = peg$parse_();
3663
+ s4 = peg$parseidentifier();
3664
+ if (s4 !== peg$FAILED) {
3665
+ if (input.charCodeAt(peg$currPos) === 46) {
3666
+ s5 = peg$c8;
3667
+ peg$currPos++;
3668
+ } else {
3669
+ s5 = peg$FAILED;
3670
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
3671
+ }
3672
+ if (s5 !== peg$FAILED) {
3673
+ s6 = peg$parseaggregationKeyword();
3674
+ if (s6 !== peg$FAILED) {
3675
+ peg$savedPos = s0;
3676
+ s0 = peg$f75(s4, s6);
3677
+ } else {
3678
+ peg$currPos = s0;
3679
+ s0 = peg$FAILED;
3680
+ }
3681
+ } else {
3682
+ peg$currPos = s0;
3683
+ s0 = peg$FAILED;
3684
+ }
3685
+ } else {
3686
+ peg$currPos = s0;
3687
+ s0 = peg$FAILED;
3688
+ }
3689
+ } else {
3690
+ peg$currPos = s0;
3691
+ s0 = peg$FAILED;
3692
+ }
3693
+ if (s0 === peg$FAILED) {
3694
+ s0 = peg$currPos;
3695
+ s1 = peg$parse_();
3696
+ if (input.charCodeAt(peg$currPos) === 64) {
3697
+ s2 = peg$c39;
3698
+ peg$currPos++;
3699
+ } else {
3700
+ s2 = peg$FAILED;
3701
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
3702
+ }
3703
+ if (s2 !== peg$FAILED) {
3704
+ s3 = peg$parse_();
3705
+ s4 = peg$parseidentifier();
3706
+ if (s4 !== peg$FAILED) {
3707
+ peg$savedPos = s0;
3708
+ s0 = peg$f76(s4);
3709
+ } else {
3710
+ peg$currPos = s0;
3711
+ s0 = peg$FAILED;
3712
+ }
3713
+ } else {
3714
+ peg$currPos = s0;
3715
+ s0 = peg$FAILED;
3716
+ }
3717
+ }
3718
+ }
3719
+ }
3720
+ }
3721
+
3722
+ return s0;
3723
+ }
3724
+
3725
+ function peg$parsediffAnnotation() {
3726
+ var s0, s1, s2, s3, s4;
3727
+
3728
+ s0 = peg$currPos;
3729
+ s1 = peg$parse_();
3730
+ if (input.charCodeAt(peg$currPos) === 126) {
3731
+ s2 = peg$c41;
3732
+ peg$currPos++;
3733
+ } else {
3734
+ s2 = peg$FAILED;
3735
+ if (peg$silentFails === 0) { peg$fail(peg$e44); }
3736
+ }
3737
+ if (s2 !== peg$FAILED) {
3738
+ s3 = peg$parse_();
3739
+ s4 = peg$parseidentifier();
3740
+ if (s4 !== peg$FAILED) {
3741
+ peg$savedPos = s0;
3742
+ s0 = peg$f77(s4);
3743
+ } else {
3744
+ peg$currPos = s0;
3745
+ s0 = peg$FAILED;
3746
+ }
3747
+ } else {
3748
+ peg$currPos = s0;
3749
+ s0 = peg$FAILED;
3750
+ }
3751
+
3752
+ return s0;
3753
+ }
3754
+
3755
+ function peg$parseoverAnnotation() {
3756
+ var s0, s1, s2, s3, s4;
3757
+
3758
+ s0 = peg$currPos;
3759
+ s1 = peg$parse_();
3760
+ if (input.charCodeAt(peg$currPos) === 47) {
3761
+ s2 = peg$c40;
3762
+ peg$currPos++;
3763
+ } else {
3764
+ s2 = peg$FAILED;
3765
+ if (peg$silentFails === 0) { peg$fail(peg$e43); }
3766
+ }
3767
+ if (s2 !== peg$FAILED) {
3768
+ s3 = peg$parse_();
3769
+ s4 = peg$parseidentifier();
3770
+ if (s4 !== peg$FAILED) {
3771
+ peg$savedPos = s0;
3772
+ s0 = peg$f78(s4);
3773
+ } else {
3774
+ peg$currPos = s0;
3775
+ s0 = peg$FAILED;
3776
+ }
3777
+ } else {
3778
+ peg$currPos = s0;
3779
+ s0 = peg$FAILED;
3780
+ }
3781
+ if (s0 === peg$FAILED) {
3782
+ s0 = peg$currPos;
3783
+ s1 = peg$parse_();
3784
+ if (input.charCodeAt(peg$currPos) === 47) {
3785
+ s2 = peg$c40;
3786
+ peg$currPos++;
3787
+ } else {
3788
+ s2 = peg$FAILED;
3789
+ if (peg$silentFails === 0) { peg$fail(peg$e43); }
3790
+ }
3791
+ if (s2 !== peg$FAILED) {
3792
+ s3 = peg$parse_();
3793
+ s4 = input.substr(peg$currPos, 3);
3794
+ if (s4.toLowerCase() === peg$c30) {
3795
+ peg$currPos += 3;
3796
+ } else {
3797
+ s4 = peg$FAILED;
3798
+ if (peg$silentFails === 0) { peg$fail(peg$e32); }
3799
+ }
3800
+ if (s4 !== peg$FAILED) {
3801
+ peg$savedPos = s0;
3802
+ s0 = peg$f79();
3803
+ } else {
3804
+ peg$currPos = s0;
3805
+ s0 = peg$FAILED;
3806
+ }
3807
+ } else {
3808
+ peg$currPos = s0;
3809
+ s0 = peg$FAILED;
3810
+ }
3811
+ }
3812
+
3813
+ return s0;
3814
+ }
3815
+
3816
+ function peg$parseidentifier() {
3817
+ var s0, s1, s2, s3, s4, s5, s6;
3818
+
3819
+ s0 = peg$currPos;
3820
+ s1 = peg$currPos;
3821
+ peg$silentFails++;
3822
+ s2 = peg$parsereservedWord();
3823
+ peg$silentFails--;
3824
+ if (s2 === peg$FAILED) {
3825
+ s1 = undefined;
3826
+ } else {
3827
+ peg$currPos = s1;
3828
+ s1 = peg$FAILED;
3829
+ }
3830
+ if (s1 !== peg$FAILED) {
3831
+ s2 = peg$currPos;
3832
+ s3 = peg$currPos;
3833
+ s4 = input.charAt(peg$currPos);
3834
+ if (peg$r2.test(s4)) {
3835
+ peg$currPos++;
3836
+ } else {
3837
+ s4 = peg$FAILED;
3838
+ if (peg$silentFails === 0) { peg$fail(peg$e45); }
3839
+ }
3840
+ if (s4 !== peg$FAILED) {
3841
+ s5 = [];
3842
+ s6 = input.charAt(peg$currPos);
3843
+ if (peg$r0.test(s6)) {
3844
+ peg$currPos++;
3845
+ } else {
3846
+ s6 = peg$FAILED;
3847
+ if (peg$silentFails === 0) { peg$fail(peg$e31); }
3848
+ }
3849
+ while (s6 !== peg$FAILED) {
3850
+ s5.push(s6);
3851
+ s6 = input.charAt(peg$currPos);
3852
+ if (peg$r0.test(s6)) {
3853
+ peg$currPos++;
3854
+ } else {
3855
+ s6 = peg$FAILED;
3856
+ if (peg$silentFails === 0) { peg$fail(peg$e31); }
3857
+ }
3858
+ }
3859
+ s4 = [s4, s5];
3860
+ s3 = s4;
3861
+ } else {
3862
+ peg$currPos = s3;
3863
+ s3 = peg$FAILED;
3864
+ }
3865
+ if (s3 !== peg$FAILED) {
3866
+ s2 = input.substring(s2, peg$currPos);
3867
+ } else {
3868
+ s2 = s3;
3869
+ }
3870
+ if (s2 !== peg$FAILED) {
3871
+ peg$savedPos = s0;
3872
+ s0 = peg$f80(s2);
3873
+ } else {
3874
+ peg$currPos = s0;
3875
+ s0 = peg$FAILED;
3876
+ }
3877
+ } else {
3878
+ peg$currPos = s0;
3879
+ s0 = peg$FAILED;
3880
+ }
3881
+
3882
+ return s0;
3883
+ }
3884
+
3885
+ function peg$parsereservedWord() {
3886
+ var s0, s1, s2, s3;
3887
+
3888
+ s0 = peg$currPos;
3889
+ s1 = input.substr(peg$currPos, 5);
3890
+ if (s1.toLowerCase() === peg$c42) {
3891
+ peg$currPos += 5;
3892
+ } else {
3893
+ s1 = peg$FAILED;
3894
+ if (peg$silentFails === 0) { peg$fail(peg$e46); }
3895
+ }
3896
+ if (s1 === peg$FAILED) {
3897
+ s1 = input.substr(peg$currPos, 7);
3898
+ if (s1.toLowerCase() === peg$c43) {
3899
+ peg$currPos += 7;
3900
+ } else {
3901
+ s1 = peg$FAILED;
3902
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
3903
+ }
3904
+ if (s1 === peg$FAILED) {
3905
+ s1 = input.substr(peg$currPos, 4);
3906
+ if (s1.toLowerCase() === peg$c44) {
3907
+ peg$currPos += 4;
3908
+ } else {
3909
+ s1 = peg$FAILED;
3910
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
3911
+ }
3912
+ if (s1 === peg$FAILED) {
3913
+ s1 = input.substr(peg$currPos, 5);
3914
+ if (s1.toLowerCase() === peg$c45) {
3915
+ peg$currPos += 5;
3916
+ } else {
3917
+ s1 = peg$FAILED;
3918
+ if (peg$silentFails === 0) { peg$fail(peg$e49); }
3919
+ }
3920
+ if (s1 === peg$FAILED) {
3921
+ s1 = input.substr(peg$currPos, 4);
3922
+ if (s1.toLowerCase() === peg$c15) {
3923
+ peg$currPos += 4;
3924
+ } else {
3925
+ s1 = peg$FAILED;
3926
+ if (peg$silentFails === 0) { peg$fail(peg$e16); }
3927
+ }
3928
+ if (s1 === peg$FAILED) {
3929
+ s1 = input.substr(peg$currPos, 4);
3930
+ if (s1.toLowerCase() === peg$c14) {
3931
+ peg$currPos += 4;
3932
+ } else {
3933
+ s1 = peg$FAILED;
3934
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
3935
+ }
3936
+ if (s1 === peg$FAILED) {
3937
+ s1 = input.substr(peg$currPos, 7);
3938
+ if (s1.toLowerCase() === peg$c46) {
3939
+ peg$currPos += 7;
3940
+ } else {
3941
+ s1 = peg$FAILED;
3942
+ if (peg$silentFails === 0) { peg$fail(peg$e50); }
3943
+ }
3944
+ if (s1 === peg$FAILED) {
3945
+ s1 = input.substr(peg$currPos, 3);
3946
+ if (s1.toLowerCase() === peg$c30) {
3947
+ peg$currPos += 3;
3948
+ } else {
3949
+ s1 = peg$FAILED;
3950
+ if (peg$silentFails === 0) { peg$fail(peg$e32); }
3951
+ }
3952
+ if (s1 === peg$FAILED) {
3953
+ s1 = input.substr(peg$currPos, 4);
3954
+ if (s1.toLowerCase() === peg$c47) {
3955
+ peg$currPos += 4;
3956
+ } else {
3957
+ s1 = peg$FAILED;
3958
+ if (peg$silentFails === 0) { peg$fail(peg$e51); }
3959
+ }
3960
+ if (s1 === peg$FAILED) {
3961
+ s1 = input.substr(peg$currPos, 2);
3962
+ if (s1.toLowerCase() === peg$c48) {
3963
+ peg$currPos += 2;
3964
+ } else {
3965
+ s1 = peg$FAILED;
3966
+ if (peg$silentFails === 0) { peg$fail(peg$e52); }
3967
+ }
3968
+ if (s1 === peg$FAILED) {
3969
+ s1 = input.substr(peg$currPos, 3);
3970
+ if (s1.toLowerCase() === peg$c16) {
3971
+ peg$currPos += 3;
3972
+ } else {
3973
+ s1 = peg$FAILED;
3974
+ if (peg$silentFails === 0) { peg$fail(peg$e17); }
3975
+ }
3976
+ if (s1 === peg$FAILED) {
3977
+ s1 = input.substr(peg$currPos, 4);
3978
+ if (s1.toLowerCase() === peg$c17) {
3979
+ peg$currPos += 4;
3980
+ } else {
3981
+ s1 = peg$FAILED;
3982
+ if (peg$silentFails === 0) { peg$fail(peg$e18); }
3983
+ }
3984
+ if (s1 === peg$FAILED) {
3985
+ s1 = input.substr(peg$currPos, 6);
3986
+ if (s1.toLowerCase() === peg$c13) {
3987
+ peg$currPos += 6;
3988
+ } else {
3989
+ s1 = peg$FAILED;
3990
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
3991
+ }
3992
+ }
3993
+ }
3994
+ }
3995
+ }
3996
+ }
3997
+ }
3998
+ }
3999
+ }
4000
+ }
4001
+ }
4002
+ }
4003
+ }
4004
+ if (s1 !== peg$FAILED) {
4005
+ s2 = peg$currPos;
4006
+ peg$silentFails++;
4007
+ s3 = peg$parseidentifierChar();
4008
+ peg$silentFails--;
4009
+ if (s3 === peg$FAILED) {
4010
+ s2 = undefined;
4011
+ } else {
4012
+ peg$currPos = s2;
4013
+ s2 = peg$FAILED;
4014
+ }
4015
+ if (s2 !== peg$FAILED) {
4016
+ s1 = [s1, s2];
4017
+ s0 = s1;
4018
+ } else {
4019
+ peg$currPos = s0;
4020
+ s0 = peg$FAILED;
4021
+ }
4022
+ } else {
4023
+ peg$currPos = s0;
4024
+ s0 = peg$FAILED;
4025
+ }
4026
+
4027
+ return s0;
4028
+ }
4029
+
4030
+ function peg$parsestringLiteral() {
4031
+ var s0, s1, s2, s3, s4;
4032
+
4033
+ s0 = peg$currPos;
4034
+ if (input.charCodeAt(peg$currPos) === 34) {
4035
+ s1 = peg$c49;
4036
+ peg$currPos++;
4037
+ } else {
4038
+ s1 = peg$FAILED;
4039
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
4040
+ }
4041
+ if (s1 !== peg$FAILED) {
4042
+ s2 = peg$currPos;
4043
+ s3 = [];
4044
+ s4 = input.charAt(peg$currPos);
4045
+ if (peg$r3.test(s4)) {
4046
+ peg$currPos++;
4047
+ } else {
4048
+ s4 = peg$FAILED;
4049
+ if (peg$silentFails === 0) { peg$fail(peg$e54); }
4050
+ }
4051
+ while (s4 !== peg$FAILED) {
4052
+ s3.push(s4);
4053
+ s4 = input.charAt(peg$currPos);
4054
+ if (peg$r3.test(s4)) {
4055
+ peg$currPos++;
4056
+ } else {
4057
+ s4 = peg$FAILED;
4058
+ if (peg$silentFails === 0) { peg$fail(peg$e54); }
4059
+ }
4060
+ }
4061
+ s2 = input.substring(s2, peg$currPos);
4062
+ if (input.charCodeAt(peg$currPos) === 34) {
4063
+ s3 = peg$c49;
4064
+ peg$currPos++;
4065
+ } else {
4066
+ s3 = peg$FAILED;
4067
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
4068
+ }
4069
+ if (s3 !== peg$FAILED) {
4070
+ peg$savedPos = s0;
4071
+ s0 = peg$f81(s2);
4072
+ } else {
4073
+ peg$currPos = s0;
4074
+ s0 = peg$FAILED;
4075
+ }
4076
+ } else {
4077
+ peg$currPos = s0;
4078
+ s0 = peg$FAILED;
4079
+ }
4080
+ if (s0 === peg$FAILED) {
4081
+ s0 = peg$currPos;
4082
+ if (input.charCodeAt(peg$currPos) === 39) {
4083
+ s1 = peg$c50;
4084
+ peg$currPos++;
4085
+ } else {
4086
+ s1 = peg$FAILED;
4087
+ if (peg$silentFails === 0) { peg$fail(peg$e55); }
4088
+ }
4089
+ if (s1 !== peg$FAILED) {
4090
+ s2 = peg$currPos;
4091
+ s3 = [];
4092
+ s4 = input.charAt(peg$currPos);
4093
+ if (peg$r4.test(s4)) {
4094
+ peg$currPos++;
4095
+ } else {
4096
+ s4 = peg$FAILED;
4097
+ if (peg$silentFails === 0) { peg$fail(peg$e56); }
4098
+ }
4099
+ while (s4 !== peg$FAILED) {
4100
+ s3.push(s4);
4101
+ s4 = input.charAt(peg$currPos);
4102
+ if (peg$r4.test(s4)) {
4103
+ peg$currPos++;
4104
+ } else {
4105
+ s4 = peg$FAILED;
4106
+ if (peg$silentFails === 0) { peg$fail(peg$e56); }
4107
+ }
4108
+ }
4109
+ s2 = input.substring(s2, peg$currPos);
4110
+ if (input.charCodeAt(peg$currPos) === 39) {
4111
+ s3 = peg$c50;
4112
+ peg$currPos++;
4113
+ } else {
4114
+ s3 = peg$FAILED;
4115
+ if (peg$silentFails === 0) { peg$fail(peg$e55); }
4116
+ }
4117
+ if (s3 !== peg$FAILED) {
4118
+ peg$savedPos = s0;
4119
+ s0 = peg$f82(s2);
4120
+ } else {
4121
+ peg$currPos = s0;
4122
+ s0 = peg$FAILED;
4123
+ }
4124
+ } else {
4125
+ peg$currPos = s0;
4126
+ s0 = peg$FAILED;
4127
+ }
4128
+ }
4129
+
4130
+ return s0;
4131
+ }
4132
+
4133
+ function peg$parseTABLE() {
4134
+ var s0;
4135
+
4136
+ s0 = input.substr(peg$currPos, 5);
4137
+ if (s0.toLowerCase() === peg$c42) {
4138
+ peg$currPos += 5;
4139
+ } else {
4140
+ s0 = peg$FAILED;
4141
+ if (peg$silentFails === 0) { peg$fail(peg$e46); }
4142
+ }
4143
+
4144
+ return s0;
4145
+ }
4146
+
4147
+ function peg$parseOPTIONS() {
4148
+ var s0;
4149
+
4150
+ s0 = input.substr(peg$currPos, 7);
4151
+ if (s0.toLowerCase() === peg$c43) {
4152
+ peg$currPos += 7;
4153
+ } else {
4154
+ s0 = peg$FAILED;
4155
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
4156
+ }
4157
+
4158
+ return s0;
4159
+ }
4160
+
4161
+ function peg$parseFROM() {
4162
+ var s0;
4163
+
4164
+ s0 = input.substr(peg$currPos, 4);
4165
+ if (s0.toLowerCase() === peg$c44) {
4166
+ peg$currPos += 4;
4167
+ } else {
4168
+ s0 = peg$FAILED;
4169
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
4170
+ }
4171
+
4172
+ return s0;
4173
+ }
4174
+
4175
+ function peg$parseWHERE() {
4176
+ var s0;
4177
+
4178
+ s0 = input.substr(peg$currPos, 5);
4179
+ if (s0.toLowerCase() === peg$c45) {
4180
+ peg$currPos += 5;
4181
+ } else {
4182
+ s0 = peg$FAILED;
4183
+ if (peg$silentFails === 0) { peg$fail(peg$e49); }
4184
+ }
4185
+
4186
+ return s0;
4187
+ }
4188
+
4189
+ function peg$parseROWS() {
4190
+ var s0;
4191
+
4192
+ s0 = input.substr(peg$currPos, 4);
4193
+ if (s0.toLowerCase() === peg$c15) {
4194
+ peg$currPos += 4;
4195
+ } else {
4196
+ s0 = peg$FAILED;
4197
+ if (peg$silentFails === 0) { peg$fail(peg$e16); }
4198
+ }
4199
+
4200
+ return s0;
4201
+ }
4202
+
4203
+ function peg$parseCOLS() {
4204
+ var s0;
4205
+
4206
+ s0 = input.substr(peg$currPos, 4);
4207
+ if (s0.toLowerCase() === peg$c14) {
4208
+ peg$currPos += 4;
4209
+ } else {
4210
+ s0 = peg$FAILED;
4211
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
4212
+ }
4213
+ if (s0 === peg$FAILED) {
4214
+ s0 = input.substr(peg$currPos, 7);
4215
+ if (s0.toLowerCase() === peg$c46) {
4216
+ peg$currPos += 7;
4217
+ } else {
4218
+ s0 = peg$FAILED;
4219
+ if (peg$silentFails === 0) { peg$fail(peg$e50); }
4220
+ }
4221
+ }
4222
+
4223
+ return s0;
4224
+ }
4225
+
4226
+ function peg$parseTHEN() {
4227
+ var s0;
4228
+
4229
+ s0 = input.substr(peg$currPos, 4);
4230
+ if (s0.toLowerCase() === peg$c47) {
4231
+ peg$currPos += 4;
4232
+ } else {
4233
+ s0 = peg$FAILED;
4234
+ if (peg$silentFails === 0) { peg$fail(peg$e51); }
4235
+ }
4236
+
4237
+ return s0;
4238
+ }
4239
+
4240
+ function peg$parseBY() {
4241
+ var s0;
4242
+
4243
+ s0 = input.substr(peg$currPos, 2);
4244
+ if (s0.toLowerCase() === peg$c48) {
4245
+ peg$currPos += 2;
4246
+ } else {
4247
+ s0 = peg$FAILED;
4248
+ if (peg$silentFails === 0) { peg$fail(peg$e52); }
4249
+ }
4250
+
4251
+ return s0;
4252
+ }
4253
+
4254
+ function peg$parse_() {
4255
+ var s0, s1;
4256
+
4257
+ peg$silentFails++;
4258
+ s0 = [];
4259
+ s1 = input.charAt(peg$currPos);
4260
+ if (peg$r5.test(s1)) {
4261
+ peg$currPos++;
4262
+ } else {
4263
+ s1 = peg$FAILED;
4264
+ if (peg$silentFails === 0) { peg$fail(peg$e58); }
4265
+ }
4266
+ while (s1 !== peg$FAILED) {
4267
+ s0.push(s1);
4268
+ s1 = input.charAt(peg$currPos);
4269
+ if (peg$r5.test(s1)) {
4270
+ peg$currPos++;
4271
+ } else {
4272
+ s1 = peg$FAILED;
4273
+ if (peg$silentFails === 0) { peg$fail(peg$e58); }
4274
+ }
4275
+ }
4276
+ peg$silentFails--;
4277
+ s1 = peg$FAILED;
4278
+ if (peg$silentFails === 0) { peg$fail(peg$e57); }
4279
+
4280
+ return s0;
4281
+ }
4282
+
4283
+ function peg$parse__() {
4284
+ var s0, s1;
4285
+
4286
+ peg$silentFails++;
4287
+ s0 = [];
4288
+ s1 = input.charAt(peg$currPos);
4289
+ if (peg$r5.test(s1)) {
4290
+ peg$currPos++;
4291
+ } else {
4292
+ s1 = peg$FAILED;
4293
+ if (peg$silentFails === 0) { peg$fail(peg$e58); }
4294
+ }
4295
+ if (s1 !== peg$FAILED) {
4296
+ while (s1 !== peg$FAILED) {
4297
+ s0.push(s1);
4298
+ s1 = input.charAt(peg$currPos);
4299
+ if (peg$r5.test(s1)) {
4300
+ peg$currPos++;
4301
+ } else {
4302
+ s1 = peg$FAILED;
4303
+ if (peg$silentFails === 0) { peg$fail(peg$e58); }
4304
+ }
4305
+ }
4306
+ } else {
4307
+ s0 = peg$FAILED;
4308
+ }
4309
+ peg$silentFails--;
4310
+ if (s0 === peg$FAILED) {
4311
+ s1 = peg$FAILED;
4312
+ if (peg$silentFails === 0) { peg$fail(peg$e59); }
4313
+ }
4314
+
4315
+ return s0;
4316
+ }
4317
+
4318
+ peg$result = peg$startRuleFunction();
4319
+
4320
+ if (options.peg$library) {
4321
+ return /** @type {any} */ ({
4322
+ peg$result,
4323
+ peg$currPos,
4324
+ peg$FAILED,
4325
+ peg$maxFailExpected,
4326
+ peg$maxFailPos
4327
+ });
4328
+ }
4329
+ if (peg$result !== peg$FAILED && peg$currPos === input.length) {
4330
+ return peg$result;
4331
+ } else {
4332
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
4333
+ peg$fail(peg$endExpectation());
4334
+ }
4335
+
4336
+ throw peg$buildStructuredError(
4337
+ peg$maxFailExpected,
4338
+ peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
4339
+ peg$maxFailPos < input.length
4340
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
4341
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
4342
+ );
4343
+ }
4344
+ }
4345
+
4346
+ const peg$allowedStartRules = [
4347
+ "start"
4348
+ ];
4349
+
4350
+ export {
4351
+ peg$allowedStartRules as StartRules,
4352
+ peg$SyntaxError as SyntaxError,
4353
+ peg$parse as parse
4354
+ };