cpp.js 12 KB

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