librenms/html/js/sql-parser.min.js
Neil Lathwood 66a3f82269
Fix NOT REGEXP rules (#8376)
* Fix NOT REGEXP rules

* not_regex -> not regex

* Fixed saving rules as well
2018-03-14 21:53:47 +00:00

8 lines
29 KiB
JavaScript

/*!
* SQLParser 1.1.0
* Copyright 2012-2015 Andy Kent <andy@forward.co.uk>
* Copyright 2015-2016 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Licensed under MIT (http://opensource.org/licenses/MIT)
*/
!function(t){var e=function(){function t(e){return t[e]}return t["./lexer"]=new function(){var t=this;(function(){var e;e=function(){function t(t,e){var n,i;for(null==e&&(e={}),this.sql=t,this.preserveWhitespace=e.preserveWhitespace||!1,this.tokens=[],this.currentLine=1,i=0;this.chunk=t.slice(i);){if((n=this.keywordToken()||this.starToken()||this.booleanToken()||this.functionToken()||this.windowExtension()||this.sortOrderToken()||this.seperatorToken()||this.operatorToken()||this.mathToken()||this.dotToken()||this.conditionalToken()||this.betweenToken()||this.subSelectOpToken()||this.subSelectUnaryOpToken()||this.numberToken()||this.stringToken()||this.parameterToken()||this.parensToken()||this.whitespaceToken()||this.literalToken())<1)throw new Error("NOTHING CONSUMED: Stopped at - '"+this.chunk.slice(0,30)+"'");i+=n}this.token("EOF",""),this.postProcess()}var e,n,i,r,o,s,u,a,h,c,l,p,f,k,T,E,g,S;return t.prototype.postProcess=function(){var t,e,n,i,r,o,s;for(o=this.tokens,s=[],t=i=0,r=o.length;i<r;t=++i)n=o[t],"STAR"===n[0]?(e=this.tokens[t+1],"SEPARATOR"!==e[0]&&"FROM"!==e[0]?s.push(n[0]="MATH_MULTI"):s.push(void 0)):s.push(void 0);return s},t.prototype.token=function(t,e){return this.tokens.push([t,e,this.currentLine])},t.prototype.tokenizeFromStringRegex=function(t,e,n,i,r){var o,s;return null==n&&(n=0),null==i&&(i=n),null==r&&(r=!0),(o=e.exec(this.chunk))?(s=o[n].replace(/''/g,"'"),r&&this.token(t,s),o[i].length):0},t.prototype.tokenizeFromRegex=function(t,e,n,i,r){var o,s;return null==n&&(n=0),null==i&&(i=n),null==r&&(r=!0),(o=e.exec(this.chunk))?(s=o[n],r&&this.token(t,s),o[i].length):0},t.prototype.tokenizeFromWord=function(t,e){var n,i;return null==e&&(e=t),e=this.regexEscape(e),i=/^\w+$/.test(e)?new RegExp("^("+e+")\\b","ig"):new RegExp("^("+e+")","ig"),(n=i.exec(this.chunk))?(this.token(t,n[1]),n[1].length):0},t.prototype.tokenizeFromList=function(t,e){var n,i,r,o;for(i=0,r=0,o=e.length;r<o&&(n=e[r],!((i=this.tokenizeFromWord(t,n))>0));r++);return i},t.prototype.keywordToken=function(){return this.tokenizeFromWord("SELECT")||this.tokenizeFromWord("INSERT")||this.tokenizeFromWord("INTO")||this.tokenizeFromWord("DEFAULT")||this.tokenizeFromWord("VALUES")||this.tokenizeFromWord("DISTINCT")||this.tokenizeFromWord("FROM")||this.tokenizeFromWord("WHERE")||this.tokenizeFromWord("GROUP")||this.tokenizeFromWord("ORDER")||this.tokenizeFromWord("BY")||this.tokenizeFromWord("HAVING")||this.tokenizeFromWord("LIMIT")||this.tokenizeFromWord("JOIN")||this.tokenizeFromWord("LEFT")||this.tokenizeFromWord("RIGHT")||this.tokenizeFromWord("INNER")||this.tokenizeFromWord("OUTER")||this.tokenizeFromWord("ON")||this.tokenizeFromWord("AS")||this.tokenizeFromWord("UNION")||this.tokenizeFromWord("ALL")||this.tokenizeFromWord("LIMIT")||this.tokenizeFromWord("OFFSET")||this.tokenizeFromWord("FETCH")||this.tokenizeFromWord("ROW")||this.tokenizeFromWord("ROWS")||this.tokenizeFromWord("ONLY")||this.tokenizeFromWord("NEXT")||this.tokenizeFromWord("FIRST")},t.prototype.dotToken=function(){return this.tokenizeFromWord("DOT",".")},t.prototype.operatorToken=function(){return this.tokenizeFromList("OPERATOR",p)},t.prototype.mathToken=function(){return this.tokenizeFromList("MATH",r)||this.tokenizeFromList("MATH_MULTI",o)},t.prototype.conditionalToken=function(){return this.tokenizeFromList("CONDITIONAL",c)},t.prototype.betweenToken=function(){return this.tokenizeFromList("BETWEEN",h)},t.prototype.subSelectOpToken=function(){return this.tokenizeFromList("SUB_SELECT_OP",E)},t.prototype.subSelectUnaryOpToken=function(){return this.tokenizeFromList("SUB_SELECT_UNARY_OP",g)},t.prototype.functionToken=function(){return this.tokenizeFromList("FUNCTION",l)},t.prototype.sortOrderToken=function(){return this.tokenizeFromList("DIRECTION",f)},t.prototype.booleanToken=function(){return this.tokenizeFromList("BOOLEAN",e)},t.prototype.starToken=function(){return this.tokenizeFromRegex("STAR",k)},t.prototype.seperatorToken=function(){return this.tokenizeFromRegex("SEPARATOR",a)},t.prototype.literalToken=function(){return this.tokenizeFromRegex("LITERAL",i,1,0)},t.prototype.numberToken=function(){return this.tokenizeFromRegex("NUMBER",s)},t.prototype.parameterToken=function(){return this.tokenizeFromRegex("PARAMETER",u,1,0)},t.prototype.stringToken=function(){return this.tokenizeFromStringRegex("STRING",T,1,0)||this.tokenizeFromRegex("DBLSTRING",n,1,0)},t.prototype.parensToken=function(){return this.tokenizeFromRegex("LEFT_PAREN",/^\(/)||this.tokenizeFromRegex("RIGHT_PAREN",/^\)/)},t.prototype.windowExtension=function(){var t;return(t=/^\.(win):(length|time)/i.exec(this.chunk))?(this.token("WINDOW",t[1]),this.token("WINDOW_FUNCTION",t[2]),t[0].length):0},t.prototype.whitespaceToken=function(){var t,e,n;return(t=S.exec(this.chunk))?(n=t[0],this.preserveWhitespace&&this.token("WHITESPACE",n),e=n.match(/\n/g,""),this.currentLine+=(null!=e?e.length:void 0)||0,n.length):0},t.prototype.regexEscape=function(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")},l=["AVG","COUNT","MIN","MAX","SUM"],f=["ASC","DESC"],p=["=","!=",">=",">","<=","<>","<","LIKE","NOT LIKE","IS NOT","IS","REGEXP", "NOT REGEXP"],E=["IN","NOT IN","ANY","ALL","SOME"],g=["EXISTS"],c=["AND","OR"],h=["BETWEEN","NOT BETWEEN"],e=["TRUE","FALSE","NULL"],r=["+","-","||","&&"],o=["/","*"],k=/^\*/,a=/^,/,S=/^[ \n\r]+/,i=/^`?([a-z_][a-z0-9_]{0,}(\:(number|float|string|date|boolean))?)`?/i,u=/^\$([a-z0-9_]+(\:(number|float|string|date|boolean))?)/,s=/^[0-9]+(\.[0-9]+)?/,T=/^'((?:[^\\']+?|\\.|'')*)'(?!')/,n=/^"([^\\"]*(?:\\.[^\\"]*)*)"/,t}(),t.tokenize=function(t,n){return new e(t,n).tokens}}).call(this)},t["./compiled_parser"]=new function(){var e=this,n=function(){function t(){this.yy={}}var e=function(t,e,n,i){for(n=n||{},i=t.length;i--;n[t[i]]=e);return n},n=[1,8],i=[5,26],r=[1,14],o=[1,13],s=[5,26,31,42],u=[1,17],a=[5,26,31,42,45,62],h=[1,27],c=[1,29],l=[1,40],p=[1,44],f=[1,45],k=[1,41],T=[1,42],E=[1,39],g=[1,43],S=[1,25],m=[5,26,31],O=[5,26,31,42,45],y=[1,57],d=[18,43],R=[1,60],N=[1,61],F=[1,62],b=[1,63],L=[1,64],w=[5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,66,67,68,70],I=[5,18,23,26,31,34,37,38,41,42,43,44,45,51,62,64,65,66,67,68,70,71,80,81,82,83,84,85,87],v=[1,72],A=[2,86],$=[1,86],W=[1,87],z=[5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,66,67,68,70,80,81,82,83,84,85,87],U=[1,105],_=[5,26,31,42,43,44],C=[1,113],P=[5,26,31,42,43,45,64],x=[5,26,31,41,42,45,62],B=[1,116],H=[1,117],M=[1,118],D=[5,26,31,34,35,37,38,41,42,45,62],G=[5,18,23,26,31,34,37,38,41,42,43,45,62,64,70],V=[5,26,31,34,37,38,41,42,45,62],j=[5,26,31,42,56,58],J={trace:function(){},yy:{},symbols_:{error:2,Root:3,Query:4,EOF:5,SelectQuery:6,Unions:7,SelectWithLimitQuery:8,BasicSelectQuery:9,Select:10,OrderClause:11,GroupClause:12,LimitClause:13,SelectClause:14,WhereClause:15,SELECT:16,Fields:17,FROM:18,Table:19,DISTINCT:20,Joins:21,Literal:22,AS:23,LEFT_PAREN:24,List:25,RIGHT_PAREN:26,WINDOW:27,WINDOW_FUNCTION:28,Number:29,Union:30,UNION:31,ALL:32,Join:33,JOIN:34,ON:35,Expression:36,LEFT:37,RIGHT:38,INNER:39,OUTER:40,WHERE:41,LIMIT:42,SEPARATOR:43,OFFSET:44,ORDER:45,BY:46,OrderArgs:47,OffsetClause:48,OrderArg:49,Value:50,DIRECTION:51,OffsetRows:52,FetchClause:53,ROW:54,ROWS:55,FETCH:56,FIRST:57,ONLY:58,NEXT:59,GroupBasicClause:60,HavingClause:61,GROUP:62,ArgumentList:63,HAVING:64,MATH:65,MATH_MULTI:66,OPERATOR:67,BETWEEN:68,BetweenExpression:69,CONDITIONAL:70,SUB_SELECT_OP:71,SubSelectExpression:72,SUB_SELECT_UNARY_OP:73,WhitepaceList:74,String:75,Function:76,UserFunction:77,Boolean:78,Parameter:79,NUMBER:80,BOOLEAN:81,PARAMETER:82,STRING:83,DBLSTRING:84,LITERAL:85,DOT:86,FUNCTION:87,AggregateArgumentList:88,Field:89,STAR:90,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",16:"SELECT",18:"FROM",20:"DISTINCT",23:"AS",24:"LEFT_PAREN",26:"RIGHT_PAREN",27:"WINDOW",28:"WINDOW_FUNCTION",31:"UNION",32:"ALL",34:"JOIN",35:"ON",37:"LEFT",38:"RIGHT",39:"INNER",40:"OUTER",41:"WHERE",42:"LIMIT",43:"SEPARATOR",44:"OFFSET",45:"ORDER",46:"BY",51:"DIRECTION",54:"ROW",55:"ROWS",56:"FETCH",57:"FIRST",58:"ONLY",59:"NEXT",62:"GROUP",64:"HAVING",65:"MATH",66:"MATH_MULTI",67:"OPERATOR",68:"BETWEEN",70:"CONDITIONAL",71:"SUB_SELECT_OP",73:"SUB_SELECT_UNARY_OP",80:"NUMBER",81:"BOOLEAN",82:"PARAMETER",83:"STRING",84:"DBLSTRING",85:"LITERAL",86:"DOT",87:"FUNCTION",90:"STAR"},productions_:[0,[3,2],[4,1],[4,2],[6,1],[6,1],[9,1],[9,2],[9,2],[9,3],[8,2],[10,1],[10,2],[14,4],[14,5],[14,5],[14,6],[19,1],[19,2],[19,3],[19,3],[19,3],[19,4],[19,6],[7,1],[7,2],[30,2],[30,3],[21,1],[21,2],[33,4],[33,5],[33,5],[33,6],[33,6],[33,6],[33,6],[15,2],[13,2],[13,4],[13,4],[11,3],[11,4],[47,1],[47,3],[49,1],[49,2],[48,2],[48,3],[52,2],[52,2],[53,4],[53,4],[12,1],[12,2],[60,3],[61,2],[36,3],[36,3],[36,3],[36,3],[36,3],[36,3],[36,5],[36,3],[36,2],[36,1],[36,1],[36,1],[69,3],[72,3],[50,1],[50,1],[50,1],[50,1],[50,1],[50,1],[50,1],[74,2],[74,2],[25,1],[29,1],[78,1],[79,1],[75,1],[75,1],[22,1],[22,3],[76,4],[77,3],[77,4],[88,1],[88,2],[63,1],[63,3],[17,1],[17,3],[89,1],[89,1],[89,3]],performAction:function(t,e,n,i,r,o,s){var u=o.length-1;switch(r){case 1:return this.$=o[u-1];case 2:case 4:case 5:case 6:case 11:case 53:case 66:case 68:case 71:case 72:case 73:case 74:case 75:case 76:case 77:this.$=o[u];break;case 3:this.$=function(){return o[u-1].unions=o[u],o[u-1]}();break;case 7:this.$=function(){return o[u-1].order=o[u],o[u-1]}();break;case 8:this.$=function(){return o[u-1].group=o[u],o[u-1]}();break;case 9:this.$=function(){return o[u-2].group=o[u-1],o[u-2].order=o[u],o[u-2]}();break;case 10:this.$=function(){return o[u-1].limit=o[u],o[u-1]}();break;case 12:this.$=function(){return o[u-1].where=o[u],o[u-1]}();break;case 13:this.$=new i.Select(o[u-2],o[u],!1);break;case 14:this.$=new i.Select(o[u-2],o[u],!0);break;case 15:this.$=new i.Select(o[u-3],o[u-1],!1,o[u]);break;case 16:this.$=new i.Select(o[u-3],o[u-1],!0,o[u]);break;case 17:this.$=new i.Table(o[u]);break;case 18:this.$=new i.Table(o[u-1],o[u]);break;case 19:this.$=new i.Table(o[u-2],o[u]);break;case 20:case 49:case 50:case 51:case 52:case 57:this.$=o[u-1];break;case 21:case 70:this.$=new i.SubSelect(o[u-1]);break;case 22:this.$=new i.SubSelect(o[u-2],o[u]);break;case 23:this.$=new i.Table(o[u-5],null,o[u-4],o[u-3],o[u-1]);break;case 24:case 28:case 43:case 93:case 95:this.$=[o[u]];break;case 25:this.$=o[u-1].concat(o[$01]);break;case 26:this.$=new i.Union(o[u]);break;case 27:this.$=new i.Union(o[u],!0);break;case 29:this.$=o[u-1].concat(o[u]);break;case 30:this.$=new i.Join(o[u-2],o[u]);break;case 31:this.$=new i.Join(o[u-2],o[u],"LEFT");break;case 32:this.$=new i.Join(o[u-2],o[u],"RIGHT");break;case 33:this.$=new i.Join(o[u-2],o[u],"LEFT","INNER");break;case 34:this.$=new i.Join(o[u-2],o[u],"RIGHT","INNER");break;case 35:this.$=new i.Join(o[u-2],o[u],"LEFT","OUTER");break;case 36:this.$=new i.Join(o[u-2],o[u],"RIGHT","OUTER");break;case 37:this.$=new i.Where(o[u]);break;case 38:this.$=new i.Limit(o[u]);break;case 39:this.$=new i.Limit(o[u],o[u-2]);break;case 40:this.$=new i.Limit(o[u-2],o[u]);break;case 41:this.$=new i.Order(o[u]);break;case 42:this.$=new i.Order(o[u-1],o[u]);break;case 44:case 94:case 96:this.$=o[u-2].concat(o[u]);break;case 45:this.$=new i.OrderArgument(o[u],"ASC");break;case 46:this.$=new i.OrderArgument(o[u-1],o[u]);break;case 47:this.$=new i.Offset(o[u]);break;case 48:this.$=new i.Offset(o[u-1],o[u]);break;case 54:this.$=function(){return o[u-1].having=o[u],o[u-1]}();break;case 55:this.$=new i.Group(o[u]);break;case 56:this.$=new i.Having(o[u]);break;case 58:case 59:case 60:case 61:case 62:case 64:this.$=new i.Op(o[u-1],o[u-2],o[u]);break;case 63:this.$=new i.Op(o[u-3],o[u-4],o[u-1]);break;case 65:this.$=new i.UnaryOp(o[u-1],o[u]);break;case 67:this.$=new i.WhitepaceList(o[u]);break;case 69:this.$=new i.BetweenOp([o[u-2],o[u]]);break;case 78:this.$=[o[u-1],o[u]];break;case 79:this.$=function(){return o[u-1].push(o[u]),o[u-1]}();break;case 80:this.$=new i.ListValue(o[u]);break;case 81:this.$=new i.NumberValue(o[u]);break;case 82:this.$=new i.BooleanValue(o[u]);break;case 83:this.$=new i.ParameterValue(o[u]);break;case 84:this.$=new i.StringValue(o[u],"'");break;case 85:this.$=new i.StringValue(o[u],'"');break;case 86:this.$=new i.LiteralValue(o[u]);break;case 87:this.$=new i.LiteralValue(o[u-2],o[u]);break;case 88:this.$=new i.FunctionValue(o[u-3],o[u-1]);break;case 89:this.$=new i.FunctionValue(o[u-2],null,!0);break;case 90:this.$=new i.FunctionValue(o[u-3],o[u-1],!0);break;case 91:this.$=new i.ArgumentListValue(o[u]);break;case 92:this.$=new i.ArgumentListValue(o[u],!0);break;case 97:this.$=new i.Star;break;case 98:this.$=new i.Field(o[u]);break;case 99:this.$=new i.Field(o[u-2],o[u])}},table:[{3:1,4:2,6:3,8:4,9:5,10:6,14:7,16:n},{1:[3]},{5:[1,9]},e(i,[2,2],{7:10,13:11,30:12,31:r,42:o}),e(s,[2,4]),e(s,[2,5]),e(s,[2,6],{11:15,12:16,60:18,45:u,62:[1,19]}),e(a,[2,11],{15:20,41:[1,21]}),{17:22,20:[1,23],22:32,24:h,29:33,36:26,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g,89:24,90:S},{1:[2,1]},e(i,[2,3],{30:46,31:r}),e(s,[2,10]),e(m,[2,24]),{29:47,80:l},{6:48,8:4,9:5,10:6,14:7,16:n,32:[1,49]},e(s,[2,7]),e(s,[2,8],{11:50,45:u}),{46:[1,51]},e(O,[2,53],{61:52,64:[1,53]}),{46:[1,54]},e(a,[2,12]),{22:32,24:h,29:33,36:55,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{18:[1,56],43:y},{17:58,22:32,24:h,29:33,36:26,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g,89:24,90:S},e(d,[2,95]),e(d,[2,97]),e(d,[2,98],{23:[1,59],65:R,66:N,67:F,68:b,70:L}),{4:66,6:3,8:4,9:5,10:6,14:7,16:n,22:32,24:h,29:33,36:65,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(w,[2,68],{22:32,29:33,75:34,76:35,77:36,78:37,79:38,50:68,71:[1,67],80:l,81:p,82:f,83:k,84:T,85:E,87:g}),{24:[1,70],72:69},e(w,[2,66]),e(w,[2,67],{22:32,29:33,75:34,76:35,77:36,78:37,79:38,50:71,80:l,81:p,82:f,83:k,84:T,85:E,87:g}),e(I,[2,71],{86:v}),e(I,[2,72]),e(I,[2,73]),e(I,[2,74]),e(I,[2,75]),e(I,[2,76]),e(I,[2,77]),e([5,18,23,26,31,34,37,38,41,42,43,44,45,51,62,64,65,66,67,68,70,71,80,81,82,83,84,85,86,87],A,{24:[1,73]}),e([5,18,23,26,31,34,37,38,41,42,43,44,45,51,54,55,62,64,65,66,67,68,70,71,80,81,82,83,84,85,87],[2,81]),e(I,[2,84]),e(I,[2,85]),{24:[1,74]},e(I,[2,82]),e(I,[2,83]),e(m,[2,25]),e(s,[2,38],{43:[1,75],44:[1,76]}),e(m,[2,26],{13:11,42:o}),{6:77,8:4,9:5,10:6,14:7,16:n},e(s,[2,9]),{22:32,29:33,47:78,49:79,50:80,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(O,[2,54]),{22:32,24:h,29:33,36:81,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:83,50:28,63:82,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(a,[2,37],{65:R,66:N,67:F,68:b,70:L}),{19:84,22:85,24:$,85:W},{22:32,24:h,29:33,36:26,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g,89:88,90:S},{18:[1,89],43:y},{22:90,85:W},{22:32,24:h,29:33,36:91,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:92,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:93,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:95,50:28,69:94,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:96,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{26:[1,97],65:R,66:N,67:F,68:b,70:L},{26:[1,98]},{24:[1,99],72:100},e(z,[2,78]),e(w,[2,65]),{4:66,6:3,8:4,9:5,10:6,14:7,16:n},e(z,[2,79]),{85:[1,101]},{20:U,22:32,24:h,26:[1,102],29:33,36:83,50:28,63:104,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g,88:103},{20:U,22:32,24:h,29:33,36:83,50:28,63:104,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g,88:106},{29:107,80:l},{29:108,80:l},e(m,[2,27],{13:11,42:o}),e(s,[2,41],{48:109,43:[1,110],44:[1,111]}),e(_,[2,43]),e(_,[2,45],{51:[1,112]}),e(O,[2,56],{65:R,66:N,67:F,68:b,70:L}),e([5,26,31,42,45,64],[2,55],{43:C}),e(P,[2,93],{65:R,66:N,67:F,68:b,70:L}),e(x,[2,13],{21:114,33:115,34:B,37:H,38:M}),e(D,[2,17],{22:119,23:[1,120],27:[1,121],85:W,86:v}),{4:123,6:3,8:4,9:5,10:6,14:7,16:n,22:32,24:h,25:122,29:33,36:83,50:28,63:124,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e([5,18,23,26,27,31,34,35,37,38,41,42,43,45,62,85,86],A),e(d,[2,96]),{19:125,22:85,24:$,85:W},e(d,[2,99],{86:v}),e([5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,67,70],[2,58],{66:N,68:b}),e([5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,66,67,70],[2,59],{68:b}),e([5,18,23,26,31,34,37,38,41,42,43,45,62,64,67,70],[2,60],{65:R,66:N,68:b}),e(w,[2,61]),{65:R,66:N,67:F,68:b,70:[1,126]},e(G,[2,62],{65:R,66:N,67:F,68:b}),e(w,[2,57]),e(w,[2,70]),{4:66,6:3,8:4,9:5,10:6,14:7,16:n,22:32,24:h,25:127,29:33,36:83,50:28,63:124,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(w,[2,64]),e([5,18,23,26,27,31,34,35,37,38,41,42,43,44,45,51,62,64,65,66,67,68,70,71,80,81,82,83,84,85,86,87],[2,87]),e(I,[2,89]),{26:[1,128]},{26:[2,91],43:C},{22:32,24:h,29:33,36:83,50:28,63:129,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{26:[1,130]},e(s,[2,39]),e(s,[2,40]),e(s,[2,42]),{22:32,29:33,49:131,50:80,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{29:133,52:132,80:l},e(_,[2,46]),{22:32,24:h,29:33,36:134,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(x,[2,15],{33:135,34:B,37:H,38:M}),e(V,[2,28]),{19:136,22:85,24:$,85:W},{34:[1,137],39:[1,138],40:[1,139]},{34:[1,140],39:[1,141],40:[1,142]},e(D,[2,18],{86:v}),{22:143,85:W},{28:[1,144]},{26:[1,145]},{26:[1,146]},{26:[2,80],43:C},e(x,[2,14],{33:115,21:147,34:B,37:H,38:M}),{22:32,24:h,29:33,36:148,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{26:[1,149]},e(I,[2,90]),{26:[2,92],43:C},e(I,[2,88]),e(_,[2,44]),e(s,[2,47],{53:150,56:[1,151]}),{54:[1,152],55:[1,153]},e(P,[2,94],{65:R,66:N,67:F,68:b,70:L}),e(V,[2,29]),{35:[1,154]},{19:155,22:85,24:$,85:W},{34:[1,156]},{34:[1,157]},{19:158,22:85,24:$,85:W},{34:[1,159]},{34:[1,160]},e(D,[2,19],{86:v}),{24:[1,161]},e(D,[2,20]),e(D,[2,21],{22:162,85:W}),e(x,[2,16],{33:135,34:B,37:H,38:M}),e(G,[2,69],{65:R,66:N,67:F,68:b}),e(w,[2,63]),e(s,[2,48]),{57:[1,163],59:[1,164]},e(j,[2,49]),e(j,[2,50]),{22:32,24:h,29:33,36:165,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{35:[1,166]},{19:167,22:85,24:$,85:W},{19:168,22:85,24:$,85:W},{35:[1,169]},{19:170,22:85,24:$,85:W},{19:171,22:85,24:$,85:W},{29:172,80:l},e(D,[2,22],{86:v}),{29:133,52:173,80:l},{29:133,52:174,80:l},e(V,[2,30],{65:R,66:N,67:F,68:b,70:L}),{22:32,24:h,29:33,36:175,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{35:[1,176]},{35:[1,177]},{22:32,24:h,29:33,36:178,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{35:[1,179]},{35:[1,180]},{26:[1,181]},{58:[1,182]},{58:[1,183]},e(V,[2,31],{65:R,66:N,67:F,68:b,70:L}),{22:32,24:h,29:33,36:184,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:185,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(V,[2,32],{65:R,66:N,67:F,68:b,70:L}),{22:32,24:h,29:33,36:186,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},{22:32,24:h,29:33,36:187,50:28,72:30,73:c,74:31,75:34,76:35,77:36,78:37,79:38,80:l,81:p,82:f,83:k,84:T,85:E,87:g},e(D,[2,23]),e(s,[2,51]),e(s,[2,52]),e(V,[2,33],{65:R,66:N,67:F,68:b,70:L}),e(V,[2,35],{65:R,66:N,67:F,68:b,70:L}),e(V,[2,34],{65:R,66:N,67:F,68:b,70:L}),e(V,[2,36],{65:R,66:N,67:F,68:b,70:L})],defaultActions:{9:[2,1]},parseError:function(t,e){if(!e.recoverable)throw new Error(t);this.trace(t)},parse:function(t){function e(){var t;return t=f.lex()||l,"number"!=typeof t&&(t=n.symbols_[t]||t),t}var n=this,i=[0],r=[null],o=[],s=this.table,u="",a=0,h=0,c=0,l=1,p=o.slice.call(arguments,1),f=Object.create(this.lexer),k={yy:{}};for(var T in this.yy)Object.prototype.hasOwnProperty.call(this.yy,T)&&(k.yy[T]=this.yy[T]);f.setInput(t,k.yy),k.yy.lexer=f,k.yy.parser=this,void 0===f.yylloc&&(f.yylloc={});var E=f.yylloc;o.push(E);var g=f.options&&f.options.ranges;"function"==typeof k.yy.parseError?this.parseError=k.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var S,m,O,y,d,R,N,F,b,L={};;){if(O=i[i.length-1],this.defaultActions[O]?y=this.defaultActions[O]:(null!==S&&void 0!==S||(S=e()),y=s[O]&&s[O][S]),void 0===y||!y.length||!y[0]){var w="";b=[];for(R in s[O])this.terminals_[R]&&R>2&&b.push("'"+this.terminals_[R]+"'");w=f.showPosition?"Parse error on line "+(a+1)+":\n"+f.showPosition()+"\nExpecting "+b.join(", ")+", got '"+(this.terminals_[S]||S)+"'":"Parse error on line "+(a+1)+": Unexpected "+(S==l?"end of input":"'"+(this.terminals_[S]||S)+"'"),this.parseError(w,{text:f.match,token:this.terminals_[S]||S,line:f.yylineno,loc:E,expected:b})}if(y[0]instanceof Array&&y.length>1)throw new Error("Parse Error: multiple actions possible at state: "+O+", token: "+S);switch(y[0]){case 1:i.push(S),r.push(f.yytext),o.push(f.yylloc),i.push(y[1]),S=null,m?(S=m,m=null):(h=f.yyleng,u=f.yytext,a=f.yylineno,E=f.yylloc,c>0&&c--);break;case 2:if(N=this.productions_[y[1]][1],L.$=r[r.length-N],L._$={first_line:o[o.length-(N||1)].first_line,last_line:o[o.length-1].last_line,first_column:o[o.length-(N||1)].first_column,last_column:o[o.length-1].last_column},g&&(L._$.range=[o[o.length-(N||1)].range[0],o[o.length-1].range[1]]),void 0!==(d=this.performAction.apply(L,[u,h,a,k.yy,y[1],r,o].concat(p))))return d;N&&(i=i.slice(0,-1*N*2),r=r.slice(0,-1*N),o=o.slice(0,-1*N)),i.push(this.productions_[y[1]][0]),r.push(L.$),o.push(L._$),F=s[i[i.length-2]][i[i.length-1]],i.push(F);break;case 3:return!0}}return!0}};return t.prototype=J,J.Parser=t,new t}();void 0!==t&&void 0!==e&&(e.parser=n,e.Parser=n.Parser,e.parse=function(){return n.parse.apply(n,arguments)},e.main=function(n){n[1]||(console.log("Usage: "+n[0]+" FILE"),process.exit(1));var i=t("fs").readFileSync(t("path").normalize(n[1]),"utf8");return e.parser.parse(i)},"undefined"!=typeof module&&t.main===module&&e.main(process.argv.slice(1)))},t["./nodes"]=new function(){var t=this;(function(){var e;e=function(t){var e;return function(){var n,i,r,o;for(r=t.split("\n"),o=[],n=0,i=r.length;n<i;n++)e=r[n],o.push(" "+e);return o}().join("\n")},t.Select=function(){function t(t,e,n,i,r){this.fields=t,this.source=e,this.distinct=null!=n&&n,this.joins=null!=i?i:[],this.unions=null!=r?r:[],this.order=null,this.group=null,this.where=null,this.limit=null}return t.prototype.toString=function(){var t,n,i,r,o,s,u,a,h;for(n=["SELECT "+this.fields.join(", ")],n.push(e("FROM "+this.source)),a=this.joins,r=0,s=a.length;r<s;r++)t=a[r],n.push(e(t.toString()));for(this.where&&n.push(e(this.where.toString())),this.group&&n.push(e(this.group.toString())),this.order&&n.push(e(this.order.toString())),this.limit&&n.push(e(this.limit.toString())),h=this.unions,o=0,u=h.length;o<u;o++)i=h[o],n.push(i.toString());return n.join("\n")},t}(),t.SubSelect=function(){function t(t,e){this.select=t,this.name=null!=e?e:null}return t.prototype.toString=function(){var t;return t=[],t.push("("),t.push(e(this.select.toString())),t.push(this.name?") "+this.name.toString():")"),t.join("\n")},t}(),t.Join=function(){function t(t,e,n,i){this.right=t,this.conditions=null!=e?e:null,this.side=null!=n?n:null,this.mode=null!=i?i:null}return t.prototype.toString=function(){var t;return t="",null!=this.side&&(t+=this.side+" "),null!=this.mode&&(t+=this.mode+" "),t+"JOIN "+this.right+"\n"+e("ON "+this.conditions)},t}(),t.Union=function(){function t(t,e){this.query=t,this.all=null!=e&&e}return t.prototype.toString=function(){return"UNION"+(this.all?" ALL":"")+"\n"+this.query.toString()},t}(),t.LiteralValue=function(){function t(t,e){this.value=t,this.value2=null!=e?e:null,this.value2?(this.nested=!0,this.values=this.value.values,this.values.push(e)):(this.nested=!1,this.values=[this.value])}return t.prototype.toString=function(t){return null==t&&(t=!0),t?"`"+this.values.join(".")+"`":""+this.values.join(".")},t}(),t.StringValue=function(){function t(t,e){this.value=t,this.quoteType=null!=e?e:"''"}return t.prototype.toString=function(){var t;return t="'"===this.quoteType?this.value.replace(/(^|[^\\])'/g,"$1''"):this.value,""+this.quoteType+t+this.quoteType},t}(),t.NumberValue=function(){function t(t){this.value=Number(t)}return t.prototype.toString=function(){return this.value.toString()},t}(),t.ListValue=function(){function t(t){this.value=t}return t.prototype.toString=function(){return"("+this.value.join(", ")+")"},t}(),t.WhitepaceList=function(){function e(t){this.value=t}return e.prototype.toString=function(){return this.value.map(function(e){return e instanceof t.LiteralValue?e.toString(!1):e.toString()}).join(" ")},e}(),t.ParameterValue=function(){function t(t){this.value=t,this.index=parseInt(t.substr(1),10)-1}return t.prototype.toString=function(){return"$"+this.value},t}(),t.ArgumentListValue=function(){function t(t,e){this.value=t,this.distinct=null!=e&&e}return t.prototype.toString=function(){return this.distinct?"DISTINCT "+this.value.join(", "):""+this.value.join(", ")},t}(),t.BooleanValue=function(){function t(t){this.value=function(){switch(t.toLowerCase()){case"true":return!0;case"false":return!1;default:return null}}()}return t.prototype.toString=function(){return null!=this.value?this.value.toString().toUpperCase():"NULL"},t}(),t.FunctionValue=function(){function t(t,e,n){this.name=t,this.arguments=null!=e?e:null,this.udf=null!=n&&n}return t.prototype.toString=function(){return this.arguments?this.name.toUpperCase()+"("+this.arguments.toString()+")":this.name.toUpperCase()+"()"},t}(),t.Order=function(){function t(t,e){this.orderings=t,this.offset=e}return t.prototype.toString=function(){return"ORDER BY "+this.orderings.join(", ")+(this.offset?"\n"+this.offset.toString():"")},t}(),t.OrderArgument=function(){function t(t,e){this.value=t,this.direction=null!=e?e:"ASC"}return t.prototype.toString=function(){return this.value+" "+this.direction},t}(),t.Offset=function(){function t(t,e){this.row_count=t,this.limit=e}return t.prototype.toString=function(){return"OFFSET "+this.row_count+" ROWS"+(this.limit?"\nFETCH NEXT "+this.limit+" ROWS ONLY":"")},t}(),t.Limit=function(){function t(t,e){this.value=t,this.offset=e}return t.prototype.toString=function(){return"LIMIT "+this.value+(this.offset?"\nOFFSET "+this.offset:"")},t}(),t.Table=function(){function t(t,e,n,i,r){this.name=t,this.alias=null!=e?e:null,this.win=null!=n?n:null,this.winFn=null!=i?i:null,this.winArg=null!=r?r:null}return t.prototype.toString=function(){return this.win?this.name+"."+this.win+":"+this.winFn+"("+this.winArg+")":this.alias?this.name+" AS "+this.alias:this.name.toString()},t}(),t.Group=function(){function t(t){this.fields=t,this.having=null}return t.prototype.toString=function(){var t;return t=["GROUP BY "+this.fields.join(", ")],this.having&&t.push(this.having.toString()),t.join("\n")},t}(),t.Where=function(){function t(t){this.conditions=t}return t.prototype.toString=function(){return"WHERE "+this.conditions},t}(),t.Having=function(){function t(t){this.conditions=t}return t.prototype.toString=function(){return"HAVING "+this.conditions},t}(),t.Op=function(){function t(t,e,n){this.operation=t,this.left=e,this.right=n}return t.prototype.toString=function(){return"("+this.left+" "+this.operation.toUpperCase()+" "+this.right+")"},t}(),t.UnaryOp=function(){function t(t,e){this.operator=t,this.operand=e}return t.prototype.toString=function(){return"("+this.operator.toUpperCase()+" "+this.operand+")"},t}(),t.BetweenOp=function(){function t(t){this.value=t}return t.prototype.toString=function(){return""+this.value.join(" AND ")},t}(),t.Field=function(){function t(t,e){this.field=t,this.name=null!=e?e:null}return t.prototype.toString=function(){return this.name?this.field+" AS "+this.name:this.field.toString()},t}(),t.Star=function(){function t(){}return t.prototype.toString=function(){return"*"},t.prototype.star=!0,t}()}).call(this)},t["./parser"]=new function(){var e=this;(function(){var n;n=function(){var e;return e=t("./compiled_parser").parser,e.lexer={lex:function(){var t,e;return e=this.tokens[this.pos++]||[""],t=e[0],this.yytext=e[1],this.yylineno=e[2],t},setInput:function(t){return this.tokens=t,this.pos=0},upcomingInput:function(){return""}},e.yy=t("./nodes"),e},e.parser=n(),e.parse=function(t){return n().parse(t)}}).call(this)},t["./sql_parser"]=new function(){var e=this;(function(){e.lexer=t("./lexer"),e.parser=t("./parser"),e.nodes=t("./nodes"),e.parse=function(t){return e.parser.parse(e.lexer.tokenize(t))}}).call(this)},t["./sql_parser"]}();"function"==typeof define&&define.amd?define(function(){return e}):t.SQLParser=e}(this);