cpp.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  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. "__m512",
  196. "__m512d",
  197. "__m512i",
  198. "__m64",
  199. "__multiple_inheritance",
  200. "__newslot",
  201. "__nogc",
  202. "__noop",
  203. "__nounwind",
  204. "__novtordisp",
  205. "__pascal",
  206. "__pin",
  207. "__pragma",
  208. "__property",
  209. "__ptr32",
  210. "__ptr64",
  211. "__raise",
  212. "__restrict",
  213. "__resume",
  214. "__sealed",
  215. "__single_inheritance",
  216. "__stdcall",
  217. "__super",
  218. "__thiscall",
  219. "__try",
  220. "__try_cast",
  221. "__typeof",
  222. "__unaligned",
  223. "__unhook",
  224. "__uuidof",
  225. "__value",
  226. "__virtual_inheritance",
  227. "__w64",
  228. "__wchar_t"
  229. ],
  230. operators: [
  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. ">>>="
  268. ],
  269. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  270. escapes: /\\(?:[0abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  271. integersuffix: /([uU](ll|LL|l|L)|(ll|LL|l|L)?[uU]?)/,
  272. floatsuffix: /[fFlL]?/,
  273. encoding: /u|u8|U|L/,
  274. tokenizer: {
  275. root: [
  276. [/@encoding?R\"(?:([^ ()\\\t]*))\(/, { token: "string.raw.begin", next: "@raw.$1" }],
  277. [
  278. /[a-zA-Z_]\w*/,
  279. {
  280. cases: {
  281. "@keywords": { token: "keyword.$0" },
  282. "@default": "identifier"
  283. }
  284. }
  285. ],
  286. [/^\s*#\s*include/, { token: "keyword.directive.include", next: "@include" }],
  287. [/^\s*#\s*\w+/, "keyword.directive"],
  288. { include: "@whitespace" },
  289. [/\[\s*\[/, { token: "annotation", next: "@annotation" }],
  290. [/[{}()\[\]]/, "@brackets"],
  291. [/[<>](?!@symbols)/, "@brackets"],
  292. [
  293. /@symbols/,
  294. {
  295. cases: {
  296. "@operators": "delimiter",
  297. "@default": ""
  298. }
  299. }
  300. ],
  301. [/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, "number.float"],
  302. [/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, "number.float"],
  303. [/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/, "number.hex"],
  304. [/0[0-7']*[0-7](@integersuffix)/, "number.octal"],
  305. [/0[bB][0-1']*[0-1](@integersuffix)/, "number.binary"],
  306. [/\d[\d']*\d(@integersuffix)/, "number"],
  307. [/\d(@integersuffix)/, "number"],
  308. [/[;,.]/, "delimiter"],
  309. [/"([^"\\]|\\.)*$/, "string.invalid"],
  310. [/"/, "string", "@string"],
  311. [/'[^\\']'/, "string"],
  312. [/(')(@escapes)(')/, ["string", "string.escape", "string"]],
  313. [/'/, "string.invalid"]
  314. ],
  315. whitespace: [
  316. [/[ \t\r\n]+/, ""],
  317. [/\/\*\*(?!\/)/, "comment.doc", "@doccomment"],
  318. [/\/\*/, "comment", "@comment"],
  319. [/\/\/.*\\$/, "comment", "@linecomment"],
  320. [/\/\/.*$/, "comment"]
  321. ],
  322. comment: [
  323. [/[^\/*]+/, "comment"],
  324. [/\*\//, "comment", "@pop"],
  325. [/[\/*]/, "comment"]
  326. ],
  327. linecomment: [
  328. [/.*[^\\]$/, "comment", "@pop"],
  329. [/[^]+/, "comment"]
  330. ],
  331. doccomment: [
  332. [/[^\/*]+/, "comment.doc"],
  333. [/\*\//, "comment.doc", "@pop"],
  334. [/[\/*]/, "comment.doc"]
  335. ],
  336. string: [
  337. [/[^\\"]+/, "string"],
  338. [/@escapes/, "string.escape"],
  339. [/\\./, "string.escape.invalid"],
  340. [/"/, "string", "@pop"]
  341. ],
  342. raw: [
  343. [
  344. /(.*)(\))(?:([^ ()\\\t"]*))(\")/,
  345. {
  346. cases: {
  347. "$3==$S2": [
  348. "string.raw",
  349. "string.raw.end",
  350. "string.raw.end",
  351. { token: "string.raw.end", next: "@pop" }
  352. ],
  353. "@default": ["string.raw", "string.raw", "string.raw", "string.raw"]
  354. }
  355. }
  356. ],
  357. [/.*/, "string.raw"]
  358. ],
  359. annotation: [
  360. { include: "@whitespace" },
  361. [/using|alignas/, "keyword"],
  362. [/[a-zA-Z0-9_]+/, "annotation"],
  363. [/[,:]/, "delimiter"],
  364. [/[()]/, "@brackets"],
  365. [/\]\s*\]/, { token: "annotation", next: "@pop" }]
  366. ],
  367. include: [
  368. [
  369. /(\s*)(<)([^<>]*)(>)/,
  370. [
  371. "",
  372. "keyword.directive.include.begin",
  373. "string.include.identifier",
  374. { token: "keyword.directive.include.end", next: "@pop" }
  375. ]
  376. ],
  377. [
  378. /(\s*)(")([^"]*)(")/,
  379. [
  380. "",
  381. "keyword.directive.include.begin",
  382. "string.include.identifier",
  383. { token: "keyword.directive.include.end", next: "@pop" }
  384. ]
  385. ]
  386. ]
  387. }
  388. };
  389. export {
  390. conf,
  391. language
  392. };