csharp.ts 6.5 KB

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