prism-d.js 3.0 KB

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