forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple.js
More file actions
1 lines (1 loc) · 5.42 KB
/
Copy pathsimple.js
File metadata and controls
1 lines (1 loc) · 5.42 KB
1
!function(mod){"object"==typeof exports&&"object"==typeof module?mod(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):mod(CodeMirror)}(function(CodeMirror){"use strict";function ensureState(states,name){if(!states.hasOwnProperty(name))throw new Error("Undefined state "+name+" in simple mode")}function toRegex(val,caret){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((!1===caret?"":"^")+"(?:"+val+")",flags)}function asToken(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}function Rule(data,states){(data.next||data.push)&&ensureState(states,data.next||data.push),this.regex=toRegex(data.regex),this.token=asToken(data.token),this.data=data}function tokenFunction(states,config){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}if(state.local){if(state.local.end&&stream.match(state.local.end)){var tok=state.local.endToken||null;return state.local=state.localState=null,tok}var tok=state.local.mode.token(stream,state.localState),m;return state.local.endScan&&(m=state.local.endScan.exec(stream.current()))&&(stream.pos=stream.start+m.index),tok}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.mode&&enterLocalMode(config,state,rule.data.mode,rule.token),rule.data.indent&&state.indent.push(stream.indentation()+config.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){for(var j=2;j<matches.length;j++)matches[j]&&(state.pending||(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 cmp(a,b){if(a===b)return!0;if(!a||"object"!=typeof a||!b||"object"!=typeof b)return!1;var props=0;for(var prop in a)if(a.hasOwnProperty(prop)){if(!b.hasOwnProperty(prop)||!cmp(a[prop],b[prop]))return!1;props++}for(var prop in b)b.hasOwnProperty(prop)&&props--;return 0==props}function enterLocalMode(config,state,spec,token){var pers;if(spec.persistent)for(var p=state.persistentStates;p&&!pers;p=p.next)(spec.spec?cmp(spec.spec,p.spec):spec.mode==p.mode)&&(pers=p);var mode=pers?pers.mode:spec.mode||CodeMirror.getMode(config,spec.spec),lState=pers?pers.state:CodeMirror.startState(mode);spec.persistent&&!pers&&(state.persistentStates={mode:mode,spec:spec.spec,state:lState,next:state.persistentStates}),state.localState=lState,state.local={mode:mode,end:spec.end&&toRegex(spec.end),endScan:spec.end&&!1!==spec.forceEnd&&toRegex(spec.end,!1),endToken:token&&token.join?token[token.length-1]:token}}function indexOf(val,arr){for(var i=0;i<arr.length;i++)if(arr[i]===val)return!0}function indentFunction(states,meta){return function(state,textAfter,line){if(state.local&&state.local.mode.indent)return state.local.mode.indent(state.localState,textAfter,line);if(null==state.indent||state.local||meta.dontIndentStates&&indexOf(state.state,meta.dontIndentStates)>-1)return CodeMirror.Pass;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]}}CodeMirror.defineSimpleMode=function(name,states){CodeMirror.defineMode(name,function(config){return CodeMirror.simpleMode(config,states)})},CodeMirror.simpleMode=function(config,states){ensureState(states,"start");var states_={},meta=states.meta||{},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)}var mode={startState:function(){return{state:"start",pending:null,local:null,localState:null,indent:hasIndentation?[]:null}},copyState:function(state){var s={state:state.state,pending:state.pending,local:state.local,localState:null,indent:state.indent&&state.indent.slice(0)};state.localState&&(s.localState=CodeMirror.copyState(state.local.mode,state.localState)),state.stack&&(s.stack=state.stack.slice(0));for(var pers=state.persistentStates;pers;pers=pers.next)s.persistentStates={mode:pers.mode,spec:pers.spec,state:pers.state==state.localState?s.localState:CodeMirror.copyState(pers.mode,pers.state),next:s.persistentStates};return s},token:tokenFunction(states_,config),innerMode:function(state){return state.local&&{mode:state.local.mode,state:state.localState}},indent:indentFunction(states_,meta)};if(meta)for(var prop in meta)meta.hasOwnProperty(prop)&&(mode[prop]=meta[prop]);return mode}});