Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/pascal/pascal.js
1294 views
1
CodeMirror.defineMode("pascal", function() {
2
function words(str) {
3
var obj = {}, words = str.split(" ");
4
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5
return obj;
6
}
7
var keywords = words("and array begin case const div do downto else end file for forward integer " +
8
"boolean char function goto if in label mod nil not of or packed procedure " +
9
"program record repeat set string then to type until var while with");
10
var atoms = {"null": true};
11
12
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
13
14
function tokenBase(stream, state) {
15
var ch = stream.next();
16
if (ch == "#" && state.startOfLine) {
17
stream.skipToEnd();
18
return "meta";
19
}
20
if (ch == '"' || ch == "'") {
21
state.tokenize = tokenString(ch);
22
return state.tokenize(stream, state);
23
}
24
if (ch == "(" && stream.eat("*")) {
25
state.tokenize = tokenComment;
26
return tokenComment(stream, state);
27
}
28
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
29
return null;
30
}
31
if (/\d/.test(ch)) {
32
stream.eatWhile(/[\w\.]/);
33
return "number";
34
}
35
if (ch == "/") {
36
if (stream.eat("/")) {
37
stream.skipToEnd();
38
return "comment";
39
}
40
}
41
if (isOperatorChar.test(ch)) {
42
stream.eatWhile(isOperatorChar);
43
return "operator";
44
}
45
stream.eatWhile(/[\w\$_]/);
46
var cur = stream.current();
47
if (keywords.propertyIsEnumerable(cur)) return "keyword";
48
if (atoms.propertyIsEnumerable(cur)) return "atom";
49
return "variable";
50
}
51
52
function tokenString(quote) {
53
return function(stream, state) {
54
var escaped = false, next, end = false;
55
while ((next = stream.next()) != null) {
56
if (next == quote && !escaped) {end = true; break;}
57
escaped = !escaped && next == "\\";
58
}
59
if (end || !escaped) state.tokenize = null;
60
return "string";
61
};
62
}
63
64
function tokenComment(stream, state) {
65
var maybeEnd = false, ch;
66
while (ch = stream.next()) {
67
if (ch == ")" && maybeEnd) {
68
state.tokenize = null;
69
break;
70
}
71
maybeEnd = (ch == "*");
72
}
73
return "comment";
74
}
75
76
// Interface
77
78
return {
79
startState: function() {
80
return {tokenize: null};
81
},
82
83
token: function(stream, state) {
84
if (stream.eatSpace()) return null;
85
var style = (state.tokenize || tokenBase)(stream, state);
86
if (style == "comment" || style == "meta") return style;
87
return style;
88
},
89
90
electricChars: "{}"
91
};
92
});
93
94
CodeMirror.defineMIME("text/x-pascal", "pascal");
95
96