UNPKG

3.95 kBJavaScriptView Raw
1/*
2Language: Delphi
3Website: https://www.embarcadero.com/products/delphi
4*/
5
6/** @type LanguageFn */
7function 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(/\{/, /\}/, { relevance: 0 }),
140 hljs.COMMENT(/\(\*/, /\*\)/, { relevance: 10 })
141 ];
142 const DIRECTIVE = {
143 className: 'meta',
144 variants: [
145 {
146 begin: /\{\$/,
147 end: /\}/
148 },
149 {
150 begin: /\(\*\$/,
151 end: /\*\)/
152 }
153 ]
154 };
155 const STRING = {
156 className: 'string',
157 begin: /'/,
158 end: /'/,
159 contains: [ { begin: /''/ } ]
160 };
161 const NUMBER = {
162 className: 'number',
163 relevance: 0,
164 // Source: https://www.freepascal.org/docs-html/ref/refse6.html
165 variants: [
166 {
167 // Hexadecimal notation, e.g., $7F.
168 begin: '\\$[0-9A-Fa-f]+' },
169 {
170 // Octal notation, e.g., &42.
171 begin: '&[0-7]+' },
172 {
173 // Binary notation, e.g., %1010.
174 begin: '%[01]+' }
175 ]
176 };
177 const CHAR_STRING = {
178 className: 'string',
179 begin: /(#\d+)+/
180 };
181 const CLASS = {
182 begin: hljs.IDENT_RE + '\\s*=\\s*class\\s*\\(',
183 returnBegin: true,
184 contains: [ hljs.TITLE_MODE ]
185 };
186 const FUNCTION = {
187 className: 'function',
188 beginKeywords: 'function constructor destructor procedure',
189 end: /[:;]/,
190 keywords: 'function constructor|10 destructor|10 procedure|10',
191 contains: [
192 hljs.TITLE_MODE,
193 {
194 className: 'params',
195 begin: /\(/,
196 end: /\)/,
197 keywords: KEYWORDS,
198 contains: [
199 STRING,
200 CHAR_STRING,
201 DIRECTIVE
202 ].concat(COMMENT_MODES)
203 },
204 DIRECTIVE
205 ].concat(COMMENT_MODES)
206 };
207 return {
208 name: 'Delphi',
209 aliases: [
210 'dpr',
211 'dfm',
212 'pas',
213 'pascal'
214 ],
215 case_insensitive: true,
216 keywords: KEYWORDS,
217 illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
218 contains: [
219 STRING,
220 CHAR_STRING,
221 hljs.NUMBER_MODE,
222 NUMBER,
223 CLASS,
224 FUNCTION,
225 DIRECTIVE
226 ].concat(COMMENT_MODES)
227 };
228}
229
230module.exports = delphi;