1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | function delphi(hljs) {
|
8 | const KEYWORDS = [
|
9 | "exports",
|
10 | "register",
|
11 | "file",
|
12 | "shl",
|
13 | "array",
|
14 | "record",
|
15 | "property",
|
16 | "for",
|
17 | "mod",
|
18 | "while",
|
19 | "set",
|
20 | "ally",
|
21 | "label",
|
22 | "uses",
|
23 | "raise",
|
24 | "not",
|
25 | "stored",
|
26 | "class",
|
27 | "safecall",
|
28 | "var",
|
29 | "interface",
|
30 | "or",
|
31 | "private",
|
32 | "static",
|
33 | "exit",
|
34 | "index",
|
35 | "inherited",
|
36 | "to",
|
37 | "else",
|
38 | "stdcall",
|
39 | "override",
|
40 | "shr",
|
41 | "asm",
|
42 | "far",
|
43 | "resourcestring",
|
44 | "finalization",
|
45 | "packed",
|
46 | "virtual",
|
47 | "out",
|
48 | "and",
|
49 | "protected",
|
50 | "library",
|
51 | "do",
|
52 | "xorwrite",
|
53 | "goto",
|
54 | "near",
|
55 | "function",
|
56 | "end",
|
57 | "div",
|
58 | "overload",
|
59 | "object",
|
60 | "unit",
|
61 | "begin",
|
62 | "string",
|
63 | "on",
|
64 | "inline",
|
65 | "repeat",
|
66 | "until",
|
67 | "destructor",
|
68 | "write",
|
69 | "message",
|
70 | "program",
|
71 | "with",
|
72 | "read",
|
73 | "initialization",
|
74 | "except",
|
75 | "default",
|
76 | "nil",
|
77 | "if",
|
78 | "case",
|
79 | "cdecl",
|
80 | "in",
|
81 | "downto",
|
82 | "threadvar",
|
83 | "of",
|
84 | "try",
|
85 | "pascal",
|
86 | "const",
|
87 | "external",
|
88 | "constructor",
|
89 | "type",
|
90 | "public",
|
91 | "then",
|
92 | "implementation",
|
93 | "finally",
|
94 | "published",
|
95 | "procedure",
|
96 | "absolute",
|
97 | "reintroduce",
|
98 | "operator",
|
99 | "as",
|
100 | "is",
|
101 | "abstract",
|
102 | "alias",
|
103 | "assembler",
|
104 | "bitpacked",
|
105 | "break",
|
106 | "continue",
|
107 | "cppdecl",
|
108 | "cvar",
|
109 | "enumerator",
|
110 | "experimental",
|
111 | "platform",
|
112 | "deprecated",
|
113 | "unimplemented",
|
114 | "dynamic",
|
115 | "export",
|
116 | "far16",
|
117 | "forward",
|
118 | "generic",
|
119 | "helper",
|
120 | "implements",
|
121 | "interrupt",
|
122 | "iochecks",
|
123 | "local",
|
124 | "name",
|
125 | "nodefault",
|
126 | "noreturn",
|
127 | "nostackframe",
|
128 | "oldfpccall",
|
129 | "otherwise",
|
130 | "saveregisters",
|
131 | "softfloat",
|
132 | "specialize",
|
133 | "strict",
|
134 | "unaligned",
|
135 | "varargs"
|
136 | ];
|
137 | const COMMENT_MODES = [
|
138 | hljs.C_LINE_COMMENT_MODE,
|
139 | hljs.COMMENT(/\{/, /\}/, {
|
140 | relevance: 0
|
141 | }),
|
142 | hljs.COMMENT(/\(\*/, /\*\)/, {
|
143 | relevance: 10
|
144 | })
|
145 | ];
|
146 | const DIRECTIVE = {
|
147 | className: 'meta',
|
148 | variants: [
|
149 | {
|
150 | begin: /\{\$/,
|
151 | end: /\}/
|
152 | },
|
153 | {
|
154 | begin: /\(\*\$/,
|
155 | end: /\*\)/
|
156 | }
|
157 | ]
|
158 | };
|
159 | const STRING = {
|
160 | className: 'string',
|
161 | begin: /'/,
|
162 | end: /'/,
|
163 | contains: [{
|
164 | begin: /''/
|
165 | }]
|
166 | };
|
167 | const NUMBER = {
|
168 | className: 'number',
|
169 | relevance: 0,
|
170 |
|
171 | variants: [
|
172 | {
|
173 |
|
174 | begin: '\\$[0-9A-Fa-f]+'
|
175 | },
|
176 | {
|
177 |
|
178 | begin: '&[0-7]+'
|
179 | },
|
180 | {
|
181 |
|
182 | begin: '%[01]+'
|
183 | }
|
184 | ]
|
185 | };
|
186 | const CHAR_STRING = {
|
187 | className: 'string',
|
188 | begin: /(#\d+)+/
|
189 | };
|
190 | const CLASS = {
|
191 | begin: hljs.IDENT_RE + '\\s*=\\s*class\\s*\\(',
|
192 | returnBegin: true,
|
193 | contains: [hljs.TITLE_MODE]
|
194 | };
|
195 | const FUNCTION = {
|
196 | className: 'function',
|
197 | beginKeywords: 'function constructor destructor procedure',
|
198 | end: /[:;]/,
|
199 | keywords: 'function constructor|10 destructor|10 procedure|10',
|
200 | contains: [
|
201 | hljs.TITLE_MODE,
|
202 | {
|
203 | className: 'params',
|
204 | begin: /\(/,
|
205 | end: /\)/,
|
206 | keywords: KEYWORDS,
|
207 | contains: [
|
208 | STRING,
|
209 | CHAR_STRING,
|
210 | DIRECTIVE
|
211 | ].concat(COMMENT_MODES)
|
212 | },
|
213 | DIRECTIVE
|
214 | ].concat(COMMENT_MODES)
|
215 | };
|
216 | return {
|
217 | name: 'Delphi',
|
218 | aliases: [
|
219 | 'dpr',
|
220 | 'dfm',
|
221 | 'pas',
|
222 | 'pascal'
|
223 | ],
|
224 | case_insensitive: true,
|
225 | keywords: KEYWORDS,
|
226 | illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
|
227 | contains: [
|
228 | STRING,
|
229 | CHAR_STRING,
|
230 | hljs.NUMBER_MODE,
|
231 | NUMBER,
|
232 | CLASS,
|
233 | FUNCTION,
|
234 | DIRECTIVE
|
235 | ].concat(COMMENT_MODES)
|
236 | };
|
237 | }
|
238 |
|
239 | export { delphi as default };
|