Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
(function(mod) {
5
if (typeof exports == "object" && typeof module == "object") // CommonJS
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd) // AMD
8
define(["../../lib/codemirror"], mod);
9
else // Plain browser env
10
mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
14
CodeMirror.defineMode("pascal", function() {
15
function words(str) {
16
var obj = {}, words = str.split(" ");
17
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
18
return obj;
19
}
20
var keywords = words("and array begin case const div do downto else end file for forward integer " +
21
"boolean char function goto if in label mod nil not of or packed procedure " +
22
"program record repeat set string then to type until var while with");
23
var atoms = {"null": true};
24
25
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
26
27
function tokenBase(stream, state) {
28
var ch = stream.next();
29
if (ch == "#" && state.startOfLine) {
30
stream.skipToEnd();
31
return "meta";
32
}
33
if (ch == '"' || ch == "'") {
34
state.tokenize = tokenString(ch);
35
return state.tokenize(stream, state);
36
}
37
if (ch == "(" && stream.eat("*")) {
38
state.tokenize = tokenComment;
39
return tokenComment(stream, state);
40
}
41
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
42
return null;
43
}
44
if (/\d/.test(ch)) {
45
stream.eatWhile(/[\w\.]/);
46
return "number";
47
}
48
if (ch == "/") {
49
if (stream.eat("/")) {
50
stream.skipToEnd();
51
return "comment";
52
}
53
}
54
if (isOperatorChar.test(ch)) {
55
stream.eatWhile(isOperatorChar);
56
return "operator";
57
}
58
stream.eatWhile(/[\w\$_]/);
59
var cur = stream.current();
60
if (keywords.propertyIsEnumerable(cur)) return "keyword";
61
if (atoms.propertyIsEnumerable(cur)) return "atom";
62
return "variable";
63
}
64
65
function tokenString(quote) {
66
return function(stream, state) {
67
var escaped = false, next, end = false;
68
while ((next = stream.next()) != null) {
69
if (next == quote && !escaped) {end = true; break;}
70
escaped = !escaped && next == "\\";
71
}
72
if (end || !escaped) state.tokenize = null;
73
return "string";
74
};
75
}
76
77
function tokenComment(stream, state) {
78
var maybeEnd = false, ch;
79
while (ch = stream.next()) {
80
if (ch == ")" && maybeEnd) {
81
state.tokenize = null;
82
break;
83
}
84
maybeEnd = (ch == "*");
85
}
86
return "comment";
87
}
88
89
// Interface
90
91
return {
92
startState: function() {
93
return {tokenize: null};
94
},
95
96
token: function(stream, state) {
97
if (stream.eatSpace()) return null;
98
var style = (state.tokenize || tokenBase)(stream, state);
99
if (style == "comment" || style == "meta") return style;
100
return style;
101
},
102
103
electricChars: "{}"
104
};
105
});
106
107
CodeMirror.defineMIME("text/x-pascal", "pascal");
108
109
});
110
111