Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/julia/julia.js
1293 views
1
CodeMirror.defineMode("julia", function(_conf, parserConf) {
2
var ERRORCLASS = 'error';
3
4
function wordRegexp(words) {
5
return new RegExp("^((" + words.join(")|(") + "))\\b");
6
}
7
8
var operators = parserConf.operators || /^(?:\.?[|&^\\%*+\-<>!=\/]=?|\?|~|:|\$|<:|\.[<>]|<<=?|>>>?=?|\.[<>=]=|->?|\/\/|\bin\b|\.{3})/;
9
var delimiters = parserConf.delimiters || /^[;,()[\]{}]/;
10
var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*!*/;
11
var blockOpeners = ["begin", "function", "type", "immutable", "let", "macro", "for", "while", "quote", "if", "else", "elseif", "try", "finally", "catch"];
12
var blockClosers = ["end", "else", "elseif", "catch", "finally"];
13
var keywordList = ['if', 'else', 'elseif', 'while', 'for', 'begin', 'let', 'end', 'do', 'try', 'catch', 'finally', 'return', 'break', 'continue', 'global', 'local', 'const', 'export', 'import', 'importall', 'using', 'function', 'macro', 'module', 'baremodule', 'type', 'immutable', 'quote', 'typealias', 'abstract', 'bitstype', 'ccall'];
14
var builtinList = ['true', 'false', 'enumerate', 'open', 'close', 'nothing', 'NaN', 'Inf', 'print', 'println', 'Int8', 'Uint8', 'Int16', 'Uint16', 'Int32', 'Uint32', 'Int64', 'Uint64', 'Int128', 'Uint128', 'Bool', 'Char', 'Float16', 'Float32', 'Float64', 'Array', 'Vector', 'Matrix', 'String', 'UTF8String', 'ASCIIString', 'error', 'warn', 'info', '@printf'];
15
16
//var stringPrefixes = new RegExp("^[br]?('|\")")
17
var stringPrefixes = /^[br]?('|"{3}|")/;
18
var keywords = wordRegexp(keywordList);
19
var builtins = wordRegexp(builtinList);
20
var openers = wordRegexp(blockOpeners);
21
var closers = wordRegexp(blockClosers);
22
var macro = /@[_A-Za-z][_A-Za-z0-9]*!*/;
23
var indentInfo = null;
24
25
function in_array(state) {
26
var ch = cur_scope(state);
27
if(ch=="[" || ch=="{") {
28
return true;
29
}
30
else {
31
return false;
32
}
33
}
34
35
function cur_scope(state) {
36
if(state.scopes.length==0) {
37
return null;
38
}
39
return state.scopes[state.scopes.length - 1];
40
}
41
42
// tokenizers
43
function tokenBase(stream, state) {
44
// Handle scope changes
45
var leaving_expr = state.leaving_expr;
46
state.leaving_expr = false;
47
if(leaving_expr) {
48
if(stream.match(/^'+/)) {
49
return 'operator';
50
}
51
if(stream.match("...")) {
52
return 'operator';
53
}
54
}
55
56
if (stream.eatSpace()) {
57
return null;
58
}
59
60
var ch = stream.peek();
61
// Handle Comments
62
if (ch === '#') {
63
stream.skipToEnd();
64
return 'comment';
65
}
66
if(ch==='[') {
67
state.scopes.push("[");
68
}
69
70
if(ch==='{') {
71
state.scopes.push("{");
72
}
73
74
var scope=cur_scope(state);
75
76
if(scope==='[' && ch===']') {
77
state.scopes.pop();
78
state.leaving_expr=true;
79
}
80
81
if(scope==='{' && ch==='}') {
82
state.scopes.pop();
83
state.leaving_expr=true;
84
}
85
86
var match;
87
if(match=stream.match(openers, false)) {
88
state.scopes.push(match);
89
}
90
91
if(!in_array(state) && stream.match(closers, false)) {
92
state.scopes.pop();
93
}
94
95
if(in_array(state)) {
96
if(stream.match("end")) {
97
return 'number';
98
}
99
100
}
101
if(stream.match("=>")) {
102
return 'operator';
103
}
104
// Handle Number Literals
105
if (stream.match(/^[0-9\.]/, false)) {
106
var imMatcher = RegExp(/^im\b/);
107
var floatLiteral = false;
108
// Floats
109
if (stream.match(/^\d*\.\d+([ef][\+\-]?\d+)?/i)) { floatLiteral = true; }
110
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
111
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
112
if (floatLiteral) {
113
// Float literals may be "imaginary"
114
stream.match(imMatcher);
115
return 'number';
116
}
117
// Integers
118
var intLiteral = false;
119
// Hex
120
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
121
// Binary
122
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
123
// Octal
124
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
125
// Decimal
126
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
127
// Decimal literals may be "imaginary"
128
stream.eat(/J/i);
129
// TODO - Can you have imaginary longs?
130
intLiteral = true;
131
}
132
// Zero by itself with no other piece of number.
133
if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
134
if (intLiteral) {
135
// Integer literals may be "long"
136
stream.match(imMatcher);
137
return 'number';
138
}
139
}
140
141
// Handle Strings
142
if (stream.match(stringPrefixes)) {
143
state.tokenize = tokenStringFactory(stream.current());
144
return state.tokenize(stream, state);
145
}
146
147
// Handle operators and Delimiters
148
if (stream.match(operators)) {
149
return 'operator';
150
}
151
152
if (stream.match(delimiters)) {
153
return null;
154
}
155
156
if (stream.match(keywords)) {
157
return 'keyword';
158
}
159
160
if (stream.match(builtins)) {
161
return 'builtin';
162
}
163
164
if (stream.match(macro)) {
165
return 'meta';
166
}
167
168
if (stream.match(identifiers)) {
169
state.leaving_expr=true;
170
return 'variable';
171
}
172
// Handle non-detected items
173
stream.next();
174
return ERRORCLASS;
175
}
176
177
function tokenStringFactory(delimiter) {
178
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
179
delimiter = delimiter.substr(1);
180
}
181
var singleline = delimiter.length == 1;
182
var OUTCLASS = 'string';
183
184
function tokenString(stream, state) {
185
while (!stream.eol()) {
186
stream.eatWhile(/[^'"\\]/);
187
if (stream.eat('\\')) {
188
stream.next();
189
if (singleline && stream.eol()) {
190
return OUTCLASS;
191
}
192
} else if (stream.match(delimiter)) {
193
state.tokenize = tokenBase;
194
return OUTCLASS;
195
} else {
196
stream.eat(/['"]/);
197
}
198
}
199
if (singleline) {
200
if (parserConf.singleLineStringErrors) {
201
return ERRORCLASS;
202
} else {
203
state.tokenize = tokenBase;
204
}
205
}
206
return OUTCLASS;
207
}
208
tokenString.isString = true;
209
return tokenString;
210
}
211
212
function tokenLexer(stream, state) {
213
indentInfo = null;
214
var style = state.tokenize(stream, state);
215
var current = stream.current();
216
217
// Handle '.' connected identifiers
218
if (current === '.') {
219
style = stream.match(identifiers, false) ? null : ERRORCLASS;
220
if (style === null && state.lastStyle === 'meta') {
221
// Apply 'meta' style to '.' connected identifiers when
222
// appropriate.
223
style = 'meta';
224
}
225
return style;
226
}
227
228
return style;
229
}
230
231
var external = {
232
startState: function() {
233
return {
234
tokenize: tokenBase,
235
scopes: [],
236
leaving_expr: false
237
};
238
},
239
240
token: function(stream, state) {
241
var style = tokenLexer(stream, state);
242
state.lastStyle = style;
243
return style;
244
},
245
246
indent: function(state, textAfter) {
247
var delta = 0;
248
if(textAfter=="end" || textAfter=="]" || textAfter=="}" || textAfter=="else" || textAfter=="elseif" || textAfter=="catch" || textAfter=="finally") {
249
delta = -1;
250
}
251
return (state.scopes.length + delta) * 2;
252
},
253
254
lineComment: "#",
255
fold: "indent",
256
electricChars: "edlsifyh]}"
257
};
258
return external;
259
});
260
261
262
CodeMirror.defineMIME("text/x-julia", "julia");
263
264