1 /*! `d` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
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.
11 Website: https://dlang.org
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
22 * - delimited string literals are not checked for matching end delimiter
23 * (not possible to do with js regexp)
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
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)
32 /** @type LanguageFn */
40 $pattern: hljs
.UNDERSCORE_IDENT_RE
,
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__',
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 '
59 * Number literal regexps
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
;
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
+ '?'
74 const hexadecimal_float_re
= '(0[xX]('
75 + hexadecimal_digits_re
+ '\\.' + hexadecimal_digits_re
+ '|'
76 + '\\.?' + hexadecimal_digits_re
77 + ')[pP][+-]?' + decimal_integer_nosus_re
+ ')';
79 const integer_re
= '('
80 + decimal_integer_re
+ '|'
81 + binary_integer_re
+ '|'
82 + hexadecimal_integer_re
86 + hexadecimal_float_re
+ '|'
91 * Escape sequence supported in D string and character literals
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
102 + '&[a-zA-Z\\d]{2,};'; // named character entity
105 * D integer number literals
109 const D_INTEGER_MODE
= {
111 begin: '\\b' + integer_re
+ '(L|u|U|Lu|LU|uL|UL)?',
116 * [D_FLOAT_MODE description]
119 const D_FLOAT_MODE
= {
122 + float_re
+ '([fF]|L|i|[fF]i|Li)?|'
123 + integer_re
+ '(i|[fF]i|Li)'
129 * D character literal
133 const D_CHARACTER_MODE
= {
135 begin: '\'(' + escape_sequence_re
+ '|.)',
141 * D string escape sequence
145 const D_ESCAPE_SEQUENCE
= {
146 begin: escape_sequence_re
,
151 * D double quoted string literal
155 const D_STRING_MODE
= {
158 contains: [ D_ESCAPE_SEQUENCE
],
163 * D wysiwyg and delimited string literals
167 const D_WYSIWYG_DELIMITED_STRING_MODE
= {
175 * D alternate wysiwyg string literal
179 const D_ALTERNATE_WYSIWYG_STRING_MODE
= {
186 * D hexadecimal string literal
190 const D_HEX_STRING_MODE
= {
192 begin: 'x"[\\da-fA-F\\s\\n\\r]*"[cwd]?',
197 * D delimited string literal
201 const D_TOKEN_STRING_MODE
= {
212 const D_HASHBANG_MODE
= {
220 * D special token sequence
224 const D_SPECIAL_TOKEN_SEQUENCE_MODE
= {
236 const D_ATTRIBUTE_MODE
= {
237 className: 'keyword',
238 begin: '@[a-zA-Z_][a-zA-Z_\\d]*'
246 const D_NESTING_COMMENT_MODE
= hljs
.COMMENT(
250 contains: [ 'self' ],
257 keywords: D_KEYWORDS
,
259 hljs
.C_LINE_COMMENT_MODE
,
260 hljs
.C_BLOCK_COMMENT_MODE
,
261 D_NESTING_COMMENT_MODE
,
264 D_WYSIWYG_DELIMITED_STRING_MODE
,
265 D_ALTERNATE_WYSIWYG_STRING_MODE
,
271 D_SPECIAL_TOKEN_SEQUENCE_MODE
,
281 hljs
.registerLanguage('d', hljsGrammar
);