cpp.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/cpp/cpp.ts
  8. var 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. var 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. ":",
  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. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  267. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  268. integersuffix: /([uU](ll|LL|l|L)|(ll|LL|l|L)?[uU]?)/,
  269. floatsuffix: /[fFlL]?/,
  270. encoding: /u|u8|U|L/,
  271. tokenizer: {
  272. root: [
  273. [/@encoding?R\"(?:([^ ()\\\t]*))\(/, { token: "string.raw.begin", next: "@raw.$1" }],
  274. [
  275. /[a-zA-Z_]\w*/,
  276. {
  277. cases: {
  278. "@keywords": { token: "keyword.$0" },
  279. "@default": "identifier"
  280. }
  281. }
  282. ],
  283. [/^\s*#\s*include/, { token: "keyword.directive.include", next: "@include" }],
  284. [/^\s*#\s*\w+/, "keyword.directive"],
  285. { include: "@whitespace" },
  286. [/\[\s*\[/, { token: "annotation", next: "@annotation" }],
  287. [/[{}()\[\]]/, "@brackets"],
  288. [/[<>](?!@symbols)/, "@brackets"],
  289. [
  290. /@symbols/,
  291. {
  292. cases: {
  293. "@operators": "delimiter",
  294. "@default": ""
  295. }
  296. }
  297. ],
  298. [/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, "number.float"],
  299. [/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, "number.float"],
  300. [/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/, "number.hex"],
  301. [/0[0-7']*[0-7](@integersuffix)/, "number.octal"],
  302. [/0[bB][0-1']*[0-1](@integersuffix)/, "number.binary"],
  303. [/\d[\d']*\d(@integersuffix)/, "number"],
  304. [/\d(@integersuffix)/, "number"],
  305. [/[;,.]/, "delimiter"],
  306. [/"([^"\\]|\\.)*$/, "string.invalid"],
  307. [/"/, "string", "@string"],
  308. [/'[^\\']'/, "string"],
  309. [/(')(@escapes)(')/, ["string", "string.escape", "string"]],
  310. [/'/, "string.invalid"]
  311. ],
  312. whitespace: [
  313. [/[ \t\r\n]+/, ""],
  314. [/\/\*\*(?!\/)/, "comment.doc", "@doccomment"],
  315. [/\/\*/, "comment", "@comment"],
  316. [/\/\/.*\\$/, "comment", "@linecomment"],
  317. [/\/\/.*$/, "comment"]
  318. ],
  319. comment: [
  320. [/[^\/*]+/, "comment"],
  321. [/\*\//, "comment", "@pop"],
  322. [/[\/*]/, "comment"]
  323. ],
  324. linecomment: [
  325. [/.*[^\\]$/, "comment", "@pop"],
  326. [/[^]+/, "comment"]
  327. ],
  328. doccomment: [
  329. [/[^\/*]+/, "comment.doc"],
  330. [/\*\//, "comment.doc", "@pop"],
  331. [/[\/*]/, "comment.doc"]
  332. ],
  333. string: [
  334. [/[^\\"]+/, "string"],
  335. [/@escapes/, "string.escape"],
  336. [/\\./, "string.escape.invalid"],
  337. [/"/, "string", "@pop"]
  338. ],
  339. raw: [
  340. [
  341. /(.*)(\))(?:([^ ()\\\t"]*))(\")/,
  342. {
  343. cases: {
  344. "$3==$S2": [
  345. "string.raw",
  346. "string.raw.end",
  347. "string.raw.end",
  348. { token: "string.raw.end", next: "@pop" }
  349. ],
  350. "@default": ["string.raw", "string.raw", "string.raw", "string.raw"]
  351. }
  352. }
  353. ],
  354. [/.*/, "string.raw"]
  355. ],
  356. annotation: [
  357. { include: "@whitespace" },
  358. [/using|alignas/, "keyword"],
  359. [/[a-zA-Z0-9_]+/, "annotation"],
  360. [/[,:]/, "delimiter"],
  361. [/[()]/, "@brackets"],
  362. [/\]\s*\]/, { token: "annotation", next: "@pop" }]
  363. ],
  364. include: [
  365. [
  366. /(\s*)(<)([^<>]*)(>)/,
  367. [
  368. "",
  369. "keyword.directive.include.begin",
  370. "string.include.identifier",
  371. { token: "keyword.directive.include.end", next: "@pop" }
  372. ]
  373. ],
  374. [
  375. /(\s*)(")([^"]*)(")/,
  376. [
  377. "",
  378. "keyword.directive.include.begin",
  379. "string.include.identifier",
  380. { token: "keyword.directive.include.end", next: "@pop" }
  381. ]
  382. ]
  383. ]
  384. }
  385. };
  386. export {
  387. conf,
  388. language
  389. };