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