cpp.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. comments: {
  7. lineComment: '//',
  8. blockComment: ['/*', '*/']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')']
  14. ],
  15. autoClosingPairs: [
  16. { open: '[', close: ']' },
  17. { open: '{', close: '}' },
  18. { open: '(', close: ')' },
  19. { open: "'", close: "'", notIn: ['string', 'comment'] },
  20. { open: '"', close: '"', notIn: ['string'] }
  21. ],
  22. surroundingPairs: [
  23. { open: '{', close: '}' },
  24. { open: '[', close: ']' },
  25. { open: '(', close: ')' },
  26. { open: '"', close: '"' },
  27. { open: "'", close: "'" }
  28. ],
  29. folding: {
  30. markers: {
  31. start: new RegExp('^\\s*#pragma\\s+region\\b'),
  32. end: new RegExp('^\\s*#pragma\\s+endregion\\b')
  33. }
  34. }
  35. };
  36. export var language = {
  37. defaultToken: '',
  38. tokenPostfix: '.cpp',
  39. brackets: [
  40. { token: 'delimiter.curly', open: '{', close: '}' },
  41. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  42. { token: 'delimiter.square', open: '[', close: ']' },
  43. { token: 'delimiter.angle', open: '<', close: '>' }
  44. ],
  45. keywords: [
  46. 'abstract',
  47. 'amp',
  48. 'array',
  49. 'auto',
  50. 'bool',
  51. 'break',
  52. 'case',
  53. 'catch',
  54. 'char',
  55. 'class',
  56. 'const',
  57. 'constexpr',
  58. 'const_cast',
  59. 'continue',
  60. 'cpu',
  61. 'decltype',
  62. 'default',
  63. 'delegate',
  64. 'delete',
  65. 'do',
  66. 'double',
  67. 'dynamic_cast',
  68. 'each',
  69. 'else',
  70. 'enum',
  71. 'event',
  72. 'explicit',
  73. 'export',
  74. 'extern',
  75. 'false',
  76. 'final',
  77. 'finally',
  78. 'float',
  79. 'for',
  80. 'friend',
  81. 'gcnew',
  82. 'generic',
  83. 'goto',
  84. 'if',
  85. 'in',
  86. 'initonly',
  87. 'inline',
  88. 'int',
  89. 'interface',
  90. 'interior_ptr',
  91. 'internal',
  92. 'literal',
  93. 'long',
  94. 'mutable',
  95. 'namespace',
  96. 'new',
  97. 'noexcept',
  98. 'nullptr',
  99. '__nullptr',
  100. 'operator',
  101. 'override',
  102. 'partial',
  103. 'pascal',
  104. 'pin_ptr',
  105. 'private',
  106. 'property',
  107. 'protected',
  108. 'public',
  109. 'ref',
  110. 'register',
  111. 'reinterpret_cast',
  112. 'restrict',
  113. 'return',
  114. 'safe_cast',
  115. 'sealed',
  116. 'short',
  117. 'signed',
  118. 'sizeof',
  119. 'static',
  120. 'static_assert',
  121. 'static_cast',
  122. 'struct',
  123. 'switch',
  124. 'template',
  125. 'this',
  126. 'thread_local',
  127. 'throw',
  128. 'tile_static',
  129. 'true',
  130. 'try',
  131. 'typedef',
  132. 'typeid',
  133. 'typename',
  134. 'union',
  135. 'unsigned',
  136. 'using',
  137. 'virtual',
  138. 'void',
  139. 'volatile',
  140. 'wchar_t',
  141. 'where',
  142. 'while',
  143. '_asm',
  144. '_based',
  145. '_cdecl',
  146. '_declspec',
  147. '_fastcall',
  148. '_if_exists',
  149. '_if_not_exists',
  150. '_inline',
  151. '_multiple_inheritance',
  152. '_pascal',
  153. '_single_inheritance',
  154. '_stdcall',
  155. '_virtual_inheritance',
  156. '_w64',
  157. '__abstract',
  158. '__alignof',
  159. '__asm',
  160. '__assume',
  161. '__based',
  162. '__box',
  163. '__builtin_alignof',
  164. '__cdecl',
  165. '__clrcall',
  166. '__declspec',
  167. '__delegate',
  168. '__event',
  169. '__except',
  170. '__fastcall',
  171. '__finally',
  172. '__forceinline',
  173. '__gc',
  174. '__hook',
  175. '__identifier',
  176. '__if_exists',
  177. '__if_not_exists',
  178. '__inline',
  179. '__int128',
  180. '__int16',
  181. '__int32',
  182. '__int64',
  183. '__int8',
  184. '__interface',
  185. '__leave',
  186. '__m128',
  187. '__m128d',
  188. '__m128i',
  189. '__m256',
  190. '__m256d',
  191. '__m256i',
  192. '__m64',
  193. '__multiple_inheritance',
  194. '__newslot',
  195. '__nogc',
  196. '__noop',
  197. '__nounwind',
  198. '__novtordisp',
  199. '__pascal',
  200. '__pin',
  201. '__pragma',
  202. '__property',
  203. '__ptr32',
  204. '__ptr64',
  205. '__raise',
  206. '__restrict',
  207. '__resume',
  208. '__sealed',
  209. '__single_inheritance',
  210. '__stdcall',
  211. '__super',
  212. '__thiscall',
  213. '__try',
  214. '__try_cast',
  215. '__typeof',
  216. '__unaligned',
  217. '__unhook',
  218. '__uuidof',
  219. '__value',
  220. '__virtual_inheritance',
  221. '__w64',
  222. '__wchar_t'
  223. ],
  224. operators: [
  225. '=',
  226. '>',
  227. '<',
  228. '!',
  229. '~',
  230. '?',
  231. ':',
  232. '==',
  233. '<=',
  234. '>=',
  235. '!=',
  236. '&&',
  237. '||',
  238. '++',
  239. '--',
  240. '+',
  241. '-',
  242. '*',
  243. '/',
  244. '&',
  245. '|',
  246. '^',
  247. '%',
  248. '<<',
  249. '>>',
  250. '>>>',
  251. '+=',
  252. '-=',
  253. '*=',
  254. '/=',
  255. '&=',
  256. '|=',
  257. '^=',
  258. '%=',
  259. '<<=',
  260. '>>=',
  261. '>>>='
  262. ],
  263. // we include these common regular expressions
  264. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  265. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  266. integersuffix: /([uU](ll|LL|l|L)|(ll|LL|l|L)?[uU]?)/,
  267. floatsuffix: /[fFlL]?/,
  268. encoding: /u|u8|U|L/,
  269. // The main tokenizer for our languages
  270. tokenizer: {
  271. root: [
  272. // C++ 11 Raw String
  273. [/@encoding?R\"(?:([^ ()\\\t]*))\(/, { token: 'string.raw.begin', next: '@raw.$1' }],
  274. // identifiers and keywords
  275. [
  276. /[a-zA-Z_]\w*/,
  277. {
  278. cases: {
  279. '@keywords': { token: 'keyword.$0' },
  280. '@default': 'identifier'
  281. }
  282. }
  283. ],
  284. // The preprocessor checks must be before whitespace as they check /^\s*#/ which
  285. // otherwise fails to match later after other whitespace has been removed.
  286. // Inclusion
  287. [/^\s*#\s*include/, { token: 'keyword.directive.include', next: '@include' }],
  288. // Preprocessor directive
  289. [/^\s*#\s*\w+/, 'keyword.directive'],
  290. // whitespace
  291. { include: '@whitespace' },
  292. // [[ attributes ]].
  293. [/\[\s*\[/, { token: 'annotation', next: '@annotation' }],
  294. // delimiters and operators
  295. [/[{}()\[\]]/, '@brackets'],
  296. [/[<>](?!@symbols)/, '@brackets'],
  297. [
  298. /@symbols/,
  299. {
  300. cases: {
  301. '@operators': 'delimiter',
  302. '@default': ''
  303. }
  304. }
  305. ],
  306. // numbers
  307. [/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  308. [/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  309. [/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/, 'number.hex'],
  310. [/0[0-7']*[0-7](@integersuffix)/, 'number.octal'],
  311. [/0[bB][0-1']*[0-1](@integersuffix)/, 'number.binary'],
  312. [/\d[\d']*\d(@integersuffix)/, 'number'],
  313. [/\d(@integersuffix)/, 'number'],
  314. // delimiter: after number because of .\d floats
  315. [/[;,.]/, 'delimiter'],
  316. // strings
  317. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  318. [/"/, 'string', '@string'],
  319. // characters
  320. [/'[^\\']'/, 'string'],
  321. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  322. [/'/, 'string.invalid']
  323. ],
  324. whitespace: [
  325. [/[ \t\r\n]+/, ''],
  326. [/\/\*\*(?!\/)/, 'comment.doc', '@doccomment'],
  327. [/\/\*/, 'comment', '@comment'],
  328. [/\/\/.*\\$/, 'comment', '@linecomment'],
  329. [/\/\/.*$/, 'comment']
  330. ],
  331. comment: [
  332. [/[^\/*]+/, 'comment'],
  333. [/\*\//, 'comment', '@pop'],
  334. [/[\/*]/, 'comment']
  335. ],
  336. //For use with continuous line comments
  337. linecomment: [
  338. [/.*[^\\]$/, 'comment', '@pop'],
  339. [/[^]+/, 'comment']
  340. ],
  341. //Identical copy of comment above, except for the addition of .doc
  342. doccomment: [
  343. [/[^\/*]+/, 'comment.doc'],
  344. [/\*\//, 'comment.doc', '@pop'],
  345. [/[\/*]/, 'comment.doc']
  346. ],
  347. string: [
  348. [/[^\\"]+/, 'string'],
  349. [/@escapes/, 'string.escape'],
  350. [/\\./, 'string.escape.invalid'],
  351. [/"/, 'string', '@pop']
  352. ],
  353. raw: [
  354. [
  355. /(.*)(\))(?:([^ ()\\\t"]*))(\")/,
  356. {
  357. cases: {
  358. '$3==$S2': [
  359. 'string.raw',
  360. 'string.raw.end',
  361. 'string.raw.end',
  362. { token: 'string.raw.end', next: '@pop' }
  363. ],
  364. '@default': ['string.raw', 'string.raw', 'string.raw', 'string.raw']
  365. }
  366. }
  367. ],
  368. [/.*/, 'string.raw']
  369. ],
  370. annotation: [
  371. { include: '@whitespace' },
  372. [/using|alignas/, 'keyword'],
  373. [/[a-zA-Z0-9_]+/, 'annotation'],
  374. [/[,:]/, 'delimiter'],
  375. [/[()]/, '@brackets'],
  376. [/\]\s*\]/, { token: 'annotation', next: '@pop' }]
  377. ],
  378. include: [
  379. [
  380. /(\s*)(<)([^<>]*)(>)/,
  381. [
  382. '',
  383. 'keyword.directive.include.begin',
  384. 'string.include.identifier',
  385. { token: 'keyword.directive.include.end', next: '@pop' }
  386. ]
  387. ],
  388. [
  389. /(\s*)(")([^"]*)(")/,
  390. [
  391. '',
  392. 'keyword.directive.include.begin',
  393. 'string.include.identifier',
  394. { token: 'keyword.directive.include.end', next: '@pop' }
  395. ]
  396. ]
  397. ]
  398. }
  399. };