]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/d.js
Initial commit.
[flow-web.git] / static / highlight / languages / d.js
1 /*! `d` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: D
8 Author: Aleksandar Ruzicic <aleksandar@ruzicic.info>
9 Description: D is a language with C-like syntax and static typing. It pragmatically combines efficiency, control, and modeling power, with safety and programmer productivity.
10 Version: 1.0a
11 Website: https://dlang.org
12 Category: system
13 Date: 2012-04-08
14 */
15
16 /**
17 * Known issues:
18 *
19 * - invalid hex string literals will be recognized as a double quoted strings
20 * but 'x' at the beginning of string will not be matched
21 *
22 * - delimited string literals are not checked for matching end delimiter
23 * (not possible to do with js regexp)
24 *
25 * - content of token string is colored as a string (i.e. no keyword coloring inside a token string)
26 * also, content of token string is not validated to contain only valid D tokens
27 *
28 * - special token sequence rule is not strictly following D grammar (anything following #line
29 * up to the end of line is matched as special token sequence)
30 */
31
32 /** @type LanguageFn */
33 function d(hljs) {
34 /**
35 * Language keywords
36 *
37 * @type {Object}
38 */
39 const D_KEYWORDS = {
40 $pattern: hljs.UNDERSCORE_IDENT_RE,
41 keyword:
42 'abstract alias align asm assert auto body break byte case cast catch class '
43 + 'const continue debug default delete deprecated do else enum export extern final '
44 + 'finally for foreach foreach_reverse|10 goto if immutable import in inout int '
45 + 'interface invariant is lazy macro mixin module new nothrow out override package '
46 + 'pragma private protected public pure ref return scope shared static struct '
47 + 'super switch synchronized template this throw try typedef typeid typeof union '
48 + 'unittest version void volatile while with __FILE__ __LINE__ __gshared|10 '
49 + '__thread __traits __DATE__ __EOF__ __TIME__ __TIMESTAMP__ __VENDOR__ __VERSION__',
50 built_in:
51 'bool cdouble cent cfloat char creal dchar delegate double dstring float function '
52 + 'idouble ifloat ireal long real short string ubyte ucent uint ulong ushort wchar '
53 + 'wstring',
54 literal:
55 'false null true'
56 };
57
58 /**
59 * Number literal regexps
60 *
61 * @type {String}
62 */
63 const decimal_integer_re = '(0|[1-9][\\d_]*)';
64 const decimal_integer_nosus_re = '(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)';
65 const binary_integer_re = '0[bB][01_]+';
66 const hexadecimal_digits_re = '([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*)';
67 const hexadecimal_integer_re = '0[xX]' + hexadecimal_digits_re;
68
69 const decimal_exponent_re = '([eE][+-]?' + decimal_integer_nosus_re + ')';
70 const decimal_float_re = '(' + decimal_integer_nosus_re + '(\\.\\d*|' + decimal_exponent_re + ')|'
71 + '\\d+\\.' + decimal_integer_nosus_re + '|'
72 + '\\.' + decimal_integer_re + decimal_exponent_re + '?'
73 + ')';
74 const hexadecimal_float_re = '(0[xX]('
75 + hexadecimal_digits_re + '\\.' + hexadecimal_digits_re + '|'
76 + '\\.?' + hexadecimal_digits_re
77 + ')[pP][+-]?' + decimal_integer_nosus_re + ')';
78
79 const integer_re = '('
80 + decimal_integer_re + '|'
81 + binary_integer_re + '|'
82 + hexadecimal_integer_re
83 + ')';
84
85 const float_re = '('
86 + hexadecimal_float_re + '|'
87 + decimal_float_re
88 + ')';
89
90 /**
91 * Escape sequence supported in D string and character literals
92 *
93 * @type {String}
94 */
95 const escape_sequence_re = '\\\\('
96 + '[\'"\\?\\\\abfnrtv]|' // common escapes
97 + 'u[\\dA-Fa-f]{4}|' // four hex digit unicode codepoint
98 + '[0-7]{1,3}|' // one to three octal digit ascii char code
99 + 'x[\\dA-Fa-f]{2}|' // two hex digit ascii char code
100 + 'U[\\dA-Fa-f]{8}' // eight hex digit unicode codepoint
101 + ')|'
102 + '&[a-zA-Z\\d]{2,};'; // named character entity
103
104 /**
105 * D integer number literals
106 *
107 * @type {Object}
108 */
109 const D_INTEGER_MODE = {
110 className: 'number',
111 begin: '\\b' + integer_re + '(L|u|U|Lu|LU|uL|UL)?',
112 relevance: 0
113 };
114
115 /**
116 * [D_FLOAT_MODE description]
117 * @type {Object}
118 */
119 const D_FLOAT_MODE = {
120 className: 'number',
121 begin: '\\b('
122 + float_re + '([fF]|L|i|[fF]i|Li)?|'
123 + integer_re + '(i|[fF]i|Li)'
124 + ')',
125 relevance: 0
126 };
127
128 /**
129 * D character literal
130 *
131 * @type {Object}
132 */
133 const D_CHARACTER_MODE = {
134 className: 'string',
135 begin: '\'(' + escape_sequence_re + '|.)',
136 end: '\'',
137 illegal: '.'
138 };
139
140 /**
141 * D string escape sequence
142 *
143 * @type {Object}
144 */
145 const D_ESCAPE_SEQUENCE = {
146 begin: escape_sequence_re,
147 relevance: 0
148 };
149
150 /**
151 * D double quoted string literal
152 *
153 * @type {Object}
154 */
155 const D_STRING_MODE = {
156 className: 'string',
157 begin: '"',
158 contains: [ D_ESCAPE_SEQUENCE ],
159 end: '"[cwd]?'
160 };
161
162 /**
163 * D wysiwyg and delimited string literals
164 *
165 * @type {Object}
166 */
167 const D_WYSIWYG_DELIMITED_STRING_MODE = {
168 className: 'string',
169 begin: '[rq]"',
170 end: '"[cwd]?',
171 relevance: 5
172 };
173
174 /**
175 * D alternate wysiwyg string literal
176 *
177 * @type {Object}
178 */
179 const D_ALTERNATE_WYSIWYG_STRING_MODE = {
180 className: 'string',
181 begin: '`',
182 end: '`[cwd]?'
183 };
184
185 /**
186 * D hexadecimal string literal
187 *
188 * @type {Object}
189 */
190 const D_HEX_STRING_MODE = {
191 className: 'string',
192 begin: 'x"[\\da-fA-F\\s\\n\\r]*"[cwd]?',
193 relevance: 10
194 };
195
196 /**
197 * D delimited string literal
198 *
199 * @type {Object}
200 */
201 const D_TOKEN_STRING_MODE = {
202 className: 'string',
203 begin: 'q"\\{',
204 end: '\\}"'
205 };
206
207 /**
208 * Hashbang support
209 *
210 * @type {Object}
211 */
212 const D_HASHBANG_MODE = {
213 className: 'meta',
214 begin: '^#!',
215 end: '$',
216 relevance: 5
217 };
218
219 /**
220 * D special token sequence
221 *
222 * @type {Object}
223 */
224 const D_SPECIAL_TOKEN_SEQUENCE_MODE = {
225 className: 'meta',
226 begin: '#(line)',
227 end: '$',
228 relevance: 5
229 };
230
231 /**
232 * D attributes
233 *
234 * @type {Object}
235 */
236 const D_ATTRIBUTE_MODE = {
237 className: 'keyword',
238 begin: '@[a-zA-Z_][a-zA-Z_\\d]*'
239 };
240
241 /**
242 * D nesting comment
243 *
244 * @type {Object}
245 */
246 const D_NESTING_COMMENT_MODE = hljs.COMMENT(
247 '\\/\\+',
248 '\\+\\/',
249 {
250 contains: [ 'self' ],
251 relevance: 10
252 }
253 );
254
255 return {
256 name: 'D',
257 keywords: D_KEYWORDS,
258 contains: [
259 hljs.C_LINE_COMMENT_MODE,
260 hljs.C_BLOCK_COMMENT_MODE,
261 D_NESTING_COMMENT_MODE,
262 D_HEX_STRING_MODE,
263 D_STRING_MODE,
264 D_WYSIWYG_DELIMITED_STRING_MODE,
265 D_ALTERNATE_WYSIWYG_STRING_MODE,
266 D_TOKEN_STRING_MODE,
267 D_FLOAT_MODE,
268 D_INTEGER_MODE,
269 D_CHARACTER_MODE,
270 D_HASHBANG_MODE,
271 D_SPECIAL_TOKEN_SEQUENCE_MODE,
272 D_ATTRIBUTE_MODE
273 ]
274 };
275 }
276
277 return d;
278
279 })();
280
281 hljs.registerLanguage('d', hljsGrammar);
282 })();