rsc3/doc-schelp/Help-3.12.2/lib/codemirror-addon-simple-5.39.2.min.js

2 lines
5.5 KiB
JavaScript
Raw Permalink Normal View History

2022-08-24 13:53:18 +00:00
(function(mod){if(typeof exports=="object"&&typeof module=="object")mod(require("../../lib/codemirror"));else if(typeof define=="function"&&define.amd)define(["../../lib/codemirror"],mod);else mod(CodeMirror)})(function(CodeMirror){"use strict";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=false;for(var state in states)if(state!=meta&&states.hasOwnProperty(state)){var list=states_[state]=[],orig=states[state];for(var i=0;i<orig.length;i++){var data=orig[i];list.push(new Rule(data,states));if(data.indent||data.dedent)hasIndentation=true}}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)};if(state.localState)s.localState=CodeMirror.copyState(state.local.mode,state.localState);if(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)if(meta.hasOwnProperty(prop))mode[prop]=meta[prop];return mode};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="";if(val instanceof RegExp){if(val.ignoreCase)flags="i";val=val.source}else{val=String(val)}return new RegExp((caret===false?"":"^")+"(?:"+val+")",flags)}function asToken(val){if(!val)return null;if(val.apply)return val;if(typeof val=="string")return val.replace(/\./g," ");var result=[];for(var i=0;i<val.length;i++)result.push(val[i]&&val[i].replace(/\./g," "));return result}function Rule(data,states){if(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();if(state.pending.length==0)state.pending=null;stream.pos+=pend.text.length;return pend.token}if(state.local){if(state.local.end&&stream.match(state.local.end)){var tok=state.local.endToken||null;state.local=state.localState=null;return tok}else{var tok=state.local.mode.token(stream,state.localState),m;if(state.local.endScan&&(m=state.local.endScan.exec(stream.current())))stream.pos=stream.start+m.index;return tok}}var curState=states[state.state];for(var i=0;i<curState.length;i++){var rule=curState[i];var matches=(!rule.data.sol||stream.sol())&&stream.match(rule.regex);if(matches){if(rule.data.next){state.state=rule.data.next}else if(rule.data.push){(state.stack||(state.stack=[])).push(state.state);state.state=rule.data.push}else if(rule.data.pop&&state.stack&&state.stack.length){state.state=state.stack.pop()}if(rule.data.mode)enterLocalMode(config,state,rule.data.mode,rule.token);if(rule.data.indent)state.indent.push(stream.indentation()+config.indentUnit);if(rule.data.dedent)state.indent.pop();var token=rule.token;if(token&&token.apply)token=token(matches);if(matches.length>2&&rule.token&&typeof rule.token!="string"){state.pending=[];for(var j=2;j<matches.length;j++)if(matches[j])state.pending.push({text:matches[j],token:rule.token[j-1]});stream.backUp(matches[0].length-(matches[1]?matches[1].length:0));return token[0]}else if(token&&token.join){return token[0]}else{return token}}}stream.next();return null}}function cmp(a,b){if(a===b)return true;if(!a||typeof a!="object"||!b||typeof b!="object")return false;var props=0;for(var prop in a)if(a.hasOwnProper