prism-d.js 3.1 KB

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