Debian Codegraph @

codemirror-legacy-modes/mode/pascal.js

raw
1 function words(str) {
2 var obj = {}, words = str.split(" ");
3 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
4 return obj;
5 }
6 var keywords = words(
7 "absolute and array asm begin case const constructor destructor div do " +
8 "downto else end file for function goto if implementation in inherited " +
9 "inline interface label mod nil not object of operator or packed procedure " +
10 "program record reintroduce repeat self set shl shr string then to type " +
11 "unit until uses var while with xor as class dispinterface except exports " +
12 "finalization finally initialization inline is library on out packed " +
13 "property raise resourcestring threadvar try absolute abstract alias " +
14 "assembler bitpacked break cdecl continue cppdecl cvar default deprecated " +
15 "dynamic enumerator experimental export external far far16 forward generic " +
16 "helper implements index interrupt iocheck local message name near " +
17 "nodefault noreturn nostackframe oldfpccall otherwise overload override " +
18 "pascal platform private protected public published read register " +
19 "reintroduce result safecall saveregisters softfloat specialize static " +
20 "stdcall stored strict unaligned unimplemented varargs virtual write");
21 var atoms = {"null": true};
22
23 var isOperatorChar = /[+\-*&%=<>!?|\/]/;
24
25 function tokenBase(stream, state) {
26 var ch = stream.next();
27 if (ch == "#" && state.startOfLine) {
28 stream.skipToEnd();
29 return "meta";
30 }
31 if (ch == '"' || ch == "'") {
32 state.tokenize = tokenString(ch);
33 return state.tokenize(stream, state);
34 }
35 if (ch == "(" && stream.eat("*")) {
36 state.tokenize = tokenComment;
37 return tokenComment(stream, state);
38 }
39 if (ch == "{") {
40 state.tokenize = tokenCommentBraces;
41 return tokenCommentBraces(stream, state);
42 }
43 if (/[\[\]\(\),;\:\.]/.test(ch)) {
44 return null;
45 }
46 if (/\d/.test(ch)) {
47 stream.eatWhile(/[\w\.]/);
48 return "number";
49 }
50 if (ch == "/") {
51 if (stream.eat("/")) {
52 stream.skipToEnd();
53 return "comment";
54 }
55 }
56 if (isOperatorChar.test(ch)) {
57 stream.eatWhile(isOperatorChar);
58 return "operator";
59 }
60 stream.eatWhile(/[\w\$_]/);
61 var cur = stream.current().toLowerCase();
62 if (keywords.propertyIsEnumerable(cur)) return "keyword";
63 if (atoms.propertyIsEnumerable(cur)) return "atom";
64 return "variable";
65 }
66
67 function tokenString(quote) {
68 return function(stream, state) {
69 var escaped = false, next, end = false;
70 while ((next = stream.next()) != null) {
71 if (next == quote && !escaped) {end = true; break;}
72 escaped = !escaped && next == "\\";
73 }
74 if (end || !escaped) state.tokenize = null;
75 return "string";
76 };
77 }
78
79 function tokenComment(stream, state) {
80 var maybeEnd = false, ch;
81 while (ch = stream.next()) {
82 if (ch == ")" && maybeEnd) {
83 state.tokenize = null;
84 break;
85 }
86 maybeEnd = (ch == "*");
87 }
88 return "comment";
89 }
90
91 function tokenCommentBraces(stream, state) {
92 var ch;
93 while (ch = stream.next()) {
94 if (ch == "}") {
95 state.tokenize = null;
96 break;
97 }
98 }
99 return "comment";
100 }
101
102 // Interface
103
104 export const pascal = {
105 name: "pascal",
106
107 startState: function() {
108 return {tokenize: null};
109 },
110
111 token: function(stream, state) {
112 if (stream.eatSpace()) return null;
113 var style = (state.tokenize || tokenBase)(stream, state);
114 if (style == "comment" || style == "meta") return style;
115 return style;
116 },
117
118 languageData: {
119 indentOnInput: /^\s*[{}]$/,
120 commentTokens: {block: {open: "(*", close: "*)"}}
121 }
122 };