Mercurial
comparison .cms/lib/codemirror/mode/pascal/pascal.js @ 0:78edf6b517a0 draft
24.10
author | Coffee CMS <info@coffee-cms.ru> |
---|---|
date | Fri, 11 Oct 2024 22:40:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78edf6b517a0 |
---|---|
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others | |
2 // Distributed under an MIT license: https://codemirror.net/5/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( | |
21 "absolute and array asm begin case const constructor destructor div do " + | |
22 "downto else end file for function goto if implementation in inherited " + | |
23 "inline interface label mod nil not object of operator or packed procedure " + | |
24 "program record reintroduce repeat self set shl shr string then to type " + | |
25 "unit until uses var while with xor as class dispinterface except exports " + | |
26 "finalization finally initialization inline is library on out packed " + | |
27 "property raise resourcestring threadvar try absolute abstract alias " + | |
28 "assembler bitpacked break cdecl continue cppdecl cvar default deprecated " + | |
29 "dynamic enumerator experimental export external far far16 forward generic " + | |
30 "helper implements index interrupt iocheck local message name near " + | |
31 "nodefault noreturn nostackframe oldfpccall otherwise overload override " + | |
32 "pascal platform private protected public published read register " + | |
33 "reintroduce result safecall saveregisters softfloat specialize static " + | |
34 "stdcall stored strict unaligned unimplemented varargs virtual write"); | |
35 var atoms = {"null": true}; | |
36 | |
37 var isOperatorChar = /[+\-*&%=<>!?|\/]/; | |
38 | |
39 function tokenBase(stream, state) { | |
40 var ch = stream.next(); | |
41 if (ch == "#" && state.startOfLine) { | |
42 stream.skipToEnd(); | |
43 return "meta"; | |
44 } | |
45 if (ch == '"' || ch == "'") { | |
46 state.tokenize = tokenString(ch); | |
47 return state.tokenize(stream, state); | |
48 } | |
49 if (ch == "(" && stream.eat("*")) { | |
50 state.tokenize = tokenComment; | |
51 return tokenComment(stream, state); | |
52 } | |
53 if (ch == "{") { | |
54 state.tokenize = tokenCommentBraces; | |
55 return tokenCommentBraces(stream, state); | |
56 } | |
57 if (/[\[\]\(\),;\:\.]/.test(ch)) { | |
58 return null; | |
59 } | |
60 if (/\d/.test(ch)) { | |
61 stream.eatWhile(/[\w\.]/); | |
62 return "number"; | |
63 } | |
64 if (ch == "/") { | |
65 if (stream.eat("/")) { | |
66 stream.skipToEnd(); | |
67 return "comment"; | |
68 } | |
69 } | |
70 if (isOperatorChar.test(ch)) { | |
71 stream.eatWhile(isOperatorChar); | |
72 return "operator"; | |
73 } | |
74 stream.eatWhile(/[\w\$_]/); | |
75 var cur = stream.current(); | |
76 if (keywords.propertyIsEnumerable(cur)) return "keyword"; | |
77 if (atoms.propertyIsEnumerable(cur)) return "atom"; | |
78 return "variable"; | |
79 } | |
80 | |
81 function tokenString(quote) { | |
82 return function(stream, state) { | |
83 var escaped = false, next, end = false; | |
84 while ((next = stream.next()) != null) { | |
85 if (next == quote && !escaped) {end = true; break;} | |
86 escaped = !escaped && next == "\\"; | |
87 } | |
88 if (end || !escaped) state.tokenize = null; | |
89 return "string"; | |
90 }; | |
91 } | |
92 | |
93 function tokenComment(stream, state) { | |
94 var maybeEnd = false, ch; | |
95 while (ch = stream.next()) { | |
96 if (ch == ")" && maybeEnd) { | |
97 state.tokenize = null; | |
98 break; | |
99 } | |
100 maybeEnd = (ch == "*"); | |
101 } | |
102 return "comment"; | |
103 } | |
104 | |
105 function tokenCommentBraces(stream, state) { | |
106 var ch; | |
107 while (ch = stream.next()) { | |
108 if (ch == "}") { | |
109 state.tokenize = null; | |
110 break; | |
111 } | |
112 } | |
113 return "comment"; | |
114 } | |
115 | |
116 // Interface | |
117 | |
118 return { | |
119 startState: function() { | |
120 return {tokenize: null}; | |
121 }, | |
122 | |
123 token: function(stream, state) { | |
124 if (stream.eatSpace()) return null; | |
125 var style = (state.tokenize || tokenBase)(stream, state); | |
126 if (style == "comment" || style == "meta") return style; | |
127 return style; | |
128 }, | |
129 | |
130 electricChars: "{}" | |
131 }; | |
132 }); | |
133 | |
134 CodeMirror.defineMIME("text/x-pascal", "pascal"); | |
135 | |
136 }); |