UNPKG

esql

Version:

Humane query language for Elasticsearch

1,672 lines (1,563 loc) 105 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.esql=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function (global){ var _ = (typeof window !== "undefined" ? window._ : typeof global !== "undefined" ? global._ : null) , parse = require('./parser').parse , walk = require('./walk') , emit = require('./emit') , slice = Array.prototype.slice module.exports = compile compile.prepare = prepare function compile(eq) { var parsed = parse(eq || '') return generate(parsed, slice.call(arguments, 1)) } function prepare(eq) { var parsed = parse(eq || '') return function() { var clone = _.cloneDeep(parsed) return generate(clone, slice.call(arguments)) } } function generate(parsed, args) { return emit(walk.apply(null, [parsed].concat(args))) } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./emit":2,"./parser":3,"./walk":4}],2:[function(require,module,exports){ (function (global){ var _ = (typeof window !== "undefined" ? window._ : typeof global !== "undefined" ? global._ : null) module.exports = function (parsed) { var query = { body: { query: {} } } _.each([from, filter, match, sort], function (f) { f(query, parsed) }) return query } function from(query, parsed) { if (parsed.index) query.index = parsed.index if (parsed.type) query.type = parsed.type _.each(parsed.options, function (v, k) { query[k] = v }) } function filter(query, parsed) { if (!parsed.filter) return var filters = parsed.filter.filters , options = parsed.filter.options , groups = _.groupBy(filters, function (f) { return f.op }) , bool = (query.body.query.filtered = { filter: { bool: {} } }).filter.bool _.extend(bool, options) _.each(groups, function (conds, op) { conds = esConds(expandMulti(conds)) bool[op] = conds.length > 1 ? conds : conds[0] }) // [a, b = 1] -> a = 1, b = 1 function expandMulti(conds) { return _.flatten(_.map(conds, function (c) { if (_.isArray(c.id)) { return _.map(c.id, function (id) { return _.extend({}, c, { id: id }) }) } else return c })) } function esConds(conds) { return _.map(conds, function (c) { var esCond = {} , range = getRange(c.value) , type = range ? 'range' : _.isArray(c.value) ? 'terms' : 'term' esCond[type] = {} esCond[type][c.id] = range || c.value _.extend(esCond[type], c.options) return esCond }) } } function match(query, parsed) { if (!parsed.match) return var matches = parsed.match.matches , options = parsed.match.options , groups = _.groupBy(matches, function (f) { return f.op }) , bool if (parsed.filter) query.body.query.filtered.query = { bool: bool = {} } else query.body.query = { bool: bool = {} } _.extend(bool, options) _.each(groups, function (conds, op) { conds = esConds(conds) bool[op] = conds.length > 1 ? conds : conds[0] }) function esConds(conds) { return _.map(conds, function (c) { var esCond = {} if (_.isArray(c.id)) { esCond.multi_match = { // jshint ignore:line fields : c.id, query : c.value } _.extend(esCond.multi_match, c.options) // jshint ignore:line } else { var range = getRange(c.value) , value = range || c.value , type = range ? 'range' : 'match' esCond[type] = {} esCond[type][c.id] = c.options ? _.extend({}, c.options, { query : value }) : value } return esCond }) } } function sort(query, parsed) { if (!parsed.sort) return query.body.sort = _.map(parsed.sort.sorts, function (s) { var res = {} res[s.id] = { order: s.order } _.extend(res[s.id], s.options) return res }) // TODO: use parsed.sort.options? } function getRange(v) { if (_.isPlainObject(v) && v.op && (v.start || v.end)) { var range = {} if (v.start) range.gte = v.start if (v.end) range[v.op === '..' ? 'lte' : 'lt'] = v.end return range } } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],3:[function(require,module,exports){ module.exports = (function() { /* * Generated by PEG.js 0.8.0. * * http://pegjs.majda.cz/ */ function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function SyntaxError(message, expected, found, offset, line, column) { this.message = message; this.expected = expected; this.found = found; this.offset = offset; this.line = line; this.column = column; this.name = "SyntaxError"; } peg$subclass(SyntaxError, Error); function parse(input) { var options = arguments.length > 1 ? arguments[1] : {}, peg$FAILED = {}, peg$startRuleFunctions = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = peg$FAILED, peg$c1 = function(e) { checkParams(); return e }, peg$c2 = null, peg$c3 = function(i) { return i }, peg$c4 = function(f) { return f }, peg$c5 = function(m) { return m }, peg$c6 = function(s) { return s }, peg$c7 = function(i, f, m, s) { var parsed = {} for (var k in i) parsed[k] = i[k] parsed.filter = f parsed.match = m parsed.sort = s return parsed }, peg$c8 = { type: "other", description: "from" }, peg$c9 = function(o) { return o }, peg$c10 = function(s, o) { s.options = o return s }, peg$c11 = { type: "other", description: "scope" }, peg$c12 = "/", peg$c13 = { type: "literal", value: "/", description: "\"/\"" }, peg$c14 = function(t) { return t }, peg$c15 = function(i, t) { return { index: i, type: t } }, peg$c16 = { type: "other", description: "filter" }, peg$c17 = function(c, o) { return { filters : c, options : o } }, peg$c18 = { type: "other", description: "match" }, peg$c19 = function(c, o) { return { matches : c, options : o } }, peg$c20 = { type: "other", description: "conditions" }, peg$c21 = [], peg$c22 = ",", peg$c23 = { type: "literal", value: ",", description: "\",\"" }, peg$c24 = function(c) { return c }, peg$c25 = function(first, rest) { return [first].concat(rest) }, peg$c26 = { type: "other", description: "condition" }, peg$c27 = function(id, op, v, o) { return { id: id, op: op, value: v, options: o } }, peg$c28 = { type: "other", description: "operator" }, peg$c29 = "==", peg$c30 = { type: "literal", value: "==", description: "\"==\"" }, peg$c31 = function() { return 'must' }, peg$c32 = "!=", peg$c33 = { type: "literal", value: "!=", description: "\"!=\"" }, peg$c34 = function() { return 'must_not' }, peg$c35 = "=", peg$c36 = { type: "literal", value: "=", description: "\"=\"" }, peg$c37 = function() { return 'should' }, peg$c38 = { type: "other", description: "sort" }, peg$c39 = function(s, o) { return { sorts : s, options : o } }, peg$c40 = { type: "other", description: "orders" }, peg$c41 = function(first, rest) { return [first].concat(rest) }, peg$c42 = { type: "other", description: "order" }, peg$c43 = function(d) { return d }, peg$c44 = function(id, d, o) { return { id: id, order: d, options: o } }, peg$c45 = { type: "other", description: "direction" }, peg$c46 = { type: "other", description: "references(s)" }, peg$c47 = "[", peg$c48 = { type: "literal", value: "[", description: "\"[\"" }, peg$c49 = function(r) { return r }, peg$c50 = "]", peg$c51 = { type: "literal", value: "]", description: "\"]\"" }, peg$c52 = function(first, rest) { return [first].concat(rest) }, peg$c53 = { type: "other", description: "references" }, peg$c54 = void 0, peg$c55 = function(start, parts) { return start + parts.join('') }, peg$c56 = { type: "other", description: "id start symbol" }, peg$c57 = /^[a-zA-Z]/, peg$c58 = { type: "class", value: "[a-zA-Z]", description: "[a-zA-Z]" }, peg$c59 = "*", peg$c60 = { type: "literal", value: "*", description: "\"*\"" }, peg$c61 = "_", peg$c62 = { type: "literal", value: "_", description: "\"_\"" }, peg$c63 = { type: "other", description: "id symbol" }, peg$c64 = /^[a-zA-Z0-9]/, peg$c65 = { type: "class", value: "[a-zA-Z0-9]", description: "[a-zA-Z0-9]" }, peg$c66 = "^", peg$c67 = { type: "literal", value: "^", description: "\"^\"" }, peg$c68 = ".", peg$c69 = { type: "literal", value: ".", description: "\".\"" }, peg$c70 = { type: "other", description: "options" }, peg$c71 = "(", peg$c72 = { type: "literal", value: "(", description: "\"(\"" }, peg$c73 = ")", peg$c74 = { type: "literal", value: ")", description: "\")\"" }, peg$c75 = function(first, rest) { var arr = [first].concat(rest) for (var i = 0, obj = {}; i < arr.length; i++) { obj[arr[i].key] = arr[i].value } return obj }, peg$c76 = { type: "other", description: "option" }, peg$c77 = ":", peg$c78 = { type: "literal", value: ":", description: "\":\"" }, peg$c79 = function(n, v) { return { key: n, value: v } }, peg$c80 = { type: "other", description: "option name" }, peg$c81 = function(chars) { return chars.join('') }, peg$c82 = { type: "other", description: "option symbol" }, peg$c83 = "from", peg$c84 = { type: "literal", value: "from", description: "\"from\"" }, peg$c85 = function() { return text() }, peg$c86 = "filter", peg$c87 = { type: "literal", value: "filter", description: "\"filter\"" }, peg$c88 = "match", peg$c89 = { type: "literal", value: "match", description: "\"match\"" }, peg$c90 = "sort", peg$c91 = { type: "literal", value: "sort", description: "\"sort\"" }, peg$c92 = "with", peg$c93 = { type: "literal", value: "with", description: "\"with\"" }, peg$c94 = "asc", peg$c95 = { type: "literal", value: "asc", description: "\"asc\"" }, peg$c96 = "desc", peg$c97 = { type: "literal", value: "desc", description: "\"desc\"" }, peg$c98 = "false", peg$c99 = { type: "literal", value: "false", description: "\"false\"" }, peg$c100 = function() { return false }, peg$c101 = "true", peg$c102 = { type: "literal", value: "true", description: "\"true\"" }, peg$c103 = function() { return true }, peg$c104 = "null", peg$c105 = { type: "literal", value: "null", description: "\"null\"" }, peg$c106 = function() { return null }, peg$c107 = "$", peg$c108 = { type: "literal", value: "$", description: "\"$\"" }, peg$c109 = function(d) { var paramNum = parseInt(text().substr(1)) addParam(paramNum) return { $param: paramNum } }, peg$c110 = { type: "other", description: "array" }, peg$c111 = function(v) { return v }, peg$c112 = function(first, rest) { return [first].concat(rest) }, peg$c113 = function(v) { return v || [] }, peg$c114 = { type: "other", description: "range" }, peg$c115 = function(v1, o, v2) { return { start: v1, end: v2, op: o } }, peg$c116 = function(v1, o) { return { start: v1 , op: o } }, peg$c117 = function(o, v2) { return { end: v2, op: o } }, peg$c118 = "..", peg$c119 = { type: "literal", value: "..", description: "\"..\"" }, peg$c120 = "...", peg$c121 = { type: "literal", value: "...", description: "\"...\"" }, peg$c122 = { type: "other", description: "number" }, peg$c123 = function() { return parseFloat(text()) }, peg$c124 = /^[0-9]/, peg$c125 = { type: "class", value: "[0-9]", description: "[0-9]" }, peg$c126 = /^[1-9]/, peg$c127 = { type: "class", value: "[1-9]", description: "[1-9]" }, peg$c128 = /^[eE]/, peg$c129 = { type: "class", value: "[eE]", description: "[eE]" }, peg$c130 = "-", peg$c131 = { type: "literal", value: "-", description: "\"-\"" }, peg$c132 = "+", peg$c133 = { type: "literal", value: "+", description: "\"+\"" }, peg$c134 = "0", peg$c135 = { type: "literal", value: "0", description: "\"0\"" }, peg$c136 = { type: "other", description: "string" }, peg$c137 = "'", peg$c138 = { type: "literal", value: "'", description: "\"'\"" }, peg$c139 = "\"", peg$c140 = { type: "literal", value: "\"", description: "\"\\\"\"" }, peg$c141 = "\\", peg$c142 = { type: "literal", value: "\\", description: "\"\\\\\"" }, peg$c143 = { type: "any", description: "any character" }, peg$c144 = function() { return '\0' }, peg$c145 = "b", peg$c146 = { type: "literal", value: "b", description: "\"b\"" }, peg$c147 = function() { return '\b' }, peg$c148 = "f", peg$c149 = { type: "literal", value: "f", description: "\"f\"" }, peg$c150 = function() { return '\f' }, peg$c151 = "n", peg$c152 = { type: "literal", value: "n", description: "\"n\"" }, peg$c153 = function() { return '\n' }, peg$c154 = "r", peg$c155 = { type: "literal", value: "r", description: "\"r\"" }, peg$c156 = function() { return '\r' }, peg$c157 = "t", peg$c158 = { type: "literal", value: "t", description: "\"t\"" }, peg$c159 = function() { return '\t' }, peg$c160 = "v", peg$c161 = { type: "literal", value: "v", description: "\"v\"" }, peg$c162 = function() { return '\v' }, peg$c163 = { type: "other", description: "whitespace" }, peg$c164 = /^[ \t\n\r\xA0\uFEFF]/, peg$c165 = { type: "class", value: "[ \\t\\n\\r\\xA0\\uFEFF]", description: "[ \\t\\n\\r\\xA0\\uFEFF]" }, peg$c166 = { type: "other", description: "newline" }, peg$c167 = /^[\n\r\u2028\u2029]/, peg$c168 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" }, peg$c169 = "\r\n", peg$c170 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" }, peg$currPos = 0, peg$reportedPos = 0, peg$cachedPos = 0, peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }, peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result; if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; } function text() { return input.substring(peg$reportedPos, peg$currPos); } function offset() { return peg$reportedPos; } function line() { return peg$computePosDetails(peg$reportedPos).line; } function column() { return peg$computePosDetails(peg$reportedPos).column; } function expected(description) { throw peg$buildException( null, [{ type: "other", description: description }], peg$reportedPos ); } function error(message) { throw peg$buildException(message, null, peg$reportedPos); } function peg$computePosDetails(pos) { function advance(details, startPos, endPos) { var p, ch; for (p = startPos; p < endPos; p++) { ch = input.charAt(p); if (ch === "\n") { if (!details.seenCR) { details.line++; } details.column = 1; details.seenCR = false; } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { details.line++; details.column = 1; details.seenCR = true; } else { details.column++; details.seenCR = false; } } } if (peg$cachedPos !== pos) { if (peg$cachedPos > pos) { peg$cachedPos = 0; peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }; } advance(peg$cachedPosDetails, peg$cachedPos, pos); peg$cachedPos = pos; } return peg$cachedPosDetails; } function peg$fail(expected) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected); } function peg$buildException(message, expected, pos) { function cleanupExpected(expected) { var i = 1; expected.sort(function(a, b) { if (a.description < b.description) { return -1; } else if (a.description > b.description) { return 1; } else { return 0; } }); while (i < expected.length) { if (expected[i - 1] === expected[i]) { expected.splice(i, 1); } else { i++; } } } function buildMessage(expected, found) { function stringEscape(s) { function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } return s .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\x08/g, '\\b') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\f/g, '\\f') .replace(/\r/g, '\\r') .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); }); } var expectedDescs = new Array(expected.length), expectedDesc, foundDesc, i; for (i = 0; i < expected.length; i++) { expectedDescs[i] = expected[i].description; } expectedDesc = expected.length > 1 ? expectedDescs.slice(0, -1).join(", ") + " or " + expectedDescs[expected.length - 1] : expectedDescs[0]; foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input"; return "Expected " + expectedDesc + " but " + foundDesc + " found."; } var posDetails = peg$computePosDetails(pos), found = pos < input.length ? input.charAt(pos) : null; if (expected !== null) { cleanupExpected(expected); } return new SyntaxError( message !== null ? message : buildMessage(expected, found), expected, found, pos, posDetails.line, posDetails.column ); } function peg$parsestart() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parse_(); if (s1 !== peg$FAILED) { s2 = peg$parseesql(); if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c1(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parseesql() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parsefrom(); if (s2 !== peg$FAILED) { s3 = peg$parse___(); if (s3 !== peg$FAILED) { peg$reportedPos = s1; s2 = peg$c3(s2); s1 = s2; } else { peg$currPos = s1; s1 = peg$c0; } } else { peg$currPos = s1; s1 = peg$c0; } if (s1 === peg$FAILED) { s1 = peg$c2; } if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = peg$parsefilter(); if (s3 !== peg$FAILED) { s4 = peg$parse___(); if (s4 !== peg$FAILED) { peg$reportedPos = s2; s3 = peg$c4(s3); s2 = s3; } else { peg$currPos = s2; s2 = peg$c0; } } else { peg$currPos = s2; s2 = peg$c0; } if (s2 === peg$FAILED) { s2 = peg$c2; } if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = peg$parsematch(); if (s4 !== peg$FAILED) { s5 = peg$parse___(); if (s5 !== peg$FAILED) { peg$reportedPos = s3; s4 = peg$c5(s4); s3 = s4; } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } if (s3 === peg$FAILED) { s3 = peg$c2; } if (s3 !== peg$FAILED) { s4 = peg$currPos; s5 = peg$parsesort(); if (s5 !== peg$FAILED) { s6 = peg$parse___(); if (s6 !== peg$FAILED) { peg$reportedPos = s4; s5 = peg$c6(s5); s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } if (s4 === peg$FAILED) { s4 = peg$c2; } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c7(s1, s2, s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } return s0; } function peg$parsefrom() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; peg$silentFails++; s0 = peg$currPos; s1 = peg$parset_from(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parsescope(); if (s3 !== peg$FAILED) { s4 = peg$currPos; s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parset_with(); if (s6 !== peg$FAILED) { s7 = peg$parse_(); if (s7 !== peg$FAILED) { s8 = peg$parseoptions(); if (s8 !== peg$FAILED) { peg$reportedPos = s4; s5 = peg$c9(s8); s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } if (s4 === peg$FAILED) { s4 = peg$c2; } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c10(s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c8); } } return s0; } function peg$parsescope() { var s0, s1, s2, s3, s4, s5, s6; peg$silentFails++; s0 = peg$currPos; s1 = peg$parserefs(); if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = peg$parse_(); if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 47) { s4 = peg$c12; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parserefs(); if (s6 !== peg$FAILED) { peg$reportedPos = s2; s3 = peg$c14(s6); s2 = s3; } else { peg$currPos = s2; s2 = peg$c0; } } else { peg$currPos = s2; s2 = peg$c0; } } else { peg$currPos = s2; s2 = peg$c0; } } else { peg$currPos = s2; s2 = peg$c0; } if (s2 === peg$FAILED) { s2 = peg$c2; } if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c15(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c11); } } return s0; } function peg$parsefilter() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; peg$silentFails++; s0 = peg$currPos; s1 = peg$parset_filter(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseconditions(); if (s3 !== peg$FAILED) { s4 = peg$currPos; s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parset_with(); if (s6 !== peg$FAILED) { s7 = peg$parse_(); if (s7 !== peg$FAILED) { s8 = peg$parseoptions(); if (s8 !== peg$FAILED) { peg$reportedPos = s4; s5 = peg$c9(s8); s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } if (s4 === peg$FAILED) { s4 = peg$c2; } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c17(s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c16); } } return s0; } function peg$parsematch() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; peg$silentFails++; s0 = peg$currPos; s1 = peg$parset_match(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseconditions(); if (s3 !== peg$FAILED) { s4 = peg$currPos; s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parset_with(); if (s6 !== peg$FAILED) { s7 = peg$parse_(); if (s7 !== peg$FAILED) { s8 = peg$parseoptions(); if (s8 !== peg$FAILED) { peg$reportedPos = s4; s5 = peg$c9(s8); s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } if (s4 === peg$FAILED) { s4 = peg$c2; } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c19(s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } return s0; } function peg$parseconditions() { var s0, s1, s2, s3, s4, s5, s6, s7; peg$silentFails++; s0 = peg$currPos; s1 = peg$parsecondition(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parse_(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c22; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parsecondition(); if (s7 !== peg$FAILED) { peg$reportedPos = s3; s4 = peg$c24(s7); s3 = s4; } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parse_(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c22; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parsecondition(); if (s7 !== peg$FAILED) { peg$reportedPos = s3; s4 = peg$c24(s7); s3 = s4; } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c25(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c20); } } return s0; } function peg$parsecondition() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; peg$silentFails++; s0 = peg$currPos; s1 = peg$parserefs(); if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { s3 = peg$parseop(); if (s3 !== peg$FAILED) { s4 = peg$parse_(); if (s4 !== peg$FAILED) { s5 = peg$parsevalue(); if (s5 !== peg$FAILED) { s6 = peg$currPos; s7 = peg$parse_(); if (s7 !== peg$FAILED) { s8 = peg$parseoptions(); if (s8 !== peg$FAILED) { peg$reportedPos = s6; s7 = peg$c9(s8); s6 = s7; } else { peg$currPos = s6; s6 = peg$c0; } } else { peg$currPos = s6; s6 = peg$c0; } if (s6 === peg$FAILED) { s6 = peg$c2; } if (s6 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c27(s1, s3, s5, s6); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c26); } } return s0; } function peg$parseop() { var s0, s1; peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c29) { s1 = peg$c29; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c30); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c31(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c32) { s1 = peg$c32; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c33); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c34(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 61) { s1 = peg$c35; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c37(); } s0 = s1; } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } return s0; } function peg$parsesort() { var s0, s1, s2, s3, s4, s5, s6, s7, s8; peg$silentFails++; s0 = peg$currPos; s1 = peg$parset_sort(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseorders(); if (s3 !== peg$FAILED) { s4 = peg$currPos; s5 = peg$parse_(); if (s5 !== peg$FAILED) { s6 = peg$parset_with(); if (s6 !== peg$FAILED) { s7 = peg$parse_(); if (s7 !== peg$FAILED) { s8 = peg$parseoptions(); if (s8 !== peg$FAILED) { peg$reportedPos = s4; s5 = peg$c9(s8); s4 = s5; } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } } else { peg$currPos = s4; s4 = peg$c0; } if (s4 === peg$FAILED) { s4 = peg$c2; } if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c39(s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } return s0; } function peg$parseorders() { var s0, s1, s2, s3, s4, s5, s6, s7; peg$silentFails++; s0 = peg$currPos; s1 = peg$parseorder(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parse_(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c22; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parseorder(); if (s7 !== peg$FAILED) { peg$reportedPos = s3; s4 = peg$c6(s7); s3 = s4; } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parse_(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c22; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s5 !== peg$FAILED) { s6 = peg$parse_(); if (s6 !== peg$FAILED) { s7 = peg$parseorder(); if (s7 !== peg$FAILED) { peg$reportedPos = s3; s4 = peg$c6(s7); s3 = s4; } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c41(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c40); } } return s0; } function peg$parseorder() { var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; s1 = peg$parseref(); if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = peg$parse__(); if (s3 !== peg$FAILED) { s4 = peg$parsedirection(); if (s4 !== peg$FAILED) { peg$reportedPos = s2; s3 = peg$c43(s4); s2 = s3; } else { peg$currPos = s2; s2 = peg$c0; } } else { peg$currPos = s2; s2 = peg$c0; } if (s2 === peg$FAILED) { s2 = peg$c2; } if (s2 !== peg$FAILED) { s3 = peg$currPos; s4 = peg$parse_(); if (s4 !== peg$FAILED) { s5 = peg$parseoptions(); if (s5 !== peg$FAILED) { peg$reportedPos = s3; s4 = peg$c9(s5); s3 = s4; } else { peg$currPos = s3; s3 = peg$c0; } } else { peg$currPos = s3; s3 = peg$c0; } if (s3 === peg$FAILED) { s3 = peg$c2; } if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c44(s1, s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c42); } } return s0; } function peg$parsedirection() { var s0, s1; peg$silentFails++; s0 = peg$parset_asc(); if (s0 === peg$FAILED) { s0 = peg$parset_desc(); } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c45); } } return s0; } function peg$parserefs() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; peg$silentFails++; s0 = peg$parseref(); if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { s1 = peg$c47; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s1 !== peg$FAILED) { s2 = peg$parse_(); if (s2 !== peg$FAILED) { s3 = peg$parseref(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$currPos; s6 = peg$parse_(); if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s7 = peg$c22; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s7 !== peg$FAILED) { s8 = peg$parse_(); if (s8 !== peg$FAILED) { s9 = peg$parseref(); if (s9 !== peg$FAILED) { peg$reportedPos = s5; s6 = peg$c49(s9); s5 = s6; } else { peg$currPos = s5; s5 = peg$c0; } } else { peg$currPos = s5; s5 = peg$c0; } } else { peg$currPos = s5; s5 = peg$c0; } } else { peg$currPos = s5; s5 = peg$c0; } while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$currPos; s6 = peg$parse_(); if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s7 = peg$c22; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s7 !== peg$FAILED) { s8 = peg$parse_(); if (s8 !== peg$FAILED) { s9 = peg$parseref(); if (s9 !== peg$FAILED) { peg$reportedPos = s5; s6 = peg$c49(s9); s5 = s6; } else { peg$currPos = s5; s5 = peg$c0; } } else { peg$currPos = s5; s5 = peg$c0; } } else { peg$currPos = s5; s5 = peg$c0; } } else { peg$currPos = s5; s5 = peg$c0; } } if (s4 !== peg$FAILED) { s5 = peg$parse_(); if (s5 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { s6 = peg$c50; peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c51); } } if (s6 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c52(s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } return s0; } function peg$parseref() { var s0, s1, s2, s3, s4; peg$silentFails++; s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; s2 = peg$parsereserved(); peg$silentFails--; if (s2 === peg$FAILED) { s1 = peg$c54; } else { peg$currPos = s1; s1 = peg$c0; } if (s1 !== peg$FAILED) { s2 = peg$parseref_start(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parseref_part(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parseref_part(); } if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c55(s2, s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } } else { peg$currPos = s0; s0 = peg$c0; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parsesingle_quote(); if (s1 !== peg$FAILED) { s2 = peg$parseref_start(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parseref_part(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parseref_part(); } if (s3 !== peg$FAILED) { s4 = peg$parsesingle_quote(); if (s4 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c55(s2, s3); s0 = s1; } else { peg$currPos = s