(function(k){"object"==typeof exports&&"object"==typeof module?k(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],k):k(CodeMirror)})(function(k){function r(d,e){if(!d.hasOwnProperty(e))throw Error("Undefined state "+e+" in simple mode");}function q(d,e){if(!d)return/(?:)/;var b="";d instanceof RegExp?(d.ignoreCase&&(b="i"),d=d.source):d=String(d);return new RegExp((!1===e?"":"^")+"(?:"+d+")",b)}function u(d,e){(d.next||d.push)&&r(e,d.next||d.push);
this.regex=q(d.regex);var b;if(b=d.token)if("string"==typeof b)b=b.replace(/\./g," ");else{for(var a=[],c=0;c<b.length;c++)a.push(b[c]&&b[c].replace(/\./g," "));b=a}else b=null;this.token=b;this.data=d}function v(d,e){return function(b,a){if(a.pending){var c=a.pending.shift();0==a.pending.length&&(a.pending=null);b.pos+=c.text.length;return c.token}if(a.local){if(a.local.end&&b.match(a.local.end))c=a.local.endToken||null,a.local=a.localState=null;else{var c=a.local.mode.token(b,a.localState),g;a.local.endScan&&
(g=a.local.endScan.exec(b.current()))&&(b.pos=b.start+g.index)}return c}for(var h=d[a.state],f=0;f<h.length;f++)if(c=h[f],g=(!c.data.sol||b.sol())&&b.match(c.regex)){c.data.next?a.state=c.data.next:c.data.push?((a.stack||(a.stack=[])).push(a.state),a.state=c.data.push):c.data.pop&&a.stack&&a.stack.length&&(a.state=a.stack.pop());if(c.data.mode){var l=e,h=a,f=c.data.mode,n=c.token,m=void 0;if(f.persistent)for(var p=h.persistentStates;p&&!m;p=p.next)if(f.spec?t(f.spec,p.spec):f.mode==p.mode)m=p;l=m?
m.mode:f.mode||k.getMode(l,f.spec);p=m?m.state:k.startState(l);f.persistent&&!m&&(h.persistentStates={mode:l,spec:f.spec,state:p,next:h.persistentStates});h.localState=p;h.local={mode:l,end:f.end&&q(f.end),endScan:f.end&&!1!==f.forceEnd&&q(f.end,!1),endToken:n&&n.join?n[n.length-1]:n}}c.data.indent&&a.indent.push(b.indentation()+e.indentUnit);c.data.dedent&&a.indent.pop();if(2<g.length){a.pending=[];for(h=2;h<g.length;h++)g[h]&&a.pending.push({text:g[h],token:c.token[h-1]});b.backUp(g[0].length-(g[1]?
g[1].length:0));return c.token[0]}return c.token&&c.token.join?c.token[0]:c.token}b.next();return null}}function t(d,e){if(d===e)return!0;if(!d||"object"!=typeof d||!e||"object"!=typeof e)return!1;var b=0,a;for(a in d)if(d.hasOwnProperty(a)){if(!e.hasOwnProperty(a)||!t(d[a],e[a]))return!1;b++}for(a in e)e.hasOwnProperty(a)&&b--;return 0==b}function w(d,e){return function(b,a,c){if(b.local&&b.local.mode.indent)return b.local.mode.indent(b.localState,a,c);if(!(c=null==b.indent||b.local)&&(c=e.dontIndentStates)){a:{c=
e.dontIndentStates;for(var g=0;g<c.length;g++)if(c[g]===b.state){c=!0;break a}c=void 0}c=-1<c}if(c)return k.Pass;c=b.indent.length-1;g=d[b.state];a:for(;;){for(var h=0;h<g.length;h++){var f=g[h];if(f.data.dedent&&!1!==f.data.dedentIfLineStart){var l=f.regex.exec(a);if(l&&l[0]){c--;if(f.next||f.push)g=d[f.next||f.push];a=a.slice(l[0].length);continue a}}}break}return 0>c?0:b.indent[c]}}k.defineSimpleMode=function(d,e){k.defineMode(d,function(b){return k.simpleMode(b,e)})};k.simpleMode=function(d,e){r(e,
"start");var b={},a=e.meta||{},c=!1,g;for(g in e)if(g!=a&&e.hasOwnProperty(g))for(var h=b[g]=[],f=e[g],l=0;l<f.length;l++){var n=f[l];h.push(new u(n,e));if(n.indent||n.dedent)c=!0}b={startState:function(){return{state:"start",pending:null,local:null,localState:null,indent:c?[]:null}},copyState:function(a){var b={state:a.state,pending:a.pending,local:a.local,localState:null,indent:a.indent&&a.indent.slice(0)};a.localState&&(b.localState=k.copyState(a.local.mode,a.localState));a.stack&&(b.stack=a.stack.slice(0));
for(var c=a.persistentStates;c;c=c.next)b.persistentStates={mode:c.mode,spec:c.spec,state:c.state==a.localState?b.localState:k.copyState(c.mode,c.state),next:b.persistentStates};return b},token:v(b,d),innerMode:function(a){return a.local&&{mode:a.local.mode,state:a.localState}},indent:w(b,a)};if(a)for(var m in a)a.hasOwnProperty(m)&&(b[m]=a[m]);return b}});