LaravelTest
139 строк · 6.4 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("q",function(config){15var indentUnit=config.indentUnit,16curPunc,17keywords=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"]),18E=/[|/&^!+:\\\-*%$=~#;@><,?_\'\"\[\(\]\)\s{}]/;19function buildRE(w){return new RegExp("^("+w.join("|")+")$");}20function tokenBase(stream,state){21var sol=stream.sol(),c=stream.next();22curPunc=null;23if(sol)24if(c=="/")25return(state.tokenize=tokenLineComment)(stream,state);26else if(c=="\\"){27if(stream.eol()||/\s/.test(stream.peek()))28return stream.skipToEnd(),/^\\\s*$/.test(stream.current())?(state.tokenize=tokenCommentToEOF)(stream):state.tokenize=tokenBase,"comment";29else30return state.tokenize=tokenBase,"builtin";31}32if(/\s/.test(c))33return stream.peek()=="/"?(stream.skipToEnd(),"comment"):"whitespace";34if(c=='"')35return(state.tokenize=tokenString)(stream,state);36if(c=='`')37return stream.eatWhile(/[A-Za-z\d_:\/.]/),"symbol";38if(("."==c&&/\d/.test(stream.peek()))||/\d/.test(c)){39var t=null;40stream.backUp(1);41if(stream.match(/^\d{4}\.\d{2}(m|\.\d{2}([DT](\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)?)?)/)42|| stream.match(/^\d+D(\d{2}(:\d{2}(:\d{2}(\.\d{1,9})?)?)?)/)43|| stream.match(/^\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?/)44|| stream.match(/^\d+[ptuv]{1}/))45t="temporal";46else if(stream.match(/^0[NwW]{1}/)47|| stream.match(/^0x[\da-fA-F]*/)48|| stream.match(/^[01]+[b]{1}/)49|| stream.match(/^\d+[chijn]{1}/)50|| stream.match(/-?\d*(\.\d*)?(e[+\-]?\d+)?(e|f)?/))51t="number";52return(t&&(!(c=stream.peek())||E.test(c)))?t:(stream.next(),"error");53}54if(/[A-Za-z]|\./.test(c))55return stream.eatWhile(/[A-Za-z._\d]/),keywords.test(stream.current())?"keyword":"variable";56if(/[|/&^!+:\\\-*%$=~#;@><\.,?_\']/.test(c))57return null;58if(/[{}\(\[\]\)]/.test(c))59return null;60return"error";61}62function tokenLineComment(stream,state){63return stream.skipToEnd(),/\/\s*$/.test(stream.current())?(state.tokenize=tokenBlockComment)(stream,state):(state.tokenize=tokenBase),"comment";64}65function tokenBlockComment(stream,state){66var f=stream.sol()&&stream.peek()=="\\";67stream.skipToEnd();68if(f&&/^\\\s*$/.test(stream.current()))69state.tokenize=tokenBase;70return"comment";71}72function tokenCommentToEOF(stream){return stream.skipToEnd(),"comment";}73function tokenString(stream,state){74var escaped=false,next,end=false;75while((next=stream.next())){76if(next=="\""&&!escaped){end=true;break;}77escaped=!escaped&&next=="\\";78}79if(end)state.tokenize=tokenBase;80return"string";81}82function pushContext(state,type,col){state.context={prev:state.context,indent:state.indent,col:col,type:type};}83function popContext(state){state.indent=state.context.indent;state.context=state.context.prev;}84return{85startState:function(){86return{tokenize:tokenBase,87context:null,88indent:0,89col:0};90},91token:function(stream,state){92if(stream.sol()){93if(state.context&&state.context.align==null)94state.context.align=false;95state.indent=stream.indentation();96}97//if (stream.eatSpace()) return null;98var style=state.tokenize(stream,state);99if(style!="comment"&&state.context&&state.context.align==null&&state.context.type!="pattern"){100state.context.align=true;101}102if(curPunc=="(")pushContext(state,")",stream.column());103else if(curPunc=="[")pushContext(state,"]",stream.column());104else if(curPunc=="{")pushContext(state,"}",stream.column());105else if(/[\]\}\)]/.test(curPunc)){106while(state.context&&state.context.type=="pattern")popContext(state);107if(state.context&&curPunc==state.context.type)popContext(state);108}109else if(curPunc=="."&&state.context&&state.context.type=="pattern")popContext(state);110else if(/atom|string|variable/.test(style)&&state.context){111if(/[\}\]]/.test(state.context.type))112pushContext(state,"pattern",stream.column());113else if(state.context.type=="pattern"&&!state.context.align){114state.context.align=true;115state.context.col=stream.column();116}117}118return style;119},120indent:function(state,textAfter){121var firstChar=textAfter&&textAfter.charAt(0);122var context=state.context;123if(/[\]\}]/.test(firstChar))124while (context&&context.type=="pattern")context=context.prev;125var closing=context&&firstChar==context.type;126if(!context)127return 0;128else if(context.type=="pattern")129return context.col;130else if(context.align)131return context.col+(closing?0:1);132else133return context.indent+(closing?0:indentUnit);134}135};136});137CodeMirror.defineMIME("text/x-q","q");138
139});140