text: !function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("../../mode/sql/sql")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../../mode/sql/sql"],t):t(CodeMirror)}(function(t){"use strict";function e(e){var r=e.doc.modeOption;return"sql"===r&&(r="text/x-sql"),t.resolveMode(r).keywords}function r(t,e){var r=t.length,n=e.substr(0,r);return t.toUpperCase()===n.toUpperCase()}function n(t,e,n,o){for(var i in n)n.hasOwnProperty(i)&&(Array.isArray(n)&&(i=n[i]),r(e,i)&&t.push(o(i)))}function o(t,e){var r=e.getCursor(),o=e.getTokenAt(r),i=o.string.substr(1),s=p(r.line,o.start),a=e.getTokenAt(s).string;f.hasOwnProperty(a)||(a=u(a,e));var l=f[a];l&&n(t,i,l,function(t){return"."+t})}function i(t,e){if(t)for(var r=/[,;]/g,n=t.split(" "),o=0;o<n.length;o++)e(n[o]?n[o].replace(r,""):"")}function s(t){return t.line+t.ch/Math.pow(10,6)}function a(t){return p(Math.floor(t),+t.toString().split(".").pop())}function u(t,e){for(var r=e.doc,n=r.getValue(),o=t.toUpperCase(),u="",l="",g=[],d={start:p(0,0),end:p(e.lastLine(),e.getLineHandle(e.lastLine()).length)},h=n.indexOf(c.QUERY_DIV);-1!=h;)g.push(r.posFromIndex(h)),h=n.indexOf(c.QUERY_DIV,h+1);g.unshift(p(0,0)),g.push(p(e.lastLine(),e.getLineHandle(e.lastLine()).text.length));for(var v=0,A=s(e.getCursor()),m=0;m<g.length;m++){var b=s(g[m]);if(A>v&&b>=A){d={start:a(v),end:a(b)};break}v=b}for(var q=r.getRange(d.start,d.end,!1),m=0;m<q.length;m++){var y=q[m];if(i(y,function(t){var e=t.toUpperCase();e===o&&f.hasOwnProperty(u)&&(l=u),e!==c.ALIAS_KEYWORD&&(u=t)}),l)break}return l}var f,l,c={QUERY_DIV:";",ALIAS_KEYWORD:"AS"},p=t.Pos;t.registerHelper("hint","sql",function(t,r){f=r&&r.tables||{},l=l||e(t);var i,s,a,u=t.getCursor(),c=[],g=t.getTokenAt(u);if(g.string.match(/^[.\w@]\w*$/)?(a=g.string,i=g.start,s=g.end):(i=s=u.ch,a=""),"."==a.charAt(0)){if(o(c,t),!c.length){for(;i&&"."==a.charAt(0);)g=t.getTokenAt(p(u.line,g.start-1)),i=g.start,a=g.string+a;n(c,a,f,function(t){return t})}}else n(c,a,f,function(t){return t}),n(c,a,l,function(t){return t.toUpperCase()});return{list:c,from:p(u.line,i),to:p(u.line,s)}})});