var curPunc,keywords=buildRE(["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"]),E=/[|/&^!+:\\\-*%$=~#;@><,?_\'\"\[\(\]\)\s{}]/;function buildRE(t){return new RegExp("^("+t.join("|")+")$")}function tokenBase(t,e){var n=t.sol(),o=t.next();if(curPunc=null,n){if("/"==o)return (e.tokenize=tokenLineComment)(t,e);if("\\"==o)return t.eol()||/\s/.test(t.peek())?(t.skipToEnd(),/^\\\s*$/.test(t.current())?(e.tokenize=tokenCommentToEOF)(t):e.tokenize=tokenBase,"comment"):(e.tokenize=tokenBase,"builtin")}if(/\s/.test(o))return "/"==t.peek()?(t.skipToEnd(),"comment"):"null";if('"'==o)return (e.tokenize=tokenString)(t,e);if("`"==o)return t.eatWhile(/[A-Za-z\d_:\/.]/),"macroName";if("."==o&&/\d/.test(t.peek())||/\d/.test(o)){var r=null;return t.backUp(1),t.match(/^\d{4}\.\d{2}(m|\.\d{2}([DT](\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)?)?)/)||t.match(/^\d+D(\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)/)||t.match(/^\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?/)||t.match(/^\d+[ptuv]{1}/)?r="temporal":(t.match(/^0[NwW]{1}/)||t.match(/^0x[\da-fA-F]*/)||t.match(/^[01]+[b]{1}/)||t.match(/^\d+[chijn]{1}/)||t.match(/-?\d*(\.\d*)?(e[+\-]?\d+)?(e|f)?/))&&(r="number"),!r||(o=t.peek())&&!E.test(o)?(t.next(),"error"):r}return /[A-Za-z]|\./.test(o)?(t.eatWhile(/[A-Za-z._\d]/),keywords.test(t.current())?"keyword":"variable"):/[|/&^!+:\\\-*%$=~#;@><\.,?_\']/.test(o)||/[{}\(\[\]\)]/.test(o)?null:"error"}function tokenLineComment(t,e){return t.skipToEnd(),/\/\s*$/.test(t.current())?(e.tokenize=tokenBlockComment)(t,e):e.tokenize=tokenBase,"comment"}function tokenBlockComment(t,e){var n=t.sol()&&"\\"==t.peek();return t.skipToEnd(),n&&/^\\\s*$/.test(t.current())&&(e.tokenize=tokenBase),"comment"}function tokenCommentToEOF(t){return t.skipToEnd(),"comment"}function tokenString(t,e){for(var n,o=!1,r=!1;n=t.next();){if('"'==n&&!o){r=!0;break}o=!o&&"\\"==n;}return r&&(e.tokenize=tokenBase),"string"}function pushContext(t,e,n){t.context={prev:t.context,indent:t.indent,col:n,type:e};}function popContext(t){t.indent=t.context.indent,t.context=t.context.prev;}const q={startState:function(){return {tokenize:tokenBase,context:null,indent:0,col:0}},token:function(t,e){t.sol()&&(e.context&&null==e.context.align&&(e.context.align=!1),e.indent=t.indentation());var n=e.tokenize(t,e);if("comment"!=n&&e.context&&null==e.context.align&&"pattern"!=e.context.type&&(e.context.align=!0),"("==curPunc)pushContext(e,")",t.column());else if("["==curPunc)pushContext(e,"]",t.column());else if("{"==curPunc)pushContext(e,"}",t.column());else if(/[\]\}\)]/.test(curPunc)){for(;e.context&&"pattern"==e.context.type;)popContext(e);e.context&&curPunc==e.context.type&&popContext(e);}else "."==curPunc&&e.context&&"pattern"==e.context.type?popContext(e):/atom|string|variable/.test(n)&&e.context&&(/[\}\]]/.test(e.context.type)?pushContext(e,"pattern",t.column()):"pattern"!=e.context.type||e.context.align||(e.context.align=!0,e.context.col=t.column()));return n},indent:function(t,e,n){var o=e&&e.charAt(0),r=t.context;if(/[\]\}]/.test(o))for(;r&&"pattern"==r.type;)r=r.prev;var i=r&&o==r.type;return r?"pattern"==r.type?r.col:r.align?r.col+(i?0:1):r.indent+(i?0:n.unit):0}};

export { q };
