UNPKG

3.12 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 // Characters
41 // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
42 /'(?:\\(?:\W|\w+)|[^\\])'/.source,
43
44 // eslint-disable-next-line regexp/strict
45 /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
46 ].join('|'), 'm'),
47 greedy: true
48 },
49 {
50 pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
51 greedy: true,
52 alias: 'token-string'
53 }
54 ],
55
56 // In order: $, keywords and special tokens, globally defined symbols
57 'keyword': /\$|\b(?: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|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|public|pure|real|ref|return|scope|shared|short|static|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|__(?:(?:FILE|MODULE|LINE|FUNCTION|PRETTY_FUNCTION|DATE|EOF|TIME|TIMESTAMP|VENDOR|VERSION)__|gshared|traits|vector|parameters)|string|wstring|dstring|size_t|ptrdiff_t)\b/,
58
59 'number': [
60 // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
61 // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
62 /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]{0,4}/i,
63 {
64 pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]{0,4}/i,
65 lookbehind: true
66 }
67 ],
68
69 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
70});
71
72Prism.languages.insertBefore('d', 'keyword', {
73 'property': /\B@\w*/
74});
75
76Prism.languages.insertBefore('d', 'function', {
77 'register': {
78 // Iasm registers
79 pattern: /\b(?:[ABCD][LHX]|E[ABCD]X|E?(?:BP|SP|DI|SI)|[ECSDGF]S|CR[0234]|DR[012367]|TR[3-7]|X?MM[0-7]|R[ABCD]X|[BS]PL|R[BS]P|[DS]IL|R[DS]I|R(?:[89]|1[0-5])[BWD]?|XMM(?:[89]|1[0-5])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
80 alias: 'variable'
81 }
82});