UNPKG

3.02 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 /\bq"(.)[\s\S]*?\2"/.source,
38
39 // Characters
40 // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
41 /'(?:\\(?:\W|\w+)|[^\\])'/.source,
42
43 /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
44 ].join('|'), 'm'),
45 greedy: true
46 },
47 {
48 pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
49 greedy: true,
50 alias: 'token-string'
51 }
52 ],
53
54 'number': [
55 // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
56 // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
57 /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]*/i,
58 {
59 pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]*/i,
60 lookbehind: true
61 }
62 ],
63
64 // In order: $, keywords and special tokens, globally defined symbols
65 '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/,
66 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
67});
68
69Prism.languages.insertBefore('d', 'keyword', {
70 'property': /\B@\w*/
71});
72
73Prism.languages.insertBefore('d', 'function', {
74 'register': {
75 // Iasm registers
76 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)/,
77 alias: 'variable'
78 }
79});