!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("q",function(e){function t(e,o){var c=e.sol(),s=e.next();if(a=null,c){if("/"==s)return(o.tokenize=n)(e,o);if("\\"==s)return e.eol()||/\s/.test(e.peek())?(e.skipToEnd(),/^\\\s*$/.test(e.current())?(o.tokenize=r)(e,o):o.tokenize=t,"comment"):(o.tokenize=t,"builtin")}if(/\s/.test(s))return"/"==e.peek()?(e.skipToEnd(),"comment"):"whitespace";if('"'==s)return(o.tokenize=i)(e,o);if("`"==s)return e.eatWhile(/[A-Z|a-z|\d|_|:|\/|\.]/),"symbol";if("."==s&&/\d/.test(e.peek())||/\d/.test(s)){var l=null;return e.backUp(1),e.match(/^\d{4}\.\d{2}(m|\.\d{2}([D|T](\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)?)?)/)||e.match(/^\d+D(\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)/)||e.match(/^\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?/)||e.match(/^\d+[ptuv]{1}/)?l="temporal":(e.match(/^0[NwW]{1}/)||e.match(/^0x[\d|a-f|A-F]*/)||e.match(/^[0|1]+[b]{1}/)||e.match(/^\d+[chijn]{1}/)||e.match(/-?\d*(\.\d*)?(e[+\-]?\d+)?(e|f)?/))&&(l="number"),!l||(s=e.peek())&&!u.test(s)?(e.next(),"error"):l}return/[A-Z|a-z]|\./.test(s)?(e.eatWhile(/[A-Z|a-z|\.|_|\d]/),d.test(e.current())?"keyword":"variable"):/[|\/&^!+:\\\-*%$=~#;@><\.,?_\']/.test(s)?null:/[{}\(\[\]\)]/.test(s)?null:"error"}function n(e,n){return e.skipToEnd(),/\/\s*$/.test(e.current())?(n.tokenize=o)(e,n):n.tokenize=t,"comment"}function o(e,n){var o=e.sol()&&"\\"==e.peek();return e.skipToEnd(),o&&/^\\\s*$/.test(e.current())&&(n.tokenize=t),"comment"}function r(e){return e.skipToEnd(),"comment"}function i(e,n){for(var o,r=!1,i=!1;o=e.next();){if('"'==o&&!r){i=!0;break}r=!r&&"\\"==o}return i&&(n.tokenize=t),"string"}function c(e,t,n){e.context={prev:e.context,indent:e.indent,col:n,type:t}}function s(e){e.indent=e.context.indent,e.context=e.context.prev}var a,l=e.indentUnit,d=function(e){return new RegExp("^("+e.join("|")+")$")}(["abs","acos","aj","aj0","all","and","any","asc","asin","asof","atan","attr","avg","avgs","bin","by","ceiling","cols","cor","cos","count","cov","cross","csv","cut","delete","deltas","desc","dev","differ","distinct","div","do","each","ej","enlist","eval","except","exec","exit","exp","fby","fills","first","fkeys","flip","floor","from","get","getenv","group","gtime","hclose","hcount","hdel","hopen","hsym","iasc","idesc","if","ij","in","insert","inter","inv","key","keys","last","like","list","lj","load","log","lower","lsq","ltime","ltrim","mavg","max","maxs","mcount","md5","mdev","med","meta","min","mins","mmax","mmin","mmu","mod","msum","neg","next","not","null","or","over","parse","peach","pj","plist","prd","prds","prev","prior","rand","rank","ratios","raze","read0","read1","reciprocal","reverse","rload","rotate","rsave","rtrim","save","scan","select","set","setenv","show","signum","sin","sqrt","ss","ssr","string","sublist","sum","sums","sv","system","tables","tan","til","trim","txf","type","uj","ungroup","union","update","upper","upsert","value","var","view","views","vs","wavg","where","where","while","within","wj","wj1","wsum","xasc","xbar","xcol","xcols","xdesc","xexp","xgroup","xkey","xlog","xprev","xrank"]),u=/[|\/&^!+:\\\-*%$=~#;@><,?_\'\"\[\(\]\)\s{}]/;return{startState:function(){return{tokenize:t,context:null,indent:0,col:0}},token:function(e,t){e.sol()&&(t.context&&null==t.context.align&&(t.context.align=!1),t.indent=e.indentation());var n=t.tokenize(e,t);if("comment"!=n&&t.context&&null==t.context.align&&"pattern"!=t.context.type&&(t.context.align=!0),"("==a)c(t,")",e.column());else if("["==a)c(t,"]",e.column());else if("{"==a)c(t,"}",e.column());else if(/[\]\}\)]/.test(a)){for(;t.context&&"pattern"==t.context.type;)s(t);t.context&&a==t.context.type&&s(t)}else"."==a&&t.context&&"pattern"==t.context.type?s(t):/atom|string|variable/.test(n)&&t.context&&(/[\}\]]/.test(t.context.type)?c(t,"pattern",e.column()):"pattern"!=t.context.type||t.context.align||(t.context.align=!0,t.context.col=e.column()));return n},indent:function(e,t){var n=t&&t.charAt(0),o=e.context;if(/[\]\}]/.test(n))for(;o&&"pattern"==o.type;)o=o.prev;var r=o&&n==o.type;return o?"pattern"==o.type?o.col:o.align?o.col+(r?0:1):o.indent+(r?0:l):0}}}),e.defineMIME("text/x-q","q")});