cs.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. module.exports = function(hljs) {
  2. var KEYWORDS = {
  3. keyword:
  4. // Normal keywords.
  5. 'abstract as base bool break byte case catch char checked const continue decimal ' +
  6. 'default delegate do double enum event explicit extern finally fixed float ' +
  7. 'for foreach goto if implicit in int interface internal is lock long ' +
  8. 'object operator out override params private protected public readonly ref sbyte ' +
  9. 'sealed short sizeof stackalloc static string struct switch this try typeof ' +
  10. 'uint ulong unchecked unsafe ushort using virtual void volatile while ' +
  11. // Contextual keywords.
  12. 'add alias ascending async await by descending dynamic equals from get global group into join ' +
  13. 'let nameof on orderby partial remove select set value var when where yield',
  14. literal:
  15. 'null false true'
  16. };
  17. var NUMBERS = {
  18. className: 'number',
  19. variants: [
  20. { begin: '\\b(0b[01\']+)' },
  21. { begin: '(-?)\\b([\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)(u|U|l|L|ul|UL|f|F|b|B)' },
  22. { begin: '(-?)(\\b0[xX][a-fA-F0-9\']+|(\\b[\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)([eE][-+]?[\\d\']+)?)' }
  23. ],
  24. relevance: 0
  25. };
  26. var VERBATIM_STRING = {
  27. className: 'string',
  28. begin: '@"', end: '"',
  29. contains: [{begin: '""'}]
  30. };
  31. var VERBATIM_STRING_NO_LF = hljs.inherit(VERBATIM_STRING, {illegal: /\n/});
  32. var SUBST = {
  33. className: 'subst',
  34. begin: '{', end: '}',
  35. keywords: KEYWORDS
  36. };
  37. var SUBST_NO_LF = hljs.inherit(SUBST, {illegal: /\n/});
  38. var INTERPOLATED_STRING = {
  39. className: 'string',
  40. begin: /\$"/, end: '"',
  41. illegal: /\n/,
  42. contains: [{begin: '{{'}, {begin: '}}'}, hljs.BACKSLASH_ESCAPE, SUBST_NO_LF]
  43. };
  44. var INTERPOLATED_VERBATIM_STRING = {
  45. className: 'string',
  46. begin: /\$@"/, end: '"',
  47. contains: [{begin: '{{'}, {begin: '}}'}, {begin: '""'}, SUBST]
  48. };
  49. var INTERPOLATED_VERBATIM_STRING_NO_LF = hljs.inherit(INTERPOLATED_VERBATIM_STRING, {
  50. illegal: /\n/,
  51. contains: [{begin: '{{'}, {begin: '}}'}, {begin: '""'}, SUBST_NO_LF]
  52. });
  53. SUBST.contains = [
  54. INTERPOLATED_VERBATIM_STRING,
  55. INTERPOLATED_STRING,
  56. VERBATIM_STRING,
  57. hljs.APOS_STRING_MODE,
  58. hljs.QUOTE_STRING_MODE,
  59. NUMBERS,
  60. hljs.C_BLOCK_COMMENT_MODE
  61. ];
  62. SUBST_NO_LF.contains = [
  63. INTERPOLATED_VERBATIM_STRING_NO_LF,
  64. INTERPOLATED_STRING,
  65. VERBATIM_STRING_NO_LF,
  66. hljs.APOS_STRING_MODE,
  67. hljs.QUOTE_STRING_MODE,
  68. NUMBERS,
  69. hljs.inherit(hljs.C_BLOCK_COMMENT_MODE, {illegal: /\n/})
  70. ];
  71. var STRING = {
  72. variants: [
  73. INTERPOLATED_VERBATIM_STRING,
  74. INTERPOLATED_STRING,
  75. VERBATIM_STRING,
  76. hljs.APOS_STRING_MODE,
  77. hljs.QUOTE_STRING_MODE
  78. ]
  79. };
  80. var TYPE_IDENT_RE = hljs.IDENT_RE + '(<' + hljs.IDENT_RE + '(\\s*,\\s*' + hljs.IDENT_RE + ')*>)?(\\[\\])?';
  81. return {
  82. aliases: ['csharp', 'c#'],
  83. keywords: KEYWORDS,
  84. illegal: /::/,
  85. contains: [
  86. hljs.COMMENT(
  87. '///',
  88. '$',
  89. {
  90. returnBegin: true,
  91. contains: [
  92. {
  93. className: 'doctag',
  94. variants: [
  95. {
  96. begin: '///', relevance: 0
  97. },
  98. {
  99. begin: '<!--|-->'
  100. },
  101. {
  102. begin: '</?', end: '>'
  103. }
  104. ]
  105. }
  106. ]
  107. }
  108. ),
  109. hljs.C_LINE_COMMENT_MODE,
  110. hljs.C_BLOCK_COMMENT_MODE,
  111. {
  112. className: 'meta',
  113. begin: '#', end: '$',
  114. keywords: {
  115. 'meta-keyword': 'if else elif endif define undef warning error line region endregion pragma checksum'
  116. }
  117. },
  118. STRING,
  119. NUMBERS,
  120. {
  121. beginKeywords: 'class interface', end: /[{;=]/,
  122. illegal: /[^\s:,]/,
  123. contains: [
  124. hljs.TITLE_MODE,
  125. hljs.C_LINE_COMMENT_MODE,
  126. hljs.C_BLOCK_COMMENT_MODE
  127. ]
  128. },
  129. {
  130. beginKeywords: 'namespace', end: /[{;=]/,
  131. illegal: /[^\s:]/,
  132. contains: [
  133. hljs.inherit(hljs.TITLE_MODE, {begin: '[a-zA-Z](\\.?\\w)*'}),
  134. hljs.C_LINE_COMMENT_MODE,
  135. hljs.C_BLOCK_COMMENT_MODE
  136. ]
  137. },
  138. {
  139. // [Attributes("")]
  140. className: 'meta',
  141. begin: '^\\s*\\[', excludeBegin: true, end: '\\]', excludeEnd: true,
  142. contains: [
  143. {className: 'meta-string', begin: /"/, end: /"/}
  144. ]
  145. },
  146. {
  147. // Expression keywords prevent 'keyword Name(...)' from being
  148. // recognized as a function definition
  149. beginKeywords: 'new return throw await else',
  150. relevance: 0
  151. },
  152. {
  153. className: 'function',
  154. begin: '(' + TYPE_IDENT_RE + '\\s+)+' + hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
  155. end: /\s*[{;=]/, excludeEnd: true,
  156. keywords: KEYWORDS,
  157. contains: [
  158. {
  159. begin: hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
  160. contains: [hljs.TITLE_MODE],
  161. relevance: 0
  162. },
  163. {
  164. className: 'params',
  165. begin: /\(/, end: /\)/,
  166. excludeBegin: true,
  167. excludeEnd: true,
  168. keywords: KEYWORDS,
  169. relevance: 0,
  170. contains: [
  171. STRING,
  172. NUMBERS,
  173. hljs.C_BLOCK_COMMENT_MODE
  174. ]
  175. },
  176. hljs.C_LINE_COMMENT_MODE,
  177. hljs.C_BLOCK_COMMENT_MODE
  178. ]
  179. }
  180. ]
  181. };
  182. };