!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(S){"use strict";function m(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 v(e,t){(e.next||e.push)&&m(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 1;if(e&&"object"==typeof e&&t&&"object"==typeof t){var n=0;for(var a in e)if(e.hasOwnProperty(a)){if(!t.hasOwnProperty(a)||!d(e[a],t[a]))return;n++}for(var a in t)t.hasOwnProperty(a)&&n--;return 0==n}}function k(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||S.getMode(e,n.spec),l=r?r.state:S.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}}S.defineSimpleMode=function(e,t){S.defineMode(e,function(e){return S.simpleMode(e,t)})},S.simpleMode=function(e,t){m(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 v(d,t)),(d.indent||d.dedent)&&(r=!0)}var c,p,f,u,h={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=S.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:S.copyState(n.mode,n.state),next:t.persistentStates};return t},token:(u=e,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;return a=t.local.mode.token(e,t.localState),t.local.endScan&&(r=t.local.endScan.exec(e.current()))&&(e.pos=e.start+r.index),a}for(var o=f[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&&k(u,t,l.data.mode,l.token),l.data.indent&&t.indent.push(e.indentation()+u.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}),innerMode:function(e){return e.local&&{mode:e.local.mode,state:e.localState}},indent:(c=f=n,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||p.dontIndentStates&&-1<function(e,t){for(var n=0;n<t.length;n++)if(t[n]===e)return!0}(e.state,p.dontIndentStates))return S.Pass;var a=e.indent.length-1,r=c[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=c[i.next||i.push]),t=t.slice(l[0].length);continue e}}}break}return a<0?0:e.indent[a]})};if(p=a)for(var g in a)a.hasOwnProperty(g)&&(h[g]=a[g]);return h}});