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