Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/octave/octave.js
1294 views
1
CodeMirror.defineMode("octave", function() {
2
function wordRegexp(words) {
3
return new RegExp("^((" + words.join(")|(") + "))\\b");
4
}
5
6
var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]");
7
var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;]');
8
var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))");
9
var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))");
10
var tripleDelimiters = new RegExp("^((>>=)|(<<=))");
11
var expressionEnd = new RegExp("^[\\]\\)]");
12
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
13
14
var builtins = wordRegexp([
15
'error', 'eval', 'function', 'abs', 'acos', 'atan', 'asin', 'cos',
16
'cosh', 'exp', 'log', 'prod', 'log10', 'max', 'min', 'sign', 'sin', 'sinh',
17
'sqrt', 'tan', 'reshape', 'break', 'zeros', 'default', 'margin', 'round', 'ones',
18
'rand', 'syn', 'ceil', 'floor', 'size', 'clear', 'zeros', 'eye', 'mean', 'std', 'cov',
19
'det', 'eig', 'inv', 'norm', 'rank', 'trace', 'expm', 'logm', 'sqrtm', 'linspace', 'plot',
20
'title', 'xlabel', 'ylabel', 'legend', 'text', 'meshgrid', 'mesh', 'num2str'
21
]);
22
23
var keywords = wordRegexp([
24
'return', 'case', 'switch', 'else', 'elseif', 'end', 'endif', 'endfunction',
25
'if', 'otherwise', 'do', 'for', 'while', 'try', 'catch', 'classdef', 'properties', 'events',
26
'methods', 'global', 'persistent', 'endfor', 'endwhile', 'printf', 'disp', 'until', 'continue'
27
]);
28
29
30
// tokenizers
31
function tokenTranspose(stream, state) {
32
if (!stream.sol() && stream.peek() === '\'') {
33
stream.next();
34
state.tokenize = tokenBase;
35
return 'operator';
36
}
37
state.tokenize = tokenBase;
38
return tokenBase(stream, state);
39
}
40
41
42
function tokenComment(stream, state) {
43
if (stream.match(/^.*%}/)) {
44
state.tokenize = tokenBase;
45
return 'comment';
46
};
47
stream.skipToEnd();
48
return 'comment';
49
}
50
51
function tokenBase(stream, state) {
52
// whitespaces
53
if (stream.eatSpace()) return null;
54
55
// Handle one line Comments
56
if (stream.match('%{')){
57
state.tokenize = tokenComment;
58
stream.skipToEnd();
59
return 'comment';
60
}
61
62
if (stream.match(/^(%)|(\.\.\.)/)){
63
stream.skipToEnd();
64
return 'comment';
65
}
66
67
// Handle Number Literals
68
if (stream.match(/^[0-9\.+-]/, false)) {
69
if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) {
70
stream.tokenize = tokenBase;
71
return 'number'; };
72
if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };
73
if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };
74
}
75
if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; };
76
77
// Handle Strings
78
if (stream.match(/^"([^"]|(""))*"/)) { return 'string'; } ;
79
if (stream.match(/^'([^']|(''))*'/)) { return 'string'; } ;
80
81
// Handle words
82
if (stream.match(keywords)) { return 'keyword'; } ;
83
if (stream.match(builtins)) { return 'builtin'; } ;
84
if (stream.match(identifiers)) { return 'variable'; } ;
85
86
if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; };
87
if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; };
88
89
if (stream.match(expressionEnd)) {
90
state.tokenize = tokenTranspose;
91
return null;
92
};
93
94
95
// Handle non-detected items
96
stream.next();
97
return 'error';
98
};
99
100
101
return {
102
startState: function() {
103
return {
104
tokenize: tokenBase
105
};
106
},
107
108
token: function(stream, state) {
109
var style = state.tokenize(stream, state);
110
if (style === 'number' || style === 'variable'){
111
state.tokenize = tokenTranspose;
112
}
113
return style;
114
}
115
};
116
});
117
118
CodeMirror.defineMIME("text/x-octave", "octave");
119
120