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