csharp.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export var conf = {
  6. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  7. comments: {
  8. lineComment: '//',
  9. blockComment: ['/*', '*/']
  10. },
  11. brackets: [
  12. ['{', '}'],
  13. ['[', ']'],
  14. ['(', ')']
  15. ],
  16. autoClosingPairs: [
  17. { open: '{', close: '}' },
  18. { open: '[', close: ']' },
  19. { open: '(', close: ')' },
  20. { open: "'", close: "'", notIn: ['string', 'comment'] },
  21. { open: '"', close: '"', notIn: ['string', 'comment'] }
  22. ],
  23. surroundingPairs: [
  24. { open: '{', close: '}' },
  25. { open: '[', close: ']' },
  26. { open: '(', close: ')' },
  27. { open: '<', close: '>' },
  28. { open: "'", close: "'" },
  29. { open: '"', close: '"' }
  30. ],
  31. folding: {
  32. markers: {
  33. start: new RegExp('^\\s*#region\\b'),
  34. end: new RegExp('^\\s*#endregion\\b')
  35. }
  36. }
  37. };
  38. export var language = {
  39. defaultToken: '',
  40. tokenPostfix: '.cs',
  41. brackets: [
  42. { open: '{', close: '}', token: 'delimiter.curly' },
  43. { open: '[', close: ']', token: 'delimiter.square' },
  44. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  45. { open: '<', close: '>', token: 'delimiter.angle' }
  46. ],
  47. keywords: [
  48. 'extern',
  49. 'alias',
  50. 'using',
  51. 'bool',
  52. 'decimal',
  53. 'sbyte',
  54. 'byte',
  55. 'short',
  56. 'ushort',
  57. 'int',
  58. 'uint',
  59. 'long',
  60. 'ulong',
  61. 'char',
  62. 'float',
  63. 'double',
  64. 'object',
  65. 'dynamic',
  66. 'string',
  67. 'assembly',
  68. 'is',
  69. 'as',
  70. 'ref',
  71. 'out',
  72. 'this',
  73. 'base',
  74. 'new',
  75. 'typeof',
  76. 'void',
  77. 'checked',
  78. 'unchecked',
  79. 'default',
  80. 'delegate',
  81. 'var',
  82. 'const',
  83. 'if',
  84. 'else',
  85. 'switch',
  86. 'case',
  87. 'while',
  88. 'do',
  89. 'for',
  90. 'foreach',
  91. 'in',
  92. 'break',
  93. 'continue',
  94. 'goto',
  95. 'return',
  96. 'throw',
  97. 'try',
  98. 'catch',
  99. 'finally',
  100. 'lock',
  101. 'yield',
  102. 'from',
  103. 'let',
  104. 'where',
  105. 'join',
  106. 'on',
  107. 'equals',
  108. 'into',
  109. 'orderby',
  110. 'ascending',
  111. 'descending',
  112. 'select',
  113. 'group',
  114. 'by',
  115. 'namespace',
  116. 'partial',
  117. 'class',
  118. 'field',
  119. 'event',
  120. 'method',
  121. 'param',
  122. 'public',
  123. 'protected',
  124. 'internal',
  125. 'private',
  126. 'abstract',
  127. 'sealed',
  128. 'static',
  129. 'struct',
  130. 'readonly',
  131. 'volatile',
  132. 'virtual',
  133. 'override',
  134. 'params',
  135. 'get',
  136. 'set',
  137. 'add',
  138. 'remove',
  139. 'operator',
  140. 'true',
  141. 'false',
  142. 'implicit',
  143. 'explicit',
  144. 'interface',
  145. 'enum',
  146. 'null',
  147. 'async',
  148. 'await',
  149. 'fixed',
  150. 'sizeof',
  151. 'stackalloc',
  152. 'unsafe',
  153. 'nameof',
  154. 'when'
  155. ],
  156. namespaceFollows: ['namespace', 'using'],
  157. parenFollows: ['if', 'for', 'while', 'switch', 'foreach', 'using', 'catch', 'when'],
  158. operators: [
  159. '=',
  160. '??',
  161. '||',
  162. '&&',
  163. '|',
  164. '^',
  165. '&',
  166. '==',
  167. '!=',
  168. '<=',
  169. '>=',
  170. '<<',
  171. '+',
  172. '-',
  173. '*',
  174. '/',
  175. '%',
  176. '!',
  177. '~',
  178. '++',
  179. '--',
  180. '+=',
  181. '-=',
  182. '*=',
  183. '/=',
  184. '%=',
  185. '&=',
  186. '|=',
  187. '^=',
  188. '<<=',
  189. '>>=',
  190. '>>',
  191. '=>'
  192. ],
  193. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  194. // escape sequences
  195. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  196. // The main tokenizer for our languages
  197. tokenizer: {
  198. root: [
  199. // identifiers and keywords
  200. [
  201. /\@?[a-zA-Z_]\w*/,
  202. {
  203. cases: {
  204. '@namespaceFollows': {
  205. token: 'keyword.$0',
  206. next: '@namespace'
  207. },
  208. '@keywords': {
  209. token: 'keyword.$0',
  210. next: '@qualified'
  211. },
  212. '@default': { token: 'identifier', next: '@qualified' }
  213. }
  214. }
  215. ],
  216. // whitespace
  217. { include: '@whitespace' },
  218. // delimiters and operators
  219. [
  220. /}/,
  221. {
  222. cases: {
  223. '$S2==interpolatedstring': {
  224. token: 'string.quote',
  225. next: '@pop'
  226. },
  227. '$S2==litinterpstring': {
  228. token: 'string.quote',
  229. next: '@pop'
  230. },
  231. '@default': '@brackets'
  232. }
  233. }
  234. ],
  235. [/[{}()\[\]]/, '@brackets'],
  236. [/[<>](?!@symbols)/, '@brackets'],
  237. [
  238. /@symbols/,
  239. {
  240. cases: {
  241. '@operators': 'delimiter',
  242. '@default': ''
  243. }
  244. }
  245. ],
  246. // numbers
  247. [/[0-9_]*\.[0-9_]+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
  248. [/0[xX][0-9a-fA-F_]+/, 'number.hex'],
  249. [/0[bB][01_]+/, 'number.hex'],
  250. [/[0-9_]+/, 'number'],
  251. // delimiter: after number because of .\d floats
  252. [/[;,.]/, 'delimiter'],
  253. // strings
  254. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  255. [/"/, { token: 'string.quote', next: '@string' }],
  256. [/\$\@"/, { token: 'string.quote', next: '@litinterpstring' }],
  257. [/\@"/, { token: 'string.quote', next: '@litstring' }],
  258. [/\$"/, { token: 'string.quote', next: '@interpolatedstring' }],
  259. // characters
  260. [/'[^\\']'/, 'string'],
  261. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  262. [/'/, 'string.invalid']
  263. ],
  264. qualified: [
  265. [
  266. /[a-zA-Z_][\w]*/,
  267. {
  268. cases: {
  269. '@keywords': { token: 'keyword.$0' },
  270. '@default': 'identifier'
  271. }
  272. }
  273. ],
  274. [/\./, 'delimiter'],
  275. ['', '', '@pop']
  276. ],
  277. namespace: [
  278. { include: '@whitespace' },
  279. [/[A-Z]\w*/, 'namespace'],
  280. [/[\.=]/, 'delimiter'],
  281. ['', '', '@pop']
  282. ],
  283. comment: [
  284. [/[^\/*]+/, 'comment'],
  285. // [/\/\*/, 'comment', '@push' ], // no nested comments :-(
  286. ['\\*/', 'comment', '@pop'],
  287. [/[\/*]/, 'comment']
  288. ],
  289. string: [
  290. [/[^\\"]+/, 'string'],
  291. [/@escapes/, 'string.escape'],
  292. [/\\./, 'string.escape.invalid'],
  293. [/"/, { token: 'string.quote', next: '@pop' }]
  294. ],
  295. litstring: [
  296. [/[^"]+/, 'string'],
  297. [/""/, 'string.escape'],
  298. [/"/, { token: 'string.quote', next: '@pop' }]
  299. ],
  300. litinterpstring: [
  301. [/[^"{]+/, 'string'],
  302. [/""/, 'string.escape'],
  303. [/{{/, 'string.escape'],
  304. [/}}/, 'string.escape'],
  305. [/{/, { token: 'string.quote', next: 'root.litinterpstring' }],
  306. [/"/, { token: 'string.quote', next: '@pop' }]
  307. ],
  308. interpolatedstring: [
  309. [/[^\\"{]+/, 'string'],
  310. [/@escapes/, 'string.escape'],
  311. [/\\./, 'string.escape.invalid'],
  312. [/{{/, 'string.escape'],
  313. [/}}/, 'string.escape'],
  314. [/{/, { token: 'string.quote', next: 'root.interpolatedstring' }],
  315. [/"/, { token: 'string.quote', next: '@pop' }]
  316. ],
  317. whitespace: [
  318. [/^[ \t\v\f]*#((r)|(load))(?=\s)/, 'directive.csx'],
  319. [/^[ \t\v\f]*#\w.*$/, 'namespace.cpp'],
  320. [/[ \t\v\f\r\n]+/, ''],
  321. [/\/\*/, 'comment', '@comment'],
  322. [/\/\/.*$/, 'comment']
  323. ]
  324. }
  325. };