UNPKG

3.17 kBJavaScriptView Raw
1Prism.languages.d = Prism.languages.extend('clike', {
2 'comment': [
3 {
4 // Shebang
5 pattern: /^\s*#!.+/,
6 greedy: true
7 },
8 {
9 pattern: RegExp(/(^|[^\\])/.source + '(?:' + [
10 // /+ comment +/
11 // Allow one level of nesting
12 /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source,
13 // // comment
14 /\/\/.*/.source,
15 // /* comment */
16 /\/\*[\s\S]*?\*\//.source
17 ].join('|') + ')'),
18 lookbehind: true,
19 greedy: true
20 }
21 ],
22 'string': [
23 {
24 pattern: RegExp([
25 // r"", x""
26 /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source,
27
28 // q"[]", q"()", q"<>", q"{}"
29 /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source,
30
31 // q"IDENT
32 // ...
33 // IDENT"
34 /\bq"((?!\d)\w+)$[\s\S]*?^\1"/.source,
35
36 // q"//", q"||", etc.
37 // eslint-disable-next-line regexp/strict
38 /\bq"(.)[\s\S]*?\2"/.source,
39
40 // eslint-disable-next-line regexp/strict
41 /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
42 ].join('|'), 'm'),
43 greedy: true
44 },
45 {
46 pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
47 greedy: true,
48 alias: 'token-string'
49 }
50 ],
51
52 // In order: $, keywords and special tokens, globally defined symbols
53 'keyword': /\$|\b(?:__(?:(?:DATE|EOF|FILE|FUNCTION|LINE|MODULE|PRETTY_FUNCTION|TIMESTAMP|TIME|VENDOR|VERSION)__|gshared|parameters|traits|vector)|abstract|alias|align|asm|assert|auto|body|bool|break|byte|case|cast|catch|cdouble|cent|cfloat|char|class|const|continue|creal|dchar|debug|default|delegate|delete|deprecated|do|double|dstring|else|enum|export|extern|false|final|finally|float|for|foreach|foreach_reverse|function|goto|idouble|if|ifloat|immutable|import|inout|int|interface|invariant|ireal|lazy|long|macro|mixin|module|new|nothrow|null|out|override|package|pragma|private|protected|ptrdiff_t|public|pure|real|ref|return|scope|shared|short|size_t|static|string|struct|super|switch|synchronized|template|this|throw|true|try|typedef|typeid|typeof|ubyte|ucent|uint|ulong|union|unittest|ushort|version|void|volatile|wchar|while|with|wstring)\b/,
54
55 'number': [
56 // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
57 // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
58 /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]{0,4}/i,
59 {
60 pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]{0,4}/i,
61 lookbehind: true
62 }
63 ],
64
65 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
66});
67
68Prism.languages.insertBefore('d', 'string', {
69 // Characters
70 // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
71 'char': /'(?:\\(?:\W|\w+)|[^\\])'/
72});
73
74Prism.languages.insertBefore('d', 'keyword', {
75 'property': /\B@\w*/
76});
77
78Prism.languages.insertBefore('d', 'function', {
79 'register': {
80 // Iasm registers
81 pattern: /\b(?:[ABCD][LHX]|E?(?:BP|DI|SI|SP)|[BS]PL|[ECSDGF]S|CR[0234]|[DS]IL|DR[012367]|E[ABCD]X|X?MM[0-7]|R(?:1[0-5]|[89])[BWD]?|R[ABCD]X|R[BS]P|R[DS]I|TR[3-7]|XMM(?:1[0-5]|[89])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
82 alias: 'variable'
83 }
84});