UNPKG

node-sqlparser

Version:

a sql parser for node.js

1,706 lines (1,617 loc) 221 kB
/* * Generated by PEG.js 0.10.0. * * http://pegjs.org/ */ "use strict"; function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function peg$SyntaxError(message, expected, found, location) { this.message = message; this.expected = expected; this.found = found; this.location = location; this.name = "SyntaxError"; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, peg$SyntaxError); } } peg$subclass(peg$SyntaxError, Error); peg$SyntaxError.buildMessage = function(expected, found) { var DESCRIBE_EXPECTATION_FNS = { literal: function(expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, "class": function(expectation) { var escapedParts = "", i; for (i = 0; i < expectation.parts.length; i++) { escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]); } return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; }, any: function(expectation) { return "any character"; }, end: function(expectation) { return "end of input"; }, other: function(expectation) { return expectation.description; } }; function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } function literalEscape(s) { return s .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\0/g, '\\0') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function classEscape(s) { return s .replace(/\\/g, '\\\\') .replace(/\]/g, '\\]') .replace(/\^/g, '\\^') .replace(/-/g, '\\-') .replace(/\0/g, '\\0') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function describeExpectation(expectation) { return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); } function describeExpected(expected) { var descriptions = new Array(expected.length), i, j; for (i = 0; i < expected.length; i++) { descriptions[i] = describeExpectation(expected[i]); } descriptions.sort(); if (descriptions.length > 0) { for (i = 1, j = 1; i < descriptions.length; i++) { if (descriptions[i - 1] !== descriptions[i]) { descriptions[j] = descriptions[i]; j++; } } descriptions.length = j; } switch (descriptions.length) { case 1: return descriptions[0]; case 2: return descriptions[0] + " or " + descriptions[1]; default: return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1]; } } function describeFound(found) { return found ? "\"" + literalEscape(found) + "\"" : "end of input"; } return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; }; function peg$parse(input, options) { options = options !== void 0 ? options : {}; var peg$FAILED = {}, peg$startRuleFunctions = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = function(ast) { ast.params = params; return ast; }, peg$c1 = function(ast) { return ast; }, peg$c2 = function(head, tail) { var cur = head; for (var i = 0; i < tail.length; i++) { cur._next = tail[i][3]; cur = cur._next } return head; }, peg$c3 = "(", peg$c4 = peg$literalExpectation("(", false), peg$c5 = ")", peg$c6 = peg$literalExpectation(")", false), peg$c7 = ";", peg$c8 = peg$literalExpectation(";", false), peg$c9 = function(tb, clist, topt, popt) { return { type: 'create_table', name: tb, columns: clist, tableOptions: topt, partitionOptions: popt } }, peg$c10 = function(h, t) { return createList(h, t); }, peg$c11 = function(n, t, e) { let ext = []; e.forEach((v) => { ext.push(v[1]); }); return { name: n, type: t, ext: ext } }, peg$c12 = function(ct) { if (ct.type === 'function') { let args = []; ct.args.value.forEach((v) => { args.push(v.value); }); return { type: ct.name, args: args } } else { return {type: ct} } }, peg$c13 = function(h, t) { let res = h; t.forEach((v) => { let tmp = v[1]; let keys = Object.keys(tmp) keys.forEach((k) => { res[k] = tmp[k].column; }); }); return res; }, peg$c14 = "=", peg$c15 = peg$literalExpectation("=", false), peg$c16 = function(k, v) { let obj = {}; let key = k.type === 'column_ref' ? k.column : k.value; let value = v.type === 'column_ref' ? v.column : v.value; obj[key] = value; return obj; }, peg$c17 = function(h, t) { let res = [h]; t.forEach((v) => { res.push(v); }); return res; }, peg$c18 = "key", peg$c19 = peg$literalExpectation("KEY", true), peg$c20 = "index", peg$c21 = peg$literalExpectation("INDEX", true), peg$c22 = function(f, n, l) { let list = []; l.forEach((v) => { list.push(v.expr.column) }); return { type: f, name: n, columns: list } }, peg$c23 = function(f, w) { return { type: 'delete', from: f, where: w } }, peg$c24 = function(s) { return s[2]; }, peg$c25 = function(d, c, f, w, g, o, l) { return { type : 'select', distinct : d, columns : c, from : f, where : w, groupby : g, orderby : o, limit : l } }, peg$c26 = peg$otherExpectation("column_clause"), peg$c27 = function() { return '*'; }, peg$c28 = function(head, tail) { return createList(head, tail); }, peg$c29 = function(e, alias) { return { expr : e, as : alias }; }, peg$c30 = function(i) { return i; }, peg$c31 = function(l) { return l; }, peg$c32 = function(head, tail) { tail.unshift(head); return tail; }, peg$c33 = function(t) { return t; }, peg$c34 = function(op, t, expr) { t.join = op; t.on = expr; return t; /* return { db : t.db, table : t.table, as : t.as, join : op, on : expr } */ }, peg$c35 = function(t, alias) { if (t.type == 'var') { t.as = alias; return t; } else { return { db : t.db, table : t.table, as : alias } } }, peg$c36 = function() { return 'LEFT JOIN'; }, peg$c37 = function() { return 'INNER JOIN'; }, peg$c38 = "`", peg$c39 = peg$literalExpectation("`", false), peg$c40 = function(dt, tail) { var obj = { db : '', table : dt } if (tail) { obj.db = dt; obj.table = tail[3]; } return obj; }, peg$c41 = function(v) { v.db = ''; v.table = v.name; return v; }, peg$c42 = function(e) { return e; }, peg$c43 = function(e, d) { var obj = { expr : e, type : 'ASC' } if (d == 'DESC') { obj.type = 'DESC'; } return obj; }, peg$c44 = function(i1, tail) { var res = [i1]; if (!tail) { res.unshift({ type : 'number', value : 0 }); } else { res.push(tail[2]); } return res; }, peg$c45 = function(t, l, w) { return { type : 'update', db : t.db, table : t.table, set : l, where : w } }, peg$c46 = function(c, v) { return { column: c, value : v } }, peg$c47 = function(ri, t, c, v) { return { type : ri, db : t.db, table : t.table, columns : c, values : v } }, peg$c48 = function() { return 'insert'; }, peg$c49 = function() { return 'replace' }, peg$c50 = function(l) { return l; }, peg$c51 = function(head, tail) { var el = { type : 'expr_list' } var l = createExprList(head, tail, el); el.value = l; return el; }, peg$c52 = "", peg$c53 = function() { return { type : 'expr_list', value : [] } }, peg$c54 = function(head, tail) { return createBinaryExprChain(head, tail); }, peg$c55 = "!", peg$c56 = peg$literalExpectation("!", false), peg$c57 = function(expr) { return createUnaryExpr('NOT', expr); }, peg$c58 = function(left, rh) { if (!rh) { return left; } else { var res = null; if (rh.type == 'arithmetic') { res = createBinaryExprChain(left, rh.tail); } else { res = createBinaryExpr(rh.op, left, rh.right); } return res; } }, peg$c59 = function(l) { return { type : 'arithmetic', tail : l } }, peg$c60 = ">=", peg$c61 = peg$literalExpectation(">=", false), peg$c62 = ">", peg$c63 = peg$literalExpectation(">", false), peg$c64 = "<=", peg$c65 = peg$literalExpectation("<=", false), peg$c66 = "<>", peg$c67 = peg$literalExpectation("<>", false), peg$c68 = "<", peg$c69 = peg$literalExpectation("<", false), peg$c70 = "!=", peg$c71 = peg$literalExpectation("!=", false), peg$c72 = function(op, right) { return { op : op, right : right } }, peg$c73 = function(op, begin, end) { return { op : op, right : { type : 'expr_list', value : [begin, end] } } }, peg$c74 = function(nk) { return nk[0] + ' ' + nk[2]; }, peg$c75 = function(op, l) { return { op : op, right : l } }, peg$c76 = function(op, e) { return { op : op, right : e } }, peg$c77 = "+", peg$c78 = peg$literalExpectation("+", false), peg$c79 = "-", peg$c80 = peg$literalExpectation("-", false), peg$c81 = function(head, tail) { return createBinaryExprChain(head, tail) }, peg$c82 = "*", peg$c83 = peg$literalExpectation("*", false), peg$c84 = "/", peg$c85 = peg$literalExpectation("/", false), peg$c86 = "%", peg$c87 = peg$literalExpectation("%", false), peg$c88 = function(e) { e.paren = true; return e; }, peg$c89 = function(tbl, col) { return { type : 'column_ref', table : tbl, column : col }; }, peg$c90 = function(col) { return { type : 'column_ref', table : '', column: col }; }, peg$c91 = function(name) { return reservedMap[name.toUpperCase()] === true; }, peg$c92 = function(name) { return name; }, peg$c93 = /^[^`]/, peg$c94 = peg$classExpectation(["`"], true, false), peg$c95 = function(chars) { return chars.join(''); }, peg$c96 = function(start, parts) { return start + parts.join(''); }, peg$c97 = /^[A-Za-z_]/, peg$c98 = peg$classExpectation([["A", "Z"], ["a", "z"], "_"], false, false), peg$c99 = /^[A-Za-z0-9_]/, peg$c100 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_"], false, false), peg$c101 = /^[A-Za-z0-9_:]/, peg$c102 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", ":"], false, false), peg$c103 = peg$otherExpectation("PARAM[:param, ?]"), peg$c104 = ":", peg$c105 = peg$literalExpectation(":", false), peg$c106 = "?", peg$c107 = peg$literalExpectation("?", false), peg$c108 = function(l) { var p = { type : 'param', value: l.length > 1 ? l[1] : l[0] }; //var key = 'L' + line + 'C' + column; //debug(key); //params[key] = p; params.push(p); return p; }, peg$c109 = function(name, e) { return { type : 'aggr_func', name : name, args : { expr : e } } }, peg$c110 = /^[0-9a-zA-Z_]/, peg$c111 = peg$classExpectation([["0", "9"], ["a", "z"], ["A", "Z"], "_"], false, false), peg$c112 = function(w) {return w.join('');}, peg$c113 = function(name, arg) { return { type : 'aggr_func', name : name, args : arg } }, peg$c114 = function(e) { return { expr : e } }, peg$c115 = function(d, c) { return { distinct : d, expr : c } }, peg$c116 = function() { return { type : 'star', value : '*' } }, peg$c117 = function(name, l) { return { type : 'function', name : name, args : l } }, peg$c118 = function() { return { type : 'null', value : null }; }, peg$c119 = function() { return { type : 'bool', value : true }; }, peg$c120 = function() { return { type : 'bool', value : false }; }, peg$c121 = "\"", peg$c122 = peg$literalExpectation("\"", false), peg$c123 = "'", peg$c124 = peg$literalExpectation("'", false), peg$c125 = function(ca) { return { type : 'string', value : ca[1].join('') } }, peg$c126 = /^[^'\\\0-\x1F\x7F]/, peg$c127 = peg$classExpectation(["'", "\\", ["\0", "\x1F"], "\x7F"], true, false), peg$c128 = /^[^"\\\0-\x1F\x7F]/, peg$c129 = peg$classExpectation(["\"", "\\", ["\0", "\x1F"], "\x7F"], true, false), peg$c130 = "\\'", peg$c131 = peg$literalExpectation("\\'", false), peg$c132 = function() { return "'"; }, peg$c133 = "\\\"", peg$c134 = peg$literalExpectation("\\\"", false), peg$c135 = function() { return '"'; }, peg$c136 = "\\\\", peg$c137 = peg$literalExpectation("\\\\", false), peg$c138 = function() { return "\\"; }, peg$c139 = "\\/", peg$c140 = peg$literalExpectation("\\/", false), peg$c141 = function() { return "/"; }, peg$c142 = "\\b", peg$c143 = peg$literalExpectation("\\b", false), peg$c144 = function() { return "\b"; }, peg$c145 = "\\f", peg$c146 = peg$literalExpectation("\\f", false), peg$c147 = function() { return "\f"; }, peg$c148 = "\\n", peg$c149 = peg$literalExpectation("\\n", false), peg$c150 = function() { return "\n"; }, peg$c151 = "\\r", peg$c152 = peg$literalExpectation("\\r", false), peg$c153 = function() { return "\r"; }, peg$c154 = "\\t", peg$c155 = peg$literalExpectation("\\t", false), peg$c156 = function() { return "\t"; }, peg$c157 = "\\u", peg$c158 = peg$literalExpectation("\\u", false), peg$c159 = function(h1, h2, h3, h4) { return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4)); }, peg$c160 = /^[\n\r]/, peg$c161 = peg$classExpectation(["\n", "\r"], false, false), peg$c162 = function(n) { return { type : 'number', value : n } }, peg$c163 = peg$otherExpectation("LITERAL INT"), peg$c164 = function(n) { return { type: 'number', value: n } }, peg$c165 = function(int_, frac, exp) { var x = parseFloat(int_ + frac + exp); return (x % 1 != 0) ? x.toString() : x.toString() + ".0"}, peg$c166 = function(int_, frac) { var x = parseFloat(int_ + frac); return (x % 1 != 0) ? x.toString() : x.toString() + ".0"}, peg$c167 = function(int_, exp) { return parseFloat(int_ + exp).toString(); }, peg$c168 = function(int_) { return parseFloat(int_).toString(); }, peg$c169 = function(digit19, digits) { return digit19 + digits; }, peg$c170 = function(op, digit19, digits) { return "-" + digit19 + digits; }, peg$c171 = function(op, digit) { return "-" + digit; }, peg$c172 = ".", peg$c173 = peg$literalExpectation(".", false), peg$c174 = function(digits) { return "." + digits; }, peg$c175 = function(e, digits) { return e + digits; }, peg$c176 = function(digits) { return digits.join(""); }, peg$c177 = peg$otherExpectation("NUMBER"), peg$c178 = /^[0-9]/, peg$c179 = peg$classExpectation([["0", "9"]], false, false), peg$c180 = /^[1-9]/, peg$c181 = peg$classExpectation([["1", "9"]], false, false), peg$c182 = peg$otherExpectation("HEX"), peg$c183 = /^[0-9a-fA-F]/, peg$c184 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false), peg$c185 = /^[eE]/, peg$c186 = peg$classExpectation(["e", "E"], false, false), peg$c187 = /^[+\-]/, peg$c188 = peg$classExpectation(["+", "-"], false, false), peg$c189 = function(e, sign) { return e + sign; }, peg$c190 = "null", peg$c191 = peg$literalExpectation("NULL", true), peg$c192 = "true", peg$c193 = peg$literalExpectation("TRUE", true), peg$c194 = "false", peg$c195 = peg$literalExpectation("FALSE", true), peg$c196 = "show", peg$c197 = peg$literalExpectation("SHOW", true), peg$c198 = "drop", peg$c199 = peg$literalExpectation("DROP", true), peg$c200 = "select", peg$c201 = peg$literalExpectation("SELECT", true), peg$c202 = "update", peg$c203 = peg$literalExpectation("UPDATE", true), peg$c204 = "create", peg$c205 = peg$literalExpectation("CREATE", true), peg$c206 = "delete", peg$c207 = peg$literalExpectation("DELETE", true), peg$c208 = "insert", peg$c209 = peg$literalExpectation("INSERT", true), peg$c210 = "replace", peg$c211 = peg$literalExpectation("REPLACE", true), peg$c212 = "explain", peg$c213 = peg$literalExpectation("EXPLAIN", true), peg$c214 = "into", peg$c215 = peg$literalExpectation("INTO", true), peg$c216 = "from", peg$c217 = peg$literalExpectation("FROM", true), peg$c218 = "set", peg$c219 = peg$literalExpectation("SET", true), peg$c220 = "as", peg$c221 = peg$literalExpectation("AS", true), peg$c222 = "table", peg$c223 = peg$literalExpectation("TABLE", true), peg$c224 = "on", peg$c225 = peg$literalExpectation("ON", true), peg$c226 = "left", peg$c227 = peg$literalExpectation("LEFT", true), peg$c228 = "inner", peg$c229 = peg$literalExpectation("INNER", true), peg$c230 = "join", peg$c231 = peg$literalExpectation("JOIN", true), peg$c232 = "union", peg$c233 = peg$literalExpectation("UNION", true), peg$c234 = "values", peg$c235 = peg$literalExpectation("VALUES", true), peg$c236 = "if", peg$c237 = peg$literalExpectation("IF", true), peg$c238 = "exists", peg$c239 = peg$literalExpectation("EXISTS", true), peg$c240 = "where", peg$c241 = peg$literalExpectation("WHERE", true), peg$c242 = "group", peg$c243 = peg$literalExpectation("GROUP", true), peg$c244 = "by", peg$c245 = peg$literalExpectation("BY", true), peg$c246 = "order", peg$c247 = peg$literalExpectation("ORDER", true), peg$c248 = "having", peg$c249 = peg$literalExpectation("HAVING", true), peg$c250 = "limit", peg$c251 = peg$literalExpectation("LIMIT", true), peg$c252 = "asc", peg$c253 = peg$literalExpectation("ASC", true), peg$c254 = function() { return 'ASC'; }, peg$c255 = "desc", peg$c256 = peg$literalExpectation("DESC", true), peg$c257 = function() { return 'DESC'; }, peg$c258 = "all", peg$c259 = peg$literalExpectation("ALL", true), peg$c260 = function() { return 'ALL'; }, peg$c261 = "distinct", peg$c262 = peg$literalExpectation("DISTINCT", true), peg$c263 = function() { return 'DISTINCT';}, peg$c264 = "between", peg$c265 = peg$literalExpectation("BETWEEN", true), peg$c266 = function() { return 'BETWEEN'; }, peg$c267 = "in", peg$c268 = peg$literalExpectation("IN", true), peg$c269 = function() { return 'IN'; }, peg$c270 = "is", peg$c271 = peg$literalExpectation("IS", true), peg$c272 = function() { return 'IS'; }, peg$c273 = "like", peg$c274 = peg$literalExpectation("LIKE", true), peg$c275 = function() { return 'LIKE'; }, peg$c276 = "contains", peg$c277 = peg$literalExpectation("CONTAINS", true), peg$c278 = function() { return 'CONTAINS';}, peg$c279 = "not", peg$c280 = peg$literalExpectation("NOT", true), peg$c281 = function() { return 'NOT'; }, peg$c282 = "and", peg$c283 = peg$literalExpectation("AND", true), peg$c284 = function() { return 'AND'; }, peg$c285 = "or", peg$c286 = peg$literalExpectation("OR", true), peg$c287 = function() { return 'OR'; }, peg$c288 = "count", peg$c289 = peg$literalExpectation("COUNT", true), peg$c290 = function() { return 'COUNT'; }, peg$c291 = "max", peg$c292 = peg$literalExpectation("MAX", true), peg$c293 = function() { return 'MAX'; }, peg$c294 = "min", peg$c295 = peg$literalExpectation("MIN", true), peg$c296 = function() { return 'MIN'; }, peg$c297 = "sum", peg$c298 = peg$literalExpectation("SUM", true), peg$c299 = function() { return 'SUM'; }, peg$c300 = "avg", peg$c301 = peg$literalExpectation("AVG", true), peg$c302 = function() { return 'AVG'; }, peg$c303 = ",", peg$c304 = peg$literalExpectation(",", false), peg$c305 = "[", peg$c306 = peg$literalExpectation("[", false), peg$c307 = "]", peg$c308 = peg$literalExpectation("]", false), peg$c309 = peg$anyExpectation(), peg$c310 = peg$otherExpectation("WHITE_SPACE"), peg$c311 = /^[ \t\n\r]/, peg$c312 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false), peg$c313 = peg$otherExpectation("EOF"), peg$c314 = function(s) { return { stmt : s, vars: varList } }, peg$c315 = function() { varList = []; return true; }, peg$c316 = function(va, e) { return { type : 'assign', left : va, right: e } }, peg$c317 = function(e) { return { type : 'return', expr: e } }, peg$c318 = function(lt, op, rt, expr) { return { type : 'join', ltable : lt, rtable : rt, op : op, on : expr } }, peg$c319 = function(name, l) { //compatible with original func_call return { type : 'function', name : name, args : { type : 'expr_list', value : l } } }, peg$c320 = function(l) { return { type : 'array', value : l } }, peg$c321 = function(name, m) { //push for analysis varList.push(name); return { type : 'var', name : name, members : m } }, peg$c322 = function(l) { var s = []; for (var i = 0; i < l.length; i++) { s.push(l[i][1]); } return s; }, peg$c323 = "$", peg$c324 = peg$literalExpectation("$", false), peg$c325 = "return", peg$c326 = peg$literalExpectation("return", true), peg$c327 = ":=", peg$c328 = peg$literalExpectation(":=", false), peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], 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$savedPos, peg$currPos); } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildStructuredError( [peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location ); } function error(message, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildSimpleError(message, location); } function peg$literalExpectation(text, ignoreCase) { return { type: "literal", text: text, ignoreCase: ignoreCase }; } function peg$classExpectation(parts, inverted, ignoreCase) { return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; } function peg$anyExpectation() { return { type: "any" }; } function peg$endExpectation() { return { type: "end" }; } function peg$otherExpectation(description) { return { type: "other", description: description }; } function peg$computePosDetails(pos) { var details = peg$posDetailsCache[pos], p; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { line: details.line, column: details.column }; while (p < pos) { if (input.charCodeAt(p) === 10) { details.line++; details.column = 1; } else { details.column++; } p++; } peg$posDetailsCache[pos] = details; return details; } } function peg$computeLocation(startPos, endPos) { var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos); return { start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column } }; } 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$buildSimpleError(message, location) { return new peg$SyntaxError(message, null, null, location); } function peg$buildStructuredError(expected, found, location) { return new peg$SyntaxError( peg$SyntaxError.buildMessage(expected, found), expected, found, location ); } function peg$parsestart() { var s0, s1, s2; s0 = peg$currPos; s1 = peg$parse__(); if (s1 !== peg$FAILED) { s2 = peg$parseunion_stmt(); if (s2 === peg$FAILED) { s2 = peg$parseupdate_stmt(); if (s2 === peg$FAILED) { s2 = peg$parsedelete_stmt(); if (s2 === peg$FAILED) { s2 = peg$parsereplace_insert_stmt(); if (s2 === peg$FAILED) { s2 = peg$parsecreate_table_stmt(); } } } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c0(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parseproc_stmts(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c1(s1); } s0 = s1; } return s0; } function peg$parseunion_stmt() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$parseselect_stmt(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseKW_UNION(); if (s5 !== peg$FAILED) { s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parseselect_stmt(); if (s7 !== peg$FAILED) { s4 = [s4, s5, s6, s7]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseKW_UNION(); if (s5 !== peg$FAILED) { s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parseselect_stmt(); if (s7 !== peg$FAILED) { s4 = [s4, s5, s6, s7]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c2(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsecreate_table_stmt() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19; s0 = peg$currPos; s1 = peg$parseKW_CREATE(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseKW_TABLE(); if (s3 !== peg$FAILED) { s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$currPos; s6 = peg$parseKW_IF(); if (s6 !== peg$FAILED) { s7 = peg$parse__(); if (s7 !== peg$FAILED) { s8 = peg$parseKW_NOT(); if (s8 !== peg$FAILED) { s9 = peg$parse__(); if (s9 !== peg$FAILED) { s10 = peg$parseKW_EXISTS(); if (s10 !== peg$FAILED) { s11 = peg$parse__(); if (s11 !== peg$FAILED) { s6 = [s6, s7, s8, s9, s10, s11]; s5 = s6; } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } if (s5 === peg$FAILED) { s5 = null; } if (s5 !== peg$FAILED) { s6 = peg$parsetable_name(); if (s6 !== peg$FAILED) { s7 = peg$parse__(); if (s7 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { s8 = peg$c3; peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s8 !== peg$FAILED) { s9 = peg$parse__(); if (s9 !== peg$FAILED) { s10 = peg$parsecolumns_defs(); if (s10 !== peg$FAILED) { s11 = peg$parse__(); if (s11 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s12 = peg$c5; peg$currPos++; } else { s12 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c6); } } if (s12 !== peg$FAILED) { s13 = peg$parse__(); if (s13 !== peg$FAILED) { s14 = peg$parsetable_options(); if (s14 === peg$FAILED) { s14 = null; } if (s14 !== peg$FAILED) { s15 = peg$parse__(); if (s15 !== peg$FAILED) { s16 = peg$parsepartition_options(); if (s16 === peg$FAILED) { s16 = null; } if (s16 !== peg$FAILED) { s17 = peg$parse__(); if (s17 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 59) { s18 = peg$c7; peg$currPos++; } else { s18 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c8); } } if (s18 === peg$FAILED) { s18 = null; } if (s18 !== peg$FAILED) { s19 = peg$parse__(); if (s19 === peg$FAILED) { s19 = null; } if (s19 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c9(s6, s10, s14, s16); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsecolumns_defs() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$parsecolumn_def(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseCOMMA(); if (s5 !== peg$FAILED) { s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parsecolumn_def(); if (s7 !== peg$FAILED) { s4 = [s4, s5, s6, s7]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseCOMMA(); if (s5 !== peg$FAILED) { s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parsecolumn_def(); if (s7 !== peg$FAILED) { s4 = [s4, s5, s6, s7]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c10(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsecolumn_def() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$parseindex_def(); if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = peg$parsecolumn(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parsecolumn_type(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$currPos; s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parseliteral(); if (s7 === peg$FAILED) { s7 = peg$parseident_name(); } if (s7 !== peg$FAILED) { s6 = [s6, s7]; s5 = s6; } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$currPos; s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parseliteral(); if (s7 === peg$FAILED) { s7 = peg$parseident_name(); } if (s7 !== peg$FAILED) { s6 = [s6, s7]; s5 = s6; } else { peg$currPos = s5; s5 = peg$FAILED; } } else { peg$currPos = s5; s5 = peg$FAILED; } } if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c11(s1, s3, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } return s0; } function peg$parsecolumn_type() { var s0, s1; s0 = peg$currPos; s1 = peg$parsefunc_call(); if (s1 === peg$FAILED) { s1 = peg$parseident(); } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c12(s1); } s0 = s1; return s0; } function peg$parsetable_options() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parsetable_option(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parsetable_option(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parsetable_option(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c13(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsetable_option() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parseprimary(); if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 61) { s3 = peg$c14; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c15); } } if (s3 === peg$FAILED) { s3 = null; } if (s3 !== peg$FAILED) { s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseprimary(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c16(s1, s5); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsepartition_options() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parseprimary(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseprimary(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; s4 = peg$parse__(); if (s4 !== peg$FAILED) { s5 = peg$parseprimary(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } } if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c17(s1, s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseindex_def() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$currPos; s3 = []; s4 = peg$parseident_name(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parseident_name(); } if (s3 !== peg$FAILED) { s4 = peg$parse__(); if (s4 !== peg$FAILED) { if (input.substr(peg$currPos, 3).toLowerCase() === peg$c18) { s5 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c19); } } if (s5 === peg$FAILED) { if (input.substr(peg$currPos, 5).toLowerCase() === peg$c20) { s5 = input.substr(peg$currPos, 5); peg$currPos += 5; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } } if (s5 !== peg$FAILED) { s3 = [s3, s4, s5]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } } else {