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