(function(){u8.services.factory.ready("CodeEditor",function(){u8.Base.Widgets.CodeEditor.defineMode("uql",e);u8.Base.Widgets.CodeEditor.validators["uql"]=r});function e(){function e(e){return e=="="||e==">"||e=="<"}function r(e){return e>="A"&&e<="Z"||e>="a"&&e<="z"||e>="0"&&e<="9"||e=="_"||e=="-"||e>="~"&&!(e>=""&&e<=" ")}function n(e){return e>="0"&&e<="9"}function t(e){return e==","||e=="("||e==")"}var i={select:null,from:null,where:null,orderby:null,with:null,withoptional:null,withsummed:null,withsummedoptional:null,without:null,withoutoptional:null,plus:null,plussummed:null,having:null,havingoptional:null,as:"from",using:"from",linked:"from",limited:"from",additionalflags:"from",flags:["from","orderby"],to:"from",rows:"from",descending:"orderby",ascending:"orderby",and:"where",or:"where"};return{token:function(l,o){o.afterSection=false;var u=l.next();if(e(u)){l.eatWhile(e);return"operator"}else if(u=="("){if(!o.inWhat){o.inWhat=o.keyword;o.inDepth=1}else{o.inDepth++}}else if(u==")"){o.inDepth--;if(o.inDepth<=0){delete o.inWhat}}else if(t(u)){return"bracket"}else if(n(u)){l.eatWhile(n);return"number"}else if(r(u)){l.eatWhile(r);var a=l.current().toLowerCase();var s=i[a];if(s===null){o.keyword=a;return"keyword"}if(s&&s.indexOf(o.inWhat)>=0){return"atom"}return"variable"}else if(u=='"'||u=="'"){var f=u,d=u;while(true){u=l.next();if(!u||u==f&&d!="\\"){break}d=u}return"string"}return},startState:function(){return{}}}}function r(){function e(e){if(!e){return}var r=$.Deferred();u8.request("QueryChannel.ParseQueryStatement",{queryStatement:e},function(e,n){var t=n.error;if(t){t.handled=true;var i=[{line:"linePos"in t?t.linePos-1:0,pos:"charPos"in t?t.charPos-1:0,reason:t.message}];return r.resolve(i)}r.resolve(null,{statement:n.response.statement})});return r}return{validate:e}}})();