From 505112d4d13ce9080bf597e2514cf63c0d25c59f Mon Sep 17 00:00:00 2001 From: Nikos M Date: Sat, 15 Aug 2015 23:11:56 +0300 Subject: [PATCH] v. 1.0.2 * utils updates/fixes --- api-reference.md | 12 ++ beeld.config | 2 +- build/codemirror_grammar.js | 203 +++++++++++++++++++------------- build/codemirror_grammar.min.js | 4 +- src/main.js | 14 +++ src/utils.js | 183 +++++++++++++++------------- 6 files changed, 254 insertions(+), 164 deletions(-) diff --git a/api-reference.md b/api-reference.md index 0600378..7d2d308 100644 --- a/api-reference.md +++ b/api-reference.md @@ -17,6 +17,18 @@ __For browser:__ +__Method__: `clone` + +```javascript +cloned = CodeMirrorGrammar.clone( grammar [, deep=true] ); +``` + +Clone (deep) a `grammar` + +Utility to clone objects efficiently + + + __Method__: `extend` ```javascript diff --git a/beeld.config b/beeld.config index 9c4f279..c679ba7 100644 --- a/beeld.config +++ b/beeld.config @@ -42,7 +42,7 @@ tasks =[{}] "@@ROOT@@" = "this" "@@EXPORTS@@" = "exports" - "@@VERSION@@" = "1.0.1" + "@@VERSION@@" = "1.0.2" "@@MODULE_NAME@@" = "CodeMirrorGrammar" @ diff --git a/build/codemirror_grammar.js b/build/codemirror_grammar.js index 0cc29b2..a8a2a4e 100644 --- a/build/codemirror_grammar.js +++ b/build/codemirror_grammar.js @@ -1,7 +1,7 @@ /** * * CodeMirrorGrammar -* @version: 1.0.1 +* @version: 1.0.2 * * Transform a grammar specification in JSON format, into a syntax-highlight parser mode for CodeMirror * https://github.com/foo123/codemirror-grammar @@ -92,55 +92,46 @@ var } ; -var undef = undefined, PROTO = 'prototype', HAS = 'hasOwnProperty', IS_ENUM = 'propertyIsEnumerable', +var undef = undefined, + PROTO = 'prototype', HAS = 'hasOwnProperty', IS_ENUM = 'propertyIsEnumerable', Keys = Object.keys, AP = Array[PROTO], OP = Object[PROTO], FP = Function[PROTO], toString = OP.toString, // types - //T_INF = 5, - T_NUM = 4, T_NAN = 5, T_BOOL = 8, + T_NUM = 4, T_INF = 5, T_NAN = 6, T_BOOL = 8, T_STR = 16, T_CHAR = 17, T_CHARLIST = 18, T_ARRAY = 32, T_OBJ = 64, T_FUNC = 128, T_REGEX = 256, T_DATE = 512, T_NULL = 1024, T_UNDEF = 2048, T_UNKNOWN = 4096, T_STR_OR_ARRAY = T_STR|T_ARRAY, T_OBJ_OR_ARRAY = T_OBJ|T_ARRAY, - TO_STRING = { + STRING_TYPE = { + "[object Number]" : T_NUM, + "[object String]" : T_STR, "[object Array]" : T_ARRAY, "[object RegExp]" : T_REGEX, "[object Date]" : T_DATE, - "[object Number]" : T_NUM, - "[object String]" : T_STR, "[object Function]" : T_FUNC, "[object Object]" : T_OBJ }, get_type = function( v ) { - var /*type_of,*/ to_string; - - if (null === v) return T_NULL; - else if (true === v || false === v) return T_BOOL; - else if (undef === v /*|| "undefined" === type_of*/) return T_UNDEF; - - //type_of = typeOf(v); - to_string = toString.call( v ); - //to_string = TO_STRING[HAS](to_string) ? TO_STRING[to_string] : T_UNKNOWN; - to_string = TO_STRING[to_string] || T_UNKNOWN; - - //if (undef === v /*|| "undefined" === type_of*/) return T_UNDEF; - if (T_NUM === to_string || v instanceof Number) return isNaN(v) ? T_NAN : T_NUM; - else if (T_STR === to_string || v instanceof String) return (1 === v.length) ? T_CHAR : T_STR; - else if (T_ARRAY === to_string || v instanceof Array) return T_ARRAY; - else if (T_REGEX === to_string || v instanceof RegExp) return T_REGEX; - else if (T_DATE === to_string || v instanceof Date) return T_DATE; - else if (T_FUNC === to_string || v instanceof Function) return T_FUNC; - else if (T_OBJ === to_string) return T_OBJ; - // unkown type - return T_UNKNOWN; + if ( null === v ) return T_NULL; + else if ( true === v || false === v || + v instanceof Boolean ) return T_BOOL; + else if ( undef === v ) return T_UNDEF; + var TYPE = STRING_TYPE[ toString.call( v ) ] || T_UNKNOWN; + if ( T_NUM === TYPE || v instanceof Number ) return isNaN(v) ? T_NAN : (isFinite(v) ? T_NUM : T_INF); + else if ( T_STR === TYPE || v instanceof String ) return 1 === v.length ? T_CHAR : T_STR; + else if ( T_ARRAY === TYPE || v instanceof Array ) return T_ARRAY; + else if ( T_REGEX === TYPE || v instanceof RegExp ) return T_REGEX; + else if ( T_DATE === TYPE || v instanceof Date ) return T_DATE; + else if ( T_FUNC === TYPE || v instanceof Function ) return T_FUNC; + else if ( T_OBJ === TYPE ) return T_OBJ; + return T_UNKNOWN; }, Merge = function(/* var args here.. */) { - var args = arguments, argslen, - o1, o2, v, p, i, T; - o1 = args[0] || {}; - argslen = args.length; + var args = arguments, argslen = args.length, + o, o2, v, p, i, T; + o = args[0] || {}; for (i=1; i1){for(p=(a>>1)+1,c=0;p>=c;c++)f=gn(i[c]),h=gn(i[a-1-c]),(tn!==f||tn!==h)&&(d=0),en&f||en&h?k=1:(Bn(i[c],e)||Bn(i[a-1-c],e))&&(m=1);if(!d||r&&X&gn(r))if(!r||k||m){for(c=0;a>c;c++)i[c]=en&gn(i[c])?s(t+"_"+c,i[c],e,r,l,o):u(t+"_"+c,Dn(i[c],e,l),c,o);g=a>1?new Fn(t,i):i[0]}else g=u(t,jn(i,r),0,o);else i=i.slice().join(""),i.isCharList=1,g=u(t,i,0,o)}return o[t]=g}function i(t,n,e,r,l){if(l[t])return l[t];var o,s,i,c,a,p,f;for(c=[],a=[],o=Rn(n),s=0,i=o.length;i>s;s++)p=u(t+"_0_"+s,Dn(o[s][0],e,r),s,l),f=o[s].length>1?on!==p.tt||X!==gn(o[s][1])||Bn(o[s][1],e)?u(t+"_1_"+s,Dn(o[s][1],e,r),s,l):o[s][1]:p,c.push(p),a.push(f);return l[t]=new Vn(t,c,a)}function c(t,n,e){var r,l,o,u,s,i,c,a,p,f,h,g;if(i=new String(wn(t)),i.pos=0,1===i.length)f=""+t,n[f]||(n[f]={type:"simple",tokens:t}),t=f;else{for(r=[],l=[],o="",h=[];i.poss[0]&&(s[0]=0),2>s.length?s.push(s[0]):s[1]=s[1].length?parseInt(s[1],10)||R:R,0>s[1]&&(s[1]=0),p=l.pop(),f=""+p+["{",s[0]||"",",",isFinite(s[1])?s[1]||"":"","}"].join(""),e[f]||(e[f]={type:"group",match:[s[0],s[1]],tokens:[p]}),l.push(f)}else{if("}"===a)continue;"|"===a?(l.length>1?(f=""+l.join(" "),e[f]||(e[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[]):"("===a?(h.push([l,r,o]),l=[],r=[],o=""):")"===a&&(l.length>1?(f=""+l.join(" "),e[f]||(e[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),e[f]||(e[f]={type:"group",match:"either",tokens:r})):r.length&&(f=r[0]),r=[],g=h.pop(),l=g[0],r=g[1],o=g[2],p=f,f="("+p+")",e[f]||(e[f]=Cn(n[p]||e[p])),l.push(f))}else o+=a;o.length&&(n[o]||e[o]||(n[o]={type:"simple",tokens:o}),l.push(o)),o="",l.length>1?(f=""+l.join(" "),e[f]||(e[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),e[f]||(e[f]={type:"group",match:"either",tokens:r}),t=f):r.length&&(t=r[0]),r=[]}return t}function a(t,n,e,r,l,o,u,h,g,k,m){var C,v,y,A,T,N,Q,q,F,K,U,Z,H,Y,J,W,tn=null;if(null===t)return new Kn(_,"EOL",t);if(""===t)return new Kn(b,"NONSPACE",t);if(!1===t||0===t)return new Kn(O,"EMPTY",t);if(en&gn(t)&&(W=t,t="NGRAM_"+W.join("_"),r[t]||(r[t]={type:"ngram",tokens:W})),t=""+t,h[t])return h[t];for(e[t]?(C=e[t],pn&gn(C)&&(C=e[t]={type:"simple",tokens:C})):C=r[t]?r[t]:t,X&gn(C)&&(C=c(C,e,r),C=e[C]||r[C]);C.extend;)Y=C.extend,J=e[Y]||r[Y],delete C.extend,J&&(pn&gn(J)&&(J={type:"simple",tokens:J}),C=vn(J,C));if("undefined"==typeof C.type&&(C.all||C.sequence?(C.type="group",C.match="sequence",C.tokens=C.all||C.sequence,C.all?delete C.all:delete C.sequence):C.either?(C.type="group",C.match="either",C.tokens=C.either,delete C.either):C.zeroOrMore?(C.type="group",C.match="zeroOrMore",C.tokens=C.zeroOrMore,delete C.zeroOrMore):C.oneOrMore?(C.type="group",C.match="oneOrMore",C.tokens=C.oneOrMore,delete C.oneOrMore):C.zeroOrOne?(C.type="group",C.match="zeroOrOne",C.tokens=C.zeroOrOne,delete C.zeroOrOne):C.comment?(C.type="comment",C.tokens=C.comment,delete C.comment):C.block?(C.type="block",C.tokens=C.block,delete C.block):C["escaped-block"]?(C.type="escaped-block",C.tokens=C["escaped-block"],delete C["escaped-block"]):C.simple?(C.type="simple",C.tokens=C.simple,delete C.simple):C.type="simple"),v=C.type?V[C.type.toUpperCase().replace(xn,"")]:S,S&v){if(""===C.tokens)return tn=new Kn(b,t,t),h[t]=tn,tn;if(null===C.tokens)return tn=new Kn(_,t,t),h[t]=tn,tn;if(!1===C.tokens||0===C.tokens)return tn=new Kn(O,t,t),h[t]=tn,tn}if(C.tokens=En(C.tokens),S&v)C.autocomplete&&f(C,t,m),C.push?(C.action||(C.action=["push",C.push]),delete C.push):C[$]("pop")&&(C.action||(C.action=["pop",C.pop]),delete C.pop),A=null,C.action&&C.action[0]&&("push"===C.action[0]?A=[d,C.action[1]]:"pop"===C.action[0]&&(A=[E,C.action[1]])),y="undefined"==typeof C.combine?"\\b":C.combine,tn=new Kn(S,t,s(t,C.tokens.slice(),n,y,o,u)),tn.ta=A,h[t]=tn;else if(w&v)M&v&&p(C,k),tn=new $n(v,t,i(t,C.tokens.slice(),n,o,u),C.multiline,C.escape,l[t+".inside"]?1:0),h[t]=tn,C.interleave&&g.push(tn.clone());else if(P&v){for(N=C.tokens.slice(),en&gn(C.match)?tn=new Un(D,t,null,C.match[0],C.match[1]):(T=z[C.match.toUpperCase()],tn=j===T?new Un(j,t,null,0,1):L===T?new Un(L,t,null,0,R):G===T?new Un(G,t,null,1,R):x&T?new Un(x,t,null):new Un(B,t,null)),h[t]=tn,Q=[],K=0,U=N.length;U>K;K++)Q=Q.concat(a(N[K],n,e,r,l,o,u,h,g,k,m));tn.set(Q)}else if(I&v){for(tn=Rn(C.tokens.slice()).slice(),q=[],K=0,U=tn.length;U>K;K++)q[K]=tn[K].slice(),tn[K]=new Un(I,t+"_NGRAM_"+K,null);for(h[t]=tn,K=0,U=tn.length;U>K;K++){for(F=q[K],Q=[],Z=0,H=F.length;H>Z;Z++)Q=Q.concat(a(F[Z],n,e,r,l,o,u,h,g,k,m));tn[K].set(Q)}}return h[t]}function p(t,n){var e,r,l,o,u,s=Rn(t.tokens.slice());for(o=0,u=s.length;u>o;o++)e=s[o][0],r=s[o].length>1?s[o][1]:s[o][0],l=s[o].length>2?s[o][2]:"",null===r?(n.line=n.line||[],n.line.push(e)):(n.block=n.block||[],n.block.push([e,r,l]))}function f(t,n,e){var r=[].concat(En(t.tokens)).map(function(t){return{word:t,meta:n}});e.autocomplete=(e.autocomplete||[]).concat(r)}function h(t){var n,e,r,l,o,u,s,i,c,p,f,h,g,k,m,d;if(t.__parsed)return t;for(f={},h={},g={},m={},d={},k=[],t=Cn(t),n=t.RegExpID||null,t.RegExpID=null,delete t.RegExpID,u=t.Lex||{},t.Lex=null,delete t.Lex,s=t.Syntax||{},t.Syntax=null,delete t.Syntax,o=t.Style||{},l=t.Parser||[],r=l.length,e=[],i=0;r>i;i++)c=l[i],p=a(c,n,u,s,o,f,h,g,k,m,d)||null,p&&(en&gn(p)?e=e.concat(p):e.push(p));return t.Parser=e,t.cTokens=k,t.Style=o,t.Comments=m,t.Keywords=d,t.Extra=t.Extra||{},t.__parsed=1,t}function g(t,n){var e=new Jn(h(t),{DEFAULT:n||k,ERROR:m}),r=function(t,n){return{startState:function(){return new Hn},copyState:function(t){return t.clone()},token:function(t,n){return e.getToken(t,n)},indent:function(r,l,o){return e.indent(r,l,o,t,n)},lineComment:e.LC,blockCommentStart:e.BCS,blockCommentEnd:e.BCE,blockCommentContinue:e.BCC,blockCommentLead:e.BCL,electricChars:e.Extra.electricChars||!1,fold:e.Extra.fold||!1}};return r.supportGrammarAnnotations=!1,r.validator=function(t){if(!r.supportGrammarAnnotations||!t||!t.length)return[];var n,l,o,u,s,i=[],c=e.parse(t),a=c.length;for(u=0;a>u;u++)if(n=c[u],n&&n.length)for(s=0,o=0;oo;o++)if(e=s[o],rn===gn(e))for(l in e)e[$](l)&&e[U](l)&&(r=e[l],u=gn(r),n[l]=Y&u?0+r:pn&u?r.slice():r);return n},mn=Object.create,dn=function(t,n){var e,r=arguments.length,l="constructor";return 0===r?(t=Object,n={}):1===r?(n=t||{},t=Object):(t=t||Object,n=n||{}),n[$](l)||(n[l]=function(){}),e=n[l],delete n[l],e[K]=kn(mn(t[K]),n),e[K][l]=e,e},En=function(t,n){return n||en!==gn(t)?[t]:t},Rn=function(t,n){return t=En(t,n),(n||en!==gn(t[0]))&&(t=[t]),t},Cn=function(t){var n,e=gn(t);if(!(fn&e))return t;var r,l={};for(r in t)t[$](r)&&t[U](r)&&(n=gn(t[r]),l[r]=rn&n?Cn(t[r]):pn&n?t[r].slice():t[r]);return l},vn=function(){var t=arguments,n=t.length;if(1>n)return null;if(2>n)return Cn(t[0]);var e,r,l,o,u=t[0],s=Cn(u);for(n--,r=1;n>r;r++)if(e=t[r])for(l in e)e[$](l)&&e[U](l)&&(u[$](l)&&u[U](l)?(o=gn(u[l]),rn&~X&o&&(s[l]=vn(u[l],e[l]))):s[l]=Cn(e[l]));return s},yn=/([.*+?^${}()|[\]\/\\\-])/g,Sn=function(t){return t.replace(yn,"\\$1")},_n=/\$(\d{1,2})/g,bn=function(t,n){var e,r,l,o;for(o=function(t,e){return n[1+parseInt(e,10)]},e=t.split("$$"),l=e.length,r=0;l>r;r++)e[r]=e[r].replace(_n,o);return e.join("$")},On=/^\s+|\s+$/g,wn=String[K].trim?function(t){return t.trim()}:function(t){return t.replace(On,"")},An=function(t,n){return n.length-t.length},Mn=/\r\n|\r|\n/g,xn=/[\-_]/g,Tn=/^([{}()*+?|'"]|\s)/,Bn=function(t,n){return X&gn(n)&&X&gn(t)&&n.length&&n.length<=t.length&&n==t.substr(0,n.length)},Dn=function(t,n,e){if(!t||Y===gn(t))return t;var r,l=n?n.length||0:0;if(l&&n==t.substr(0,l)){var o,u,s,i,r,c,a=t.substr(l),p=a[0],f="";for(r=a.length;r--&&(c=a[r],p!=c);)"i"==c.toLowerCase()&&(f="i");return o=a.substring(1,r),u="^("+o+")",e[u]||(s=new RegExp(u,f),i={peek:null,negativepeek:null},e[u]=[s,i]),e[u]}return t},jn=function(t,n){var e={},r="",l=gn(n);(X===l||tn===l)&&(r=n);var o=t.sort(An).map(function(t){return e[t.charAt(0)]=1,Sn(t)}).join("|");return[new RegExp("^("+o+")"+r),{peek:e,negativepeek:null},1]},Ln=0,Gn=function(){return++Ln},Pn=function(t){return[t||"uuid",++Ln,(new Date).getTime()].join("_")},In=(!("undefined"==typeof global||"[object global]"!==H.call(global)),Math.max),Nn=/^[\s\u00a0]+/,Qn=/[^\s\u00a0]/,qn=dn({constructor:function(t){var n=this;n._=null,n.s=t?""+t:"",n.start=n.pos=0,n.lCP=n.lCV=0,n.lS=0},_:null,s:"",start:0,pos:0,lCP:0,lCV:0,lS:0,dispose:function(){var t=this;return t._=null,t.s=null,t.start=null,t.pos=null,t.lCP=null,t.lCV=null,t.lS=null,t},toString:function(){return this.s},sol:function(){return 0===this.pos},eol:function(){return this.pos>=this.s.length},chr:function(t,n){var e=this,r=e.s.charAt(e.pos)||null;return r&&t===r?(!1!==n&&(e.pos+=1,e._&&(e._.pos=e.pos)),r):!1},chl:function(t,n){var e=this,r=e.s.charAt(e.pos)||null;return r&&-10?!1:(!1!==l&&(u.pos+=o[r||0].length,u._&&(u._.pos=u.pos)),o)},spc:function(t){var n,e=this,r=e.pos,l=e.s.slice(r);return(n=l.match(Nn))?(!1!==t&&(e.pos+=n[0].length,e._&&(e._.pos=e.pos)),1):0},end:function(){var t=this;return t.pos=t.s.length,t._&&(t._.pos=t.pos),t},nxt:function(){var t,n=this,e=n.s;return n.poso;++o)u+=" "==t.charAt(o)?e-u%e:1;return u},qn._=function(t){var n=new qn;return n._=t,n.s=""+t.string,n.start=t.start,n.pos=t.pos,n.lCP=t.lastColumnPos,n.lCV=t.lastColumnValue,n.lS=t.lineStart,n};var zn,Vn,Fn,Kn,$n,Un,Zn=dn({constructor:function(t){this._=t||[]},_:null,dispose:function(){var t=this;return t._=null,t},toString:function(){return this._.slice().reverse().join("\n")},clone:function(){return new Zn(this._.slice())},isEmpty:function(){return 0>=this._.length},pos:function(){return this._.length},peek:function(t){var n=this,e=n._;if(t=arguments.length?t:-1,e.length){if(0>t&&0<=e.length+t)return e[e.length+t];if(t>=0&&te;e++)if(r=o[e].get(t,n))return s?[e,r[1]]:r;return!1}}),Vn=dn(zn,{constructor:function(t,n,e){var r=this;r.mt=y,r.tn=t,r.s=new Fn(r.tn+"_Start",n,!1),r.e=e},s:null,e:null,get:function(t,n){var e,r=this,l=r.s,o=r.e;if(e=l.get(t,n)){var u,s=o[e[0]],i=gn(s),c=l.ms[e[0]].tt;return on===c&&(Y===i?(u=e[1][s+1],s=new zn(u.length>1?X:tn,r.tn+"_End",u)):X===i&&(u=bn(s,e[1]),s=new zn(u.length>1?X:tn,r.tn+"_End",u))),s}return!1}}),Kn=dn({constructor:function(t,n,e){var r=this;r.tt=t||S,r.id=n,r.tk=e,r.REQ=0,r.ERR=0,r.ACTER=0,r.MSG=null,r.CLONE=["tk"]},sID:null,id:null,tt:null,tk:null,ta:null,REQ:0,ERR:0,ACTER:0,MSG:null,CLONE:null,act:function(t,n){var e,r,l=this,o=l.ta||null,u=n.data;if(o)if(e=o[0],r=o[1],E===e)if(r){if(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),u.isEmpty()||r!==u.peek())return l.MSG='Token "'+r+'" No Match',u.pop(),1;u.pop()}else u.pop();else d===e&&r&&(t&&(r=Y===gn(r)?t[1][r]:bn(r,t[1])),u.push(r));return 0},get:function(t,n){var e=this,r=e.ta,l=e.tk,o=e.tt,u=e.id,s=null;if(e.MSG=null,e.ACTER=0,O===o)return e.ERR=0,e.REQ=0,!0;if(_===o){if(t.spc(),t.eol())return u}else if(b===o)e.ERR=e.REQ&&t.spc()&&!t.eol()?1:0,e.REQ=0;else if(s=l.get(t))return r&&(e.ACTER=e.act(s,n)),u;return!1},req:function(t){return this.REQ=!!t,this},err:function(){var t=this;return t.MSG?t.MSG:t.REQ?'Token "'+t.id+'" Expected':'Syntax Error: "'+t.id+'"'},clone:function(){var t,n,e,r=this,l=r.CLONE;if(t=new r.constructor,t.tt=r.tt,t.id=r.id,t.ta=r.ta?r.ta.slice():r.ta,l&&l.length)for(n=0,e=l.length;e>n;n++)t[l[n]]=r[l[n]];return t},toString:function(){var t=this;return["[","Tokenizer: ",t.id,", Matcher: ",t.tk?t.tk.toString():null,"]"].join("")}}),$n=dn(Kn,{constructor:function(t,n,e,r,l,o){var u=this;u.tt=t,u.id=n,u.tk=e,u.REQ=0,u.ERR=0,u.ACTER=0,u.MSG=null,u.mline="undefined"==typeof r?1:r,u.esc=l||"\\",u.inter=o,u.CLONE=["tk","mline","esc","inter"]},inter:0,mline:0,esc:null,get:function(t,n){var e,r,l,o,u,s,i,c,a,p=this,f=0,h=0,g="",k=p.mline,m=p.tk,d=p.id,E=p.tt,R=p.inter,C=R?d+".inside":d,v=0,y=A===E,S=p.esc;if(p.MSG=null,p.ACTER=0,M===E&&(p.REQ=0),u=0,n.inBlock===d?(h=1,e=n.endBlock,u=1,s=C):!n.inBlock&&(e=m.get(t))&&(h=1,n.inBlock=d,n.endBlock=e,s=d),h){if(l=n.stack.pos(),o=sn===e.tt,R){if(u&&o&&t.sol())return p.REQ=0,n.inBlock=null,n.endBlock=null,!1;if(!u)return n.stack.pushAt(l,p.clone(),"sID",d),s}if(f=e.get(t),r=k,a=0,f)s=o?C:d;else for(c=t.pos;!t.eol();){if(i=t.pos,!(y&&v||!e.get(t))){R&&t.pos>i&&i>c?(s=C,t.bck2(i),a=1):(s=d,f=1);break}g=t.nxt(),v=!v&&g==S}return r=k||y&&v,f||!r&&!a?(n.inBlock=null,n.endBlock=null):n.stack.pushAt(l,p.clone(),"sID",d),s}return!1}}),Un=dn(Kn,{constructor:function(t,n,e,r,l){var o=this;o.tt=t?t:D,o.id=n||null,o.tk=null,o.ts=null,o.REQ=0,o.ERR=0,o.ACTER=0,o.MSG=null,o.min=r||0,o.max=l||R,o.found=0,o.CLONE=["ts","min","max","found"],e&&o.set(e)},ts:null,min:0,max:1,found:0,set:function(t){return t&&(this.ts=En(t)),this},get:function(t,n){var e,r,l,o,u,s,i,c,a,p,f,h,g=this,k=g.tt,m=g.ts,d=m.length;if(x===k){for(i=0,c=0,g.REQ=1,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,e=0;d>e;e++){if(r=m[e].clone().req(1),l=r.get(t,n),i+=r.REQ?1:0,!1!==l)return g.ACTER=r.ACTER,g.MSG=r.MSG,l;r.ERR&&(c++,t.bck2(a))}return g.REQ=i>0,g.ERR=d==c&&i>0,!1}if(N&k){if(h=k&B?1:0,g.REQ=h,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),r=m[0].clone().req(h),l=r.get(t,n),f=g.id+"_"+Gn(),!1!==l){if(!0!==l)for(var e=d-1;e>0;e--)n.stack.pushAt(p+d-e-1,m[e].clone().req(1),"sID",f);return g.ACTER=r.ACTER,g.MSG=r.MSG,l}return r.ERR?(g.ERR=h,t.bck2(a)):h&&r.REQ&&(g.ERR=1),!1}for(i=0,o=g.found,u=g.min,s=g.max,g.ERR=0,g.REQ=0,g.ACTER=0,g.MSG=null,a=t.pos,p=n.stack.pos(),f=g.id+"_"+Gn(),e=0;d>e;e++){if(r=m[e].clone().req(1),l=r.get(t,n),!1!==l){if(++o,s>=o)return g.found=o,n.stack.pushAt(p,g.clone(),"sID",f),g.found=0,g.ACTER=r.ACTER,g.MSG=r.MSG,l;break}r.REQ&&i++,r.ERR&&t.bck2(a)}return g.REQ=u>o,g.ERR=o>s||u>o&&i>0,!1}});var Yn=CodeMirror||{Pass:{toString:function(){return"CodeMirror.Pass"}}};k=null,m="error";{var Jn=dn({constructor:function(t,n){var e=this;e.Extra=t.Extra||{},e.LC=t.Comments.line?t.Comments.line[0]:null,e.BCS=t.Comments.block?t.Comments.block[0][0]:null,e.BCE=t.Comments.block?t.Comments.block[0][1]:null,e.BCC=e.BCL=t.Comments.block?t.Comments.block[0][2]:null,e.DEF=n.DEFAULT,e.ERR=t.Style.error||n.ERROR,e.Keywords=t.Keywords.autocomplete||null,e.Tokens=t.Parser||[],e.cTokens=t.cTokens.length?t.cTokens:null,e.Style=t.Style},Extra:null,LC:null,BCS:null,BCE:null,BCL:null,BCC:null,ERR:null,DEF:null,Keywords:null,cTokens:null,Tokens:null,Style:null,dispose:function(){var t=this;return t.Extra=null,t.LC=null,t.BCS=null,t.BCE=null,t.BCL=null,t.BCC=null,t.ERR=null,t.DEF=null,t.Keywords=null,t.cTokens=null,t.Tokens=null,t.Style=null,t},parse:function(t){t=t||"";var n,e,r,l,o=this,u=t.split(Mn),s=u.length,i=[];for(r=new Hn,r.parseAll=1,n=0;s>n;n++){for(l=new qn(u[n]),e=[];!l.eol();)e.push(o.getToken(l,r));i.push(e)}return i},getToken:function(t,n){var e,r,l,o,u,s=this,i=s.cTokens,c=s.Tokens,a=c.length,p=!!n.parseAll,f=s.Style,h=s.DEF,g=s.ERR;if(t=p?t:qn._(t),u=n.stack,t.sol()&&!u.isEmpty()&&_===u.peek().tt&&u.pop(),(u.isEmpty()||b!==u.peek().tt)&&t.spc())return p?{value:t.cur(1),type:h,error:null}:n.t=h;for(;!u.isEmpty()&&!t.eol();){if(i)for(r=0;re;e++)if(l=c[e],o=l.get(t,n),!1!==o){if(!0!==o)return o=f[o]||h,l.ACTER?(u.empty("sID",l.sID),n.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:n.t=g):p?{value:t.cur(1),type:o,error:null}:n.t=o}else if(l.ERR||l.REQ)return u.empty("sID",l.sID),t.nxt(),n.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:n.t=g;return t.nxt(),n.t=h,p?{value:t.cur(1),type:h,error:null}:n.t=h},indent:function(t,n,e,r){var l=(r.indentUnit||4,Yn.Pass);return l}});t.CodeMirrorGrammar={VERSION:"1.0.1",extend:vn,parse:h,getMode:g}}return t.CodeMirrorGrammar}); \ No newline at end of file +**/!function(t,e,n){"use strict";var r,l="object"==typeof module&&module.exports,o="function"==typeof define&&define.amd;l?module.exports=(module.$deps=module.$deps||{})[e]=module.$deps[e]||n.call(t,{NODE:module})||1:o&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(e)?define(e,["require","exports","module"],function(e,r,l){return n.call(t,{AMD:l})}):e in t||(t[e]=r=n.call(t,{})||1)&&o&&define(e,[],function(){return r})}(this,"CodeMirrorGrammar",function(t){"use strict";function e(t,e){var n,r=this;return(n=t.chr(r.tp,e))?[r.tk,n]:!1}function n(t,e){var n,r=this;return(n=t.chl(r.tp,e))?[r.tk,n]:!1}function r(t,e){var n,r=this;return(n=t.str(r.tp,r.p,e))?[r.tk,n]:!1}function l(t,e){var n,r=this;return(n=t.rex(r.tp,r.p,r.np,r.tg,e))?[r.tk,n]:!1}function o(t,e){var n=this;return!1!==e&&t.end(),[n.tk,""]}function u(t,e,n,r){var l=he(e);if(Y===l)return e;if(r[t])return r[t];n=n||0;var o,u=0;return e&&e.isCharList&&(u=1,delete e.isCharList),o=ie&l?new qe(ie,t,e,n):ee===l?new qe(ee,t,e,n):te&l?u?new qe(ne,t,e,n):new qe(te,t,e,n):re&l?new qe(ue,t,e,n):e,r[t]=o}function s(t,e,n,r,l,o){if(o[t])return o[t];var i,c,a,p,f,h,g,k=0,m=0,d=1;if(i=de(e),a=i.length,1===a)g=u(t,Be(i[0],n,l),0,o);else if(a>1){for(p=(a>>1)+1,c=0;p>=c;c++)f=he(i[c]),h=he(i[a-1-c]),(ee!==f||ee!==h)&&(d=0),re&f||re&h?k=1:(Te(i[c],n)||Te(i[a-1-c],n))&&(m=1);if(!d||r&&te&he(r))if(!r||k||m){for(c=0;a>c;c++)i[c]=re&he(i[c])?s(t+"_"+c,i[c],n,r,l,o):u(t+"_"+c,Be(i[c],n,l),c,o);g=a>1?new Fe(t,i):i[0]}else g=u(t,De(i,r),0,o);else i=i.slice().join(""),i.isCharList=1,g=u(t,i,0,o)}return o[t]=g}function i(t,e,n,r,l){if(l[t])return l[t];var o,s,i,c,a,p,f;for(c=[],a=[],o=Ee(e),s=0,i=o.length;i>s;s++)p=u(t+"_0_"+s,Be(o[s][0],n,r),s,l),f=o[s].length>1?ue!==p.tt||te!==he(o[s][1])||Te(o[s][1],n)?u(t+"_1_"+s,Be(o[s][1],n,r),s,l):o[s][1]:p,c.push(p),a.push(f);return l[t]=new ze(t,c,a)}function c(t,e,n){var r,l,o,u,s,i,c,a,p,f,h,g;if(i=new String(Oe(t)),i.pos=0,1===i.length)f=""+t,e[f]||(e[f]={type:"simple",tokens:t}),t=f;else{for(r=[],l=[],o="",h=[];i.poss[0]&&(s[0]=0),2>s.length?s.push(s[0]):s[1]=s[1].length?parseInt(s[1],10)||R:R,0>s[1]&&(s[1]=0),p=l.pop(),f=""+p+["{",s[0]||"",",",isFinite(s[1])?s[1]||"":"","}"].join(""),n[f]||(n[f]={type:"group",match:[s[0],s[1]],tokens:[p]}),l.push(f)}else{if("}"===a)continue;"|"===a?(l.length>1?(f=""+l.join(" "),n[f]||(n[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[]):"("===a?(h.push([l,r,o]),l=[],r=[],o=""):")"===a&&(l.length>1?(f=""+l.join(" "),n[f]||(n[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),n[f]||(n[f]={type:"group",match:"either",tokens:r})):r.length&&(f=r[0]),r=[],g=h.pop(),l=g[0],r=g[1],o=g[2],p=f,f="("+p+")",n[f]||(n[f]=Re(e[p]||n[p])),l.push(f))}else o+=a;o.length&&(e[o]||n[o]||(e[o]={type:"simple",tokens:o}),l.push(o)),o="",l.length>1?(f=""+l.join(" "),n[f]||(n[f]={type:"group",match:"sequence",tokens:l}),r.push(f)):l.length&&r.push(l[0]),l=[],r.length>1?(f=""+r.join(" | "),n[f]||(n[f]={type:"group",match:"either",tokens:r}),t=f):r.length&&(t=r[0]),r=[]}return t}function a(t,e,n,r,l,o,u,h,g,k,m){var C,v,y,A,T,N,Q,q,V,K,U,Z,H,Y,J,W,X=null;if(null===t)return new Ve(_,"EOL",t);if(""===t)return new Ve(b,"NONSPACE",t);if(!1===t||0===t)return new Ve(O,"EMPTY",t);if(re&he(t)&&(W=t,t="NGRAM_"+W.join("_"),r[t]||(r[t]={type:"ngram",tokens:W})),t=""+t,h[t])return h[t];for(n[t]?(C=n[t],pe&he(C)&&(C=n[t]={type:"simple",tokens:C})):C=r[t]?r[t]:t,te&he(C)&&(C=c(C,n,r),C=n[C]||r[C]);C.extend;)Y=C.extend,J=n[Y]||r[Y],delete C.extend,J&&(pe&he(J)&&(J={type:"simple",tokens:J}),C=Ce(J,C));if("undefined"==typeof C.type&&(C.all||C.sequence?(C.type="group",C.match="sequence",C.tokens=C.all||C.sequence,C.all?delete C.all:delete C.sequence):C.either?(C.type="group",C.match="either",C.tokens=C.either,delete C.either):C.zeroOrMore?(C.type="group",C.match="zeroOrMore",C.tokens=C.zeroOrMore,delete C.zeroOrMore):C.oneOrMore?(C.type="group",C.match="oneOrMore",C.tokens=C.oneOrMore,delete C.oneOrMore):C.zeroOrOne?(C.type="group",C.match="zeroOrOne",C.tokens=C.zeroOrOne,delete C.zeroOrOne):C.comment?(C.type="comment",C.tokens=C.comment,delete C.comment):C.block?(C.type="block",C.tokens=C.block,delete C.block):C["escaped-block"]?(C.type="escaped-block",C.tokens=C["escaped-block"],delete C["escaped-block"]):C.simple?(C.type="simple",C.tokens=C.simple,delete C.simple):C.type="simple"),v=C.type?F[C.type.toUpperCase().replace(Me,"")]:S,S&v){if(""===C.tokens)return X=new Ve(b,t,t),h[t]=X,X;if(null===C.tokens)return X=new Ve(_,t,t),h[t]=X,X;if(!1===C.tokens||0===C.tokens)return X=new Ve(O,t,t),h[t]=X,X}if(C.tokens=de(C.tokens),S&v)C.autocomplete&&f(C,t,m),C.push?(C.action||(C.action=["push",C.push]),delete C.push):C[$]("pop")&&(C.action||(C.action=["pop",C.pop]),delete C.pop),A=null,C.action&&C.action[0]&&("push"===C.action[0]?A=[d,C.action[1]]:"pop"===C.action[0]&&(A=[E,C.action[1]])),y="undefined"==typeof C.combine?"\\b":C.combine,X=new Ve(S,t,s(t,C.tokens.slice(),e,y,o,u)),X.ta=A,h[t]=X;else if(w&v)M&v&&p(C,k),X=new Ke(v,t,i(t,C.tokens.slice(),e,o,u),C.multiline,C.escape,l[t+".inside"]?1:0),h[t]=X,C.interleave&&g.push(X.clone());else if(P&v){for(N=C.tokens.slice(),re&he(C.match)?X=new $e(D,t,null,C.match[0],C.match[1]):(T=z[C.match.toUpperCase()],X=j===T?new $e(j,t,null,0,1):L===T?new $e(L,t,null,0,R):G===T?new $e(G,t,null,1,R):x&T?new $e(x,t,null):new $e(B,t,null)),h[t]=X,Q=[],K=0,U=N.length;U>K;K++)Q=Q.concat(a(N[K],e,n,r,l,o,u,h,g,k,m));X.set(Q)}else if(I&v){for(X=Ee(C.tokens.slice()).slice(),q=[],K=0,U=X.length;U>K;K++)q[K]=X[K].slice(),X[K]=new $e(I,t+"_NGRAM_"+K,null);for(h[t]=X,K=0,U=X.length;U>K;K++){for(V=q[K],Q=[],Z=0,H=V.length;H>Z;Z++)Q=Q.concat(a(V[Z],e,n,r,l,o,u,h,g,k,m));X[K].set(Q)}}return h[t]}function p(t,e){var n,r,l,o,u,s=Ee(t.tokens.slice());for(o=0,u=s.length;u>o;o++)n=s[o][0],r=s[o].length>1?s[o][1]:s[o][0],l=s[o].length>2?s[o][2]:"",null===r?(e.line=e.line||[],e.line.push(n)):(e.block=e.block||[],e.block.push([n,r,l]))}function f(t,e,n){var r=[].concat(de(t.tokens)).map(function(t){return{word:t,meta:e}});n.autocomplete=(n.autocomplete||[]).concat(r)}function h(t){var e,n,r,l,o,u,s,i,c,p,f,h,g,k,m,d;if(t.__parsed)return t;for(f={},h={},g={},m={},d={},k=[],t=Re(t),e=t.RegExpID||null,t.RegExpID=null,delete t.RegExpID,u=t.Lex||{},t.Lex=null,delete t.Lex,s=t.Syntax||{},t.Syntax=null,delete t.Syntax,o=t.Style||{},l=t.Parser||[],r=l.length,n=[],i=0;r>i;i++)c=l[i],p=a(c,e,u,s,o,f,h,g,k,m,d)||null,p&&(re&he(p)?n=n.concat(p):n.push(p));return t.Parser=n,t.cTokens=k,t.Style=o,t.Comments=m,t.Keywords=d,t.Extra=t.Extra||{},t.__parsed=1,t}function g(t,e){var n=new Ye(h(t),{DEFAULT:e||k,ERROR:m}),r=function(t,e){return{startState:function(){return new Ze},copyState:function(t){return t.clone()},token:function(t,e){return n.getToken(t,e)},indent:function(r,l,o){return n.indent(r,l,o,t,e)},lineComment:n.LC,blockCommentStart:n.BCS,blockCommentEnd:n.BCE,blockCommentContinue:n.BCC,blockCommentLead:n.BCL,electricChars:n.Extra.electricChars||!1,fold:n.Extra.fold||!1}};return r.supportGrammarAnnotations=!1,r.validator=function(t){if(!r.supportGrammarAnnotations||!t||!t.length)return[];var e,l,o,u,s,i=[],c=n.parse(t),a=c.length;for(u=0;a>u;u++)if(e=c[u],e&&e.length)for(s=0,o=0;ol;l++)if(e=u[l],le===he(e))for(r in e)e[$](r)&&e[U](r)&&(n=e[r],o=he(n),t[r]=Y&o?0+n:pe&o?n.slice():n);return t},ke=Object.create,me=function(t,e){var n,r=arguments.length,l="constructor";return 0===r?(t=Object,e={}):1===r?(e=t||{},t=Object):(t=t||Object,e=e||{}),e[$](l)||(e[l]=function(){}),n=e[l],delete e[l],n[K]=ge(ke(t[K]),e),n[K][l]=n,n},de=function(t,e){return e||re!==he(t)?[t]:t},Ee=function(t,e){return t=de(t),(e||re!==he(t[0]))&&(t=[t]),t},Re=function(t,e){var n,r,l,o,u=he(t);if(e=!1!==e,le===u){r={};for(l in t)t[$](l)&&t[U](l)&&(n=he(t[l]),r[l]=le===n?e?Re(t[l],e):t[l]:re===n?e?Re(t[l],e):t[l].slice():te&n?t[l].slice():Y&n?0+t[l]:t[l])}else if(re===u)for(o=t.length,r=new Array(o),l=0;o>l;l++)n=he(t[l]),r[l]=le===n?e?Re(t[l],e):t[l]:re===n?e?Re(t[l],e):t[l].slice():te&n?t[l].slice():Y&n?0+t[l]:t[l];else r=te&u?t.slice():Y&u?0+t:t;return r},Ce=function(){var t,e,n,r,l,o,u,s,i,c,a=arguments,p=a.length;if(1>p)return null;for(e=Re(a[0]),n=1;p>n;n++)if(t=a[n])for(r in t)if(t[$](r)&&t[U](r))if(e[$](r)&&e[U](r)){if(i=he(e[r]),c=he(t[r]),le===i&&le===c)e[r]=Ce(e[r],t[r]);else if(re===i&&re===c){if(u=e[r],s=t[r],o=s.length,!o)continue;if(u.length)for(l=0;o>l;l++)0>u.indexOf(s[l])&&u.push(s[l]);else e[r]=s.slice()}}else e[r]=Re(t[r]);return e},ve=/([.*+?^${}()|[\]\/\\\-])/g,ye=function(t){return t.replace(ve,"\\$1")},Se=/\$(\d{1,2})/g,_e=function(t,e){var n,r,l,o;for(o=function(t,n){return e[1+parseInt(n,10)]},n=t.split("$$"),l=n.length,r=0;l>r;r++)n[r]=n[r].replace(Se,o);return n.join("$")},be=/^\s+|\s+$/g,Oe=String[K].trim?function(t){return t.trim()}:function(t){return t.replace(be,"")},we=function(t,e){return e.length-t.length},Ae=/\r\n|\r|\n/g,Me=/[\-_]/g,xe=/^([{}()*+?|'"]|\s)/,Te=function(t,e){return te&he(e)&&te&he(t)&&e.length&&e.length<=t.length&&e==t.substr(0,e.length)},Be=function(t,e,n){if(!t||Y===he(t))return t;var r,l=e?e.length||0:0;if(l&&e==t.substr(0,l)){var o,u,s,i,r,c,a=t.substr(l),p=a[0],f="";for(r=a.length;r--&&(c=a[r],p!=c);)"i"==c.toLowerCase()&&(f="i");return o=a.substring(1,r),u="^("+o+")",n[u]||(s=new RegExp(u,f),i={peek:null,negativepeek:null},n[u]=[s,i]),n[u]}return t},De=function(t,e){var n={},r="",l=he(e);(te===l||ee===l)&&(r=e);var o=t.sort(we).map(function(t){return n[t.charAt(0)]=1,ye(t)}).join("|");return[new RegExp("^("+o+")"+r),{peek:n,negativepeek:null},1]},je=0,Le=function(){return++je},Ge=function(t){return[t||"uuid",++je,(new Date).getTime()].join("_")},Pe=Math.max,Ie=/^[\s\u00a0]+/,Ne=/[^\s\u00a0]/,Qe=me({constructor:function(t){var e=this;e._=null,e.s=t?""+t:"",e.start=e.pos=0,e.lCP=e.lCV=0,e.lS=0},_:null,s:"",start:0,pos:0,lCP:0,lCV:0,lS:0,dispose:function(){var t=this;return t._=null,t.s=null,t.start=null,t.pos=null,t.lCP=null,t.lCV=null,t.lS=null,t},toString:function(){return this.s},sol:function(){return 0===this.pos},eol:function(){return this.pos>=this.s.length},chr:function(t,e){var n=this,r=n.s.charAt(n.pos)||null;return r&&t===r?(!1!==e&&(n.pos+=1,n._&&(n._.pos=n.pos)),r):!1},chl:function(t,e){var n=this,r=n.s.charAt(n.pos)||null;return r&&-10?!1:(!1!==l&&(u.pos+=o[r||0].length,u._&&(u._.pos=u.pos)),o)},spc:function(t){var e,n=this,r=n.pos,l=n.s.slice(r);return(e=l.match(Ie))?(!1!==t&&(n.pos+=e[0].length,n._&&(n._.pos=n.pos)),1):0},end:function(){var t=this;return t.pos=t.s.length,t._&&(t._.pos=t.pos),t},nxt:function(){var t,e=this,n=e.s;return e.poso;++o)u+=" "==t.charAt(o)?n-u%n:1;return u},Qe._=function(t){var e=new Qe;return e._=t,e.s=""+t.string,e.start=t.start,e.pos=t.pos,e.lCP=t.lastColumnPos,e.lCV=t.lastColumnValue,e.lS=t.lineStart,e};var qe,ze,Fe,Ve,Ke,$e,Ue=me({constructor:function(t){this._=t||[]},_:null,dispose:function(){var t=this;return t._=null,t},toString:function(){return this._.slice().reverse().join("\n")},clone:function(){return new Ue(this._.slice())},isEmpty:function(){return 0>=this._.length},pos:function(){return this._.length},peek:function(t){var e=this,n=e._;if(t=arguments.length?t:-1,n.length){if(0>t&&0<=n.length+t)return n[n.length+t];if(t>=0&&tn;n++)if(r=o[n].get(t,e))return s?[n,r[1]]:r;return!1}}),ze=me(qe,{constructor:function(t,e,n){var r=this;r.mt=y,r.tn=t,r.s=new Fe(r.tn+"_Start",e,!1),r.e=n},s:null,e:null,get:function(t,e){var n,r=this,l=r.s,o=r.e;if(n=l.get(t,e)){var u,s=o[n[0]],i=he(s),c=l.ms[n[0]].tt;return ue===c&&(Y===i?(u=n[1][s+1],s=new qe(u.length>1?te:ee,r.tn+"_End",u)):te===i&&(u=_e(s,n[1]),s=new qe(u.length>1?te:ee,r.tn+"_End",u))),s}return!1}}),Ve=me({constructor:function(t,e,n){var r=this;r.tt=t||S,r.id=e,r.tk=n,r.REQ=0,r.ERR=0,r.ACTER=0,r.MSG=null,r.CLONE=["tk"]},sID:null,id:null,tt:null,tk:null,ta:null,REQ:0,ERR:0,ACTER:0,MSG:null,CLONE:null,act:function(t,e){var n,r,l=this,o=l.ta||null,u=e.data;if(o)if(n=o[0],r=o[1],E===n)if(r){if(t&&(r=Y===he(r)?t[1][r]:_e(r,t[1])),u.isEmpty()||r!==u.peek())return l.MSG='Token "'+r+'" No Match',u.pop(),1;u.pop()}else u.pop();else d===n&&r&&(t&&(r=Y===he(r)?t[1][r]:_e(r,t[1])),u.push(r));return 0},get:function(t,e){var n=this,r=n.ta,l=n.tk,o=n.tt,u=n.id,s=null;if(n.MSG=null,n.ACTER=0,O===o)return n.ERR=0,n.REQ=0,!0;if(_===o){if(t.spc(),t.eol())return u}else if(b===o)n.ERR=n.REQ&&t.spc()&&!t.eol()?1:0,n.REQ=0;else if(s=l.get(t))return r&&(n.ACTER=n.act(s,e)),u;return!1},req:function(t){return this.REQ=!!t,this},err:function(){var t=this;return t.MSG?t.MSG:t.REQ?'Token "'+t.id+'" Expected':'Syntax Error: "'+t.id+'"'},clone:function(){var t,e,n,r=this,l=r.CLONE;if(t=new r.constructor,t.tt=r.tt,t.id=r.id,t.ta=r.ta?r.ta.slice():r.ta,l&&l.length)for(e=0,n=l.length;n>e;e++)t[l[e]]=r[l[e]];return t},toString:function(){var t=this;return["[","Tokenizer: ",t.id,", Matcher: ",t.tk?t.tk.toString():null,"]"].join("")}}),Ke=me(Ve,{constructor:function(t,e,n,r,l,o){var u=this;u.tt=t,u.id=e,u.tk=n,u.REQ=0,u.ERR=0,u.ACTER=0,u.MSG=null,u.mline="undefined"==typeof r?1:r,u.esc=l||"\\",u.inter=o,u.CLONE=["tk","mline","esc","inter"]},inter:0,mline:0,esc:null,get:function(t,e){var n,r,l,o,u,s,i,c,a,p=this,f=0,h=0,g="",k=p.mline,m=p.tk,d=p.id,E=p.tt,R=p.inter,C=R?d+".inside":d,v=0,y=A===E,S=p.esc;if(p.MSG=null,p.ACTER=0,M===E&&(p.REQ=0),u=0,e.inBlock===d?(h=1,n=e.endBlock,u=1,s=C):!e.inBlock&&(n=m.get(t))&&(h=1,e.inBlock=d,e.endBlock=n,s=d),h){if(l=e.stack.pos(),o=ie===n.tt,R){if(u&&o&&t.sol())return p.REQ=0,e.inBlock=null,e.endBlock=null,!1;if(!u)return e.stack.pushAt(l,p.clone(),"sID",d),s}if(f=n.get(t),r=k,a=0,f)s=o?C:d;else for(c=t.pos;!t.eol();){if(i=t.pos,!(y&&v||!n.get(t))){R&&t.pos>i&&i>c?(s=C,t.bck2(i),a=1):(s=d,f=1);break}g=t.nxt(),v=!v&&g==S}return r=k||y&&v,f||!r&&!a?(e.inBlock=null,e.endBlock=null):e.stack.pushAt(l,p.clone(),"sID",d),s}return!1}}),$e=me(Ve,{constructor:function(t,e,n,r,l){var o=this;o.tt=t?t:D,o.id=e||null,o.tk=null,o.ts=null,o.REQ=0,o.ERR=0,o.ACTER=0,o.MSG=null,o.min=r||0,o.max=l||R,o.found=0,o.CLONE=["ts","min","max","found"],n&&o.set(n)},ts:null,min:0,max:1,found:0,set:function(t){return t&&(this.ts=de(t)),this},get:function(t,e){var n,r,l,o,u,s,i,c,a,p,f,h,g=this,k=g.tt,m=g.ts,d=m.length;if(x===k){for(i=0,c=0,g.REQ=1,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,n=0;d>n;n++){if(r=m[n].clone().req(1),l=r.get(t,e),i+=r.REQ?1:0,!1!==l)return g.ACTER=r.ACTER,g.MSG=r.MSG,l;r.ERR&&(c++,t.bck2(a))}return g.REQ=i>0,g.ERR=d==c&&i>0,!1}if(N&k){if(h=k&B?1:0,g.REQ=h,g.ERR=0,g.ACTER=0,g.MSG=null,a=t.pos,p=e.stack.pos(),r=m[0].clone().req(h),l=r.get(t,e),f=g.id+"_"+Le(),!1!==l){if(!0!==l)for(var n=d-1;n>0;n--)e.stack.pushAt(p+d-n-1,m[n].clone().req(1),"sID",f);return g.ACTER=r.ACTER,g.MSG=r.MSG,l}return r.ERR?(g.ERR=h,t.bck2(a)):h&&r.REQ&&(g.ERR=1),!1}for(i=0,o=g.found,u=g.min,s=g.max,g.ERR=0,g.REQ=0,g.ACTER=0,g.MSG=null,a=t.pos,p=e.stack.pos(),f=g.id+"_"+Le(),n=0;d>n;n++){if(r=m[n].clone().req(1),l=r.get(t,e),!1!==l){if(++o,s>=o)return g.found=o,e.stack.pushAt(p,g.clone(),"sID",f),g.found=0,g.ACTER=r.ACTER,g.MSG=r.MSG,l;break}r.REQ&&i++,r.ERR&&t.bck2(a)}return g.REQ=u>o,g.ERR=o>s||u>o&&i>0,!1}});var He=CodeMirror||{Pass:{toString:function(){return"CodeMirror.Pass"}}};k=null,m="error";{var Ye=me({constructor:function(t,e){var n=this;n.Extra=t.Extra||{},n.LC=t.Comments.line?t.Comments.line[0]:null,n.BCS=t.Comments.block?t.Comments.block[0][0]:null,n.BCE=t.Comments.block?t.Comments.block[0][1]:null,n.BCC=n.BCL=t.Comments.block?t.Comments.block[0][2]:null,n.DEF=e.DEFAULT,n.ERR=t.Style.error||e.ERROR,n.Keywords=t.Keywords.autocomplete||null,n.Tokens=t.Parser||[],n.cTokens=t.cTokens.length?t.cTokens:null,n.Style=t.Style},Extra:null,LC:null,BCS:null,BCE:null,BCL:null,BCC:null,ERR:null,DEF:null,Keywords:null,cTokens:null,Tokens:null,Style:null,dispose:function(){var t=this;return t.Extra=null,t.LC=null,t.BCS=null,t.BCE=null,t.BCL=null,t.BCC=null,t.ERR=null,t.DEF=null,t.Keywords=null,t.cTokens=null,t.Tokens=null,t.Style=null,t},parse:function(t){t=t||"";var e,n,r,l,o=this,u=t.split(Ae),s=u.length,i=[];for(r=new Ze,r.parseAll=1,e=0;s>e;e++){for(l=new Qe(u[e]),n=[];!l.eol();)n.push(o.getToken(l,r));i.push(n)}return i},getToken:function(t,e){var n,r,l,o,u,s=this,i=s.cTokens,c=s.Tokens,a=c.length,p=!!e.parseAll,f=s.Style,h=s.DEF,g=s.ERR;if(t=p?t:Qe._(t),u=e.stack,t.sol()&&!u.isEmpty()&&_===u.peek().tt&&u.pop(),(u.isEmpty()||b!==u.peek().tt)&&t.spc())return p?{value:t.cur(1),type:h,error:null}:e.t=h;for(;!u.isEmpty()&&!t.eol();){if(i)for(r=0;rn;n++)if(l=c[n],o=l.get(t,e),!1!==o){if(!0!==o)return o=f[o]||h,l.ACTER?(u.empty("sID",l.sID),e.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:e.t=g):p?{value:t.cur(1),type:o,error:null}:e.t=o}else if(l.ERR||l.REQ)return u.empty("sID",l.sID),t.nxt(),e.t=o=g,p?{value:t.cur(1),type:g,error:l.err()}:e.t=g;return t.nxt(),e.t=h,p?{value:t.cur(1),type:h,error:null}:e.t=h},indent:function(t,e,n,r){var l=(r.indentUnit||4,He.Pass);return l}});t.CodeMirrorGrammar={VERSION:"1.0.2",clone:Re,extend:Ce,parse:h,getMode:g}}return t.CodeMirrorGrammar}); \ No newline at end of file diff --git a/src/main.js b/src/main.js index 315df20..4232817 100644 --- a/src/main.js +++ b/src/main.js @@ -360,6 +360,20 @@ var CodeMirrorGrammar = exports['@@MODULE_NAME@@'] = { VERSION: "@@VERSION@@", + // clone a grammar + /**[DOC_MARKDOWN] + * __Method__: `clone` + * + * ```javascript + * cloned = CodeMirrorGrammar.clone( grammar [, deep=true] ); + * ``` + * + * Clone (deep) a `grammar` + * + * Utility to clone objects efficiently + [/DOC_MARKDOWN]**/ + clone: clone, + // extend a grammar using another base grammar /**[DOC_MARKDOWN] * __Method__: `extend` diff --git a/src/utils.js b/src/utils.js index 7f829b3..82d9297 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,53 +1,44 @@ -var undef = undefined, PROTO = 'prototype', HAS = 'hasOwnProperty', IS_ENUM = 'propertyIsEnumerable', +var undef = undefined, + PROTO = 'prototype', HAS = 'hasOwnProperty', IS_ENUM = 'propertyIsEnumerable', Keys = Object.keys, AP = Array[PROTO], OP = Object[PROTO], FP = Function[PROTO], toString = OP.toString, // types - //T_INF = 5, - T_NUM = 4, T_NAN = 5, T_BOOL = 8, + T_NUM = 4, T_INF = 5, T_NAN = 6, T_BOOL = 8, T_STR = 16, T_CHAR = 17, T_CHARLIST = 18, T_ARRAY = 32, T_OBJ = 64, T_FUNC = 128, T_REGEX = 256, T_DATE = 512, T_NULL = 1024, T_UNDEF = 2048, T_UNKNOWN = 4096, T_STR_OR_ARRAY = T_STR|T_ARRAY, T_OBJ_OR_ARRAY = T_OBJ|T_ARRAY, - TO_STRING = { + STRING_TYPE = { + "[object Number]" : T_NUM, + "[object String]" : T_STR, "[object Array]" : T_ARRAY, "[object RegExp]" : T_REGEX, "[object Date]" : T_DATE, - "[object Number]" : T_NUM, - "[object String]" : T_STR, "[object Function]" : T_FUNC, "[object Object]" : T_OBJ }, get_type = function( v ) { - var /*type_of,*/ to_string; - - if (null === v) return T_NULL; - else if (true === v || false === v) return T_BOOL; - else if (undef === v /*|| "undefined" === type_of*/) return T_UNDEF; - - //type_of = typeOf(v); - to_string = toString.call( v ); - //to_string = TO_STRING[HAS](to_string) ? TO_STRING[to_string] : T_UNKNOWN; - to_string = TO_STRING[to_string] || T_UNKNOWN; - - //if (undef === v /*|| "undefined" === type_of*/) return T_UNDEF; - if (T_NUM === to_string || v instanceof Number) return isNaN(v) ? T_NAN : T_NUM; - else if (T_STR === to_string || v instanceof String) return (1 === v.length) ? T_CHAR : T_STR; - else if (T_ARRAY === to_string || v instanceof Array) return T_ARRAY; - else if (T_REGEX === to_string || v instanceof RegExp) return T_REGEX; - else if (T_DATE === to_string || v instanceof Date) return T_DATE; - else if (T_FUNC === to_string || v instanceof Function) return T_FUNC; - else if (T_OBJ === to_string) return T_OBJ; - // unkown type - return T_UNKNOWN; + if ( null === v ) return T_NULL; + else if ( true === v || false === v || + v instanceof Boolean ) return T_BOOL; + else if ( undef === v ) return T_UNDEF; + var TYPE = STRING_TYPE[ toString.call( v ) ] || T_UNKNOWN; + if ( T_NUM === TYPE || v instanceof Number ) return isNaN(v) ? T_NAN : (isFinite(v) ? T_NUM : T_INF); + else if ( T_STR === TYPE || v instanceof String ) return 1 === v.length ? T_CHAR : T_STR; + else if ( T_ARRAY === TYPE || v instanceof Array ) return T_ARRAY; + else if ( T_REGEX === TYPE || v instanceof RegExp ) return T_REGEX; + else if ( T_DATE === TYPE || v instanceof Date ) return T_DATE; + else if ( T_FUNC === TYPE || v instanceof Function ) return T_FUNC; + else if ( T_OBJ === TYPE ) return T_OBJ; + return T_UNKNOWN; }, Merge = function(/* var args here.. */) { - var args = arguments, argslen, - o1, o2, v, p, i, T; - o1 = args[0] || {}; - argslen = args.length; + var args = arguments, argslen = args.length, + o, o2, v, p, i, T; + o = args[0] || {}; for (i=1; i