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