Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/addon/mode/multiplex.js
1293 views
1
CodeMirror.multiplexingMode = function(outer /*, others */) {
2
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
3
var others = Array.prototype.slice.call(arguments, 1);
4
var n_others = others.length;
5
6
function indexOf(string, pattern, from) {
7
if (typeof pattern == "string") return string.indexOf(pattern, from);
8
var m = pattern.exec(from ? string.slice(from) : string);
9
return m ? m.index + from : -1;
10
}
11
12
return {
13
startState: function() {
14
return {
15
outer: CodeMirror.startState(outer),
16
innerActive: null,
17
inner: null
18
};
19
},
20
21
copyState: function(state) {
22
return {
23
outer: CodeMirror.copyState(outer, state.outer),
24
innerActive: state.innerActive,
25
inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
26
};
27
},
28
29
token: function(stream, state) {
30
if (!state.innerActive) {
31
var cutOff = Infinity, oldContent = stream.string;
32
for (var i = 0; i < n_others; ++i) {
33
var other = others[i];
34
var found = indexOf(oldContent, other.open, stream.pos);
35
if (found == stream.pos) {
36
stream.match(other.open);
37
state.innerActive = other;
38
state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
39
return other.delimStyle;
40
} else if (found != -1 && found < cutOff) {
41
cutOff = found;
42
}
43
}
44
if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);
45
var outerToken = outer.token(stream, state.outer);
46
if (cutOff != Infinity) stream.string = oldContent;
47
return outerToken;
48
} else {
49
var curInner = state.innerActive, oldContent = stream.string;
50
if (!curInner.close && stream.sol()) {
51
state.innerActive = state.inner = null;
52
return this.token(stream, state);
53
}
54
var found = curInner.close ? indexOf(oldContent, curInner.close, stream.pos) : -1;
55
if (found == stream.pos) {
56
stream.match(curInner.close);
57
state.innerActive = state.inner = null;
58
return curInner.delimStyle;
59
}
60
if (found > -1) stream.string = oldContent.slice(0, found);
61
var innerToken = curInner.mode.token(stream, state.inner);
62
if (found > -1) stream.string = oldContent;
63
64
if (curInner.innerStyle) {
65
if (innerToken) innerToken = innerToken + ' ' + curInner.innerStyle;
66
else innerToken = curInner.innerStyle;
67
}
68
69
return innerToken;
70
}
71
},
72
73
indent: function(state, textAfter) {
74
var mode = state.innerActive ? state.innerActive.mode : outer;
75
if (!mode.indent) return CodeMirror.Pass;
76
return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
77
},
78
79
blankLine: function(state) {
80
var mode = state.innerActive ? state.innerActive.mode : outer;
81
if (mode.blankLine) {
82
mode.blankLine(state.innerActive ? state.inner : state.outer);
83
}
84
if (!state.innerActive) {
85
for (var i = 0; i < n_others; ++i) {
86
var other = others[i];
87
if (other.open === "\n") {
88
state.innerActive = other;
89
state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
90
}
91
}
92
} else if (state.innerActive.close === "\n") {
93
state.innerActive = state.inner = null;
94
}
95
},
96
97
electricChars: outer.electricChars,
98
99
innerMode: function(state) {
100
return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};
101
}
102
};
103
};
104
105