function simpleMode(states){ensureState(states,"start");var states_={},meta=states.languageData||{},hasIndentation=!1;for(var state in states)if(state!=meta&&states.hasOwnProperty(state))for(var list=states_[state]=[],orig=states[state],i=0;i<orig.length;i++){var data=orig[i];list.push(new Rule(data,states)),(data.indent||data.dedent)&&(hasIndentation=!0)}return{name:meta.name,startState:function(){return{state:"start",pending:null,indent:hasIndentation?[]:null}},copyState:function(state2){var s={state:state2.state,pending:state2.pending,indent:state2.indent&&state2.indent.slice(0)};return state2.stack&&(s.stack=state2.stack.slice(0)),s},token:tokenFunction(states_),indent:indentFunction(states_,meta),mergeTokens:meta.mergeTokens,languageData:meta}}function ensureState(states,name){if(!states.hasOwnProperty(name))throw new Error("Undefined state "+name+" in simple mode")}function Rule(data,states){(data.next||data.push)&&ensureState(states,data.next||data.push),this.regex=function(val){if(!val)return/(?:)/;var flags="";return val instanceof RegExp?(val.ignoreCase&&(flags="i"),val.unicode&&(flags+="u"),val=val.source):val=String(val),new RegExp("^(?:"+val+")",flags)}(data.regex),this.token=function(val){if(!val)return null;if(val.apply)return val;if("string"==typeof val)return val.replace(/\./g," ");for(var result=[],i=0;i<val.length;i++)result.push(val[i]&&val[i].replace(/\./g," "));return result}(data.token),this.data=data}function tokenFunction(states){return function(stream,state){if(state.pending){var pend=state.pending.shift();return 0==state.pending.length&&(state.pending=null),stream.pos+=pend.text.length,pend.token}for(var curState=states[state.state],i=0;i<curState.length;i++){var rule=curState[i],matches=(!rule.data.sol||stream.sol())&&stream.match(rule.regex);if(matches){rule.data.next?state.state=rule.data.next:rule.data.push?((state.stack||(state.stack=[])).push(state.state),state.state=rule.data.push):rule.data.pop&&state.stack&&state.stack.length&&(state.state=state.stack.pop()),rule.data.indent&&state.indent.push(stream.indentation()+stream.indentUnit),rule.data.dedent&&state.indent.pop();var token=rule.token;if(token&&token.apply&&(token=token(matches)),matches.length>2&&rule.token&&"string"!=typeof rule.token){state.pending=[];for(var j=2;j<matches.length;j++)matches[j]&&state.pending.push({text:matches[j],token:rule.token[j-1]});return stream.backUp(matches[0].length-(matches[1]?matches[1].length:0)),token[0]}return token&&token.join?token[0]:token}}return stream.next(),null}}function indentFunction(states,meta){return function(state,textAfter){if(null==state.indent||meta.dontIndentStates&&meta.dontIndentStates.indexOf(state.state)>-1)return null;var pos=state.indent.length-1,rules=states[state.state];scan:for(;;){for(var i=0;i<rules.length;i++){var rule=rules[i];if(rule.data.dedent&&!1!==rule.data.dedentIfLineStart){var m=rule.regex.exec(textAfter);if(m&&m[0]){pos--,(rule.next||rule.push)&&(rules=states[rule.next||rule.push]),textAfter=textAfter.slice(m[0].length);continue scan}}}break}return pos<0?0:state.indent[pos]}}export{simpleMode as s};
