cpp.test.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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. import { testTokenization } from '../test/testRunner';
  6. testTokenization('cpp', [
  7. // Keywords
  8. [
  9. {
  10. line: 'int _tmain(int argc, _TCHAR* argv[])',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.int.cpp' },
  13. { startIndex: 3, type: '' },
  14. { startIndex: 4, type: 'identifier.cpp' },
  15. { startIndex: 10, type: 'delimiter.parenthesis.cpp' },
  16. { startIndex: 11, type: 'keyword.int.cpp' },
  17. { startIndex: 14, type: '' },
  18. { startIndex: 15, type: 'identifier.cpp' },
  19. { startIndex: 19, type: 'delimiter.cpp' },
  20. { startIndex: 20, type: '' },
  21. { startIndex: 21, type: 'identifier.cpp' },
  22. { startIndex: 27, type: 'delimiter.cpp' },
  23. { startIndex: 28, type: '' },
  24. { startIndex: 29, type: 'identifier.cpp' },
  25. { startIndex: 33, type: 'delimiter.square.cpp' },
  26. { startIndex: 35, type: 'delimiter.parenthesis.cpp' }
  27. ]
  28. }
  29. ],
  30. // Comments - single line
  31. [
  32. {
  33. line: '//',
  34. tokens: [{ startIndex: 0, type: 'comment.cpp' }]
  35. }
  36. ],
  37. [
  38. {
  39. line: ' // a comment',
  40. tokens: [
  41. { startIndex: 0, type: '' },
  42. { startIndex: 4, type: 'comment.cpp' }
  43. ]
  44. }
  45. ],
  46. [
  47. {
  48. line: '// a comment',
  49. tokens: [{ startIndex: 0, type: 'comment.cpp' }]
  50. }
  51. ],
  52. [
  53. {
  54. line: '//sticky comment',
  55. tokens: [{ startIndex: 0, type: 'comment.cpp' }]
  56. }
  57. ],
  58. [
  59. {
  60. line: '/almost a comment',
  61. tokens: [
  62. { startIndex: 0, type: 'delimiter.cpp' },
  63. { startIndex: 1, type: 'identifier.cpp' },
  64. { startIndex: 7, type: '' },
  65. { startIndex: 8, type: 'identifier.cpp' },
  66. { startIndex: 9, type: '' },
  67. { startIndex: 10, type: 'identifier.cpp' }
  68. ]
  69. }
  70. ],
  71. [
  72. {
  73. line: '/* //*/ a',
  74. tokens: [
  75. { startIndex: 0, type: 'comment.cpp' },
  76. { startIndex: 7, type: '' },
  77. { startIndex: 8, type: 'identifier.cpp' }
  78. ]
  79. }
  80. ],
  81. [
  82. {
  83. line: '1 / 2; /* comment',
  84. tokens: [
  85. { startIndex: 0, type: 'number.cpp' },
  86. { startIndex: 1, type: '' },
  87. { startIndex: 2, type: 'delimiter.cpp' },
  88. { startIndex: 3, type: '' },
  89. { startIndex: 4, type: 'number.cpp' },
  90. { startIndex: 5, type: 'delimiter.cpp' },
  91. { startIndex: 6, type: '' },
  92. { startIndex: 7, type: 'comment.cpp' }
  93. ]
  94. }
  95. ],
  96. [
  97. {
  98. line: 'int x = 1; // my comment // is a nice one',
  99. tokens: [
  100. { startIndex: 0, type: 'keyword.int.cpp' },
  101. { startIndex: 3, type: '' },
  102. { startIndex: 4, type: 'identifier.cpp' },
  103. { startIndex: 5, type: '' },
  104. { startIndex: 6, type: 'delimiter.cpp' },
  105. { startIndex: 7, type: '' },
  106. { startIndex: 8, type: 'number.cpp' },
  107. { startIndex: 9, type: 'delimiter.cpp' },
  108. { startIndex: 10, type: '' },
  109. { startIndex: 11, type: 'comment.cpp' }
  110. ]
  111. }
  112. ],
  113. // Comments - range comment, single line
  114. [
  115. {
  116. line: '/* a simple comment */',
  117. tokens: [{ startIndex: 0, type: 'comment.cpp' }]
  118. }
  119. ],
  120. [
  121. {
  122. line: 'int x = /* a simple comment */ 1;',
  123. tokens: [
  124. { startIndex: 0, type: 'keyword.int.cpp' },
  125. { startIndex: 3, type: '' },
  126. { startIndex: 4, type: 'identifier.cpp' },
  127. { startIndex: 5, type: '' },
  128. { startIndex: 6, type: 'delimiter.cpp' },
  129. { startIndex: 7, type: '' },
  130. { startIndex: 8, type: 'comment.cpp' },
  131. { startIndex: 30, type: '' },
  132. { startIndex: 31, type: 'number.cpp' },
  133. { startIndex: 32, type: 'delimiter.cpp' }
  134. ]
  135. }
  136. ],
  137. [
  138. {
  139. line: 'int x = /* comment */ 1; */',
  140. tokens: [
  141. { startIndex: 0, type: 'keyword.int.cpp' },
  142. { startIndex: 3, type: '' },
  143. { startIndex: 4, type: 'identifier.cpp' },
  144. { startIndex: 5, type: '' },
  145. { startIndex: 6, type: 'delimiter.cpp' },
  146. { startIndex: 7, type: '' },
  147. { startIndex: 8, type: 'comment.cpp' },
  148. { startIndex: 21, type: '' },
  149. { startIndex: 22, type: 'number.cpp' },
  150. { startIndex: 23, type: 'delimiter.cpp' },
  151. { startIndex: 24, type: '' }
  152. ]
  153. }
  154. ],
  155. [
  156. {
  157. line: 'x = /**/;',
  158. tokens: [
  159. { startIndex: 0, type: 'identifier.cpp' },
  160. { startIndex: 1, type: '' },
  161. { startIndex: 2, type: 'delimiter.cpp' },
  162. { startIndex: 3, type: '' },
  163. { startIndex: 4, type: 'comment.cpp' },
  164. { startIndex: 8, type: 'delimiter.cpp' }
  165. ]
  166. }
  167. ],
  168. [
  169. {
  170. line: 'x = /*/;',
  171. tokens: [
  172. { startIndex: 0, type: 'identifier.cpp' },
  173. { startIndex: 1, type: '' },
  174. { startIndex: 2, type: 'delimiter.cpp' },
  175. { startIndex: 3, type: '' },
  176. { startIndex: 4, type: 'comment.cpp' }
  177. ]
  178. }
  179. ],
  180. // Numbers
  181. [
  182. {
  183. line: '0',
  184. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  185. }
  186. ],
  187. [
  188. {
  189. line: '12l',
  190. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  191. }
  192. ],
  193. [
  194. {
  195. line: '34U',
  196. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  197. }
  198. ],
  199. [
  200. {
  201. line: '55LL',
  202. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  203. }
  204. ],
  205. [
  206. {
  207. line: '34ul',
  208. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  209. }
  210. ],
  211. [
  212. {
  213. line: '55llU',
  214. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  215. }
  216. ],
  217. [
  218. {
  219. line: "5'5llU",
  220. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  221. }
  222. ],
  223. [
  224. {
  225. line: "100'000'000",
  226. tokens: [{ startIndex: 0, type: 'number.cpp' }]
  227. }
  228. ],
  229. [
  230. {
  231. line: "0x100'aafllU",
  232. tokens: [{ startIndex: 0, type: 'number.hex.cpp' }]
  233. }
  234. ],
  235. [
  236. {
  237. line: "0342'325",
  238. tokens: [{ startIndex: 0, type: 'number.octal.cpp' }]
  239. }
  240. ],
  241. [
  242. {
  243. line: '0x123',
  244. tokens: [{ startIndex: 0, type: 'number.hex.cpp' }]
  245. }
  246. ],
  247. [
  248. {
  249. line: '23.5',
  250. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  251. }
  252. ],
  253. [
  254. {
  255. line: '23.5e3',
  256. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  257. }
  258. ],
  259. [
  260. {
  261. line: '23.5E3',
  262. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  263. }
  264. ],
  265. [
  266. {
  267. line: '23.5F',
  268. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  269. }
  270. ],
  271. [
  272. {
  273. line: '23.5f',
  274. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  275. }
  276. ],
  277. [
  278. {
  279. line: '1.72E3F',
  280. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  281. }
  282. ],
  283. [
  284. {
  285. line: '1.72E3f',
  286. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  287. }
  288. ],
  289. [
  290. {
  291. line: '1.72e3F',
  292. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  293. }
  294. ],
  295. [
  296. {
  297. line: '1.72e3f',
  298. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  299. }
  300. ],
  301. [
  302. {
  303. line: '23.5L',
  304. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  305. }
  306. ],
  307. [
  308. {
  309. line: '23.5l',
  310. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  311. }
  312. ],
  313. [
  314. {
  315. line: '1.72E3L',
  316. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  317. }
  318. ],
  319. [
  320. {
  321. line: '1.72E3l',
  322. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  323. }
  324. ],
  325. [
  326. {
  327. line: '1.72e3L',
  328. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  329. }
  330. ],
  331. [
  332. {
  333. line: '1.72e3l',
  334. tokens: [{ startIndex: 0, type: 'number.float.cpp' }]
  335. }
  336. ],
  337. [
  338. {
  339. line: '0+0',
  340. tokens: [
  341. { startIndex: 0, type: 'number.cpp' },
  342. { startIndex: 1, type: 'delimiter.cpp' },
  343. { startIndex: 2, type: 'number.cpp' }
  344. ]
  345. }
  346. ],
  347. [
  348. {
  349. line: '100+10',
  350. tokens: [
  351. { startIndex: 0, type: 'number.cpp' },
  352. { startIndex: 3, type: 'delimiter.cpp' },
  353. { startIndex: 4, type: 'number.cpp' }
  354. ]
  355. }
  356. ],
  357. [
  358. {
  359. line: '0 + 0',
  360. tokens: [
  361. { startIndex: 0, type: 'number.cpp' },
  362. { startIndex: 1, type: '' },
  363. { startIndex: 2, type: 'delimiter.cpp' },
  364. { startIndex: 3, type: '' },
  365. { startIndex: 4, type: 'number.cpp' }
  366. ]
  367. }
  368. ],
  369. // Monarch Generated
  370. [
  371. {
  372. line: '#include<iostream>',
  373. tokens: [
  374. { startIndex: 0, type: 'keyword.directive.include.cpp' },
  375. { startIndex: 8, type: 'keyword.directive.include.begin.cpp' },
  376. { startIndex: 9, type: 'string.include.identifier.cpp' },
  377. { startIndex: 17, type: 'keyword.directive.include.end.cpp' }
  378. ]
  379. },
  380. {
  381. line: '#include "/path/to/my/file.h"',
  382. tokens: [
  383. { startIndex: 0, type: 'keyword.directive.include.cpp' },
  384. { startIndex: 8, type: '' },
  385. { startIndex: 9, type: 'keyword.directive.include.begin.cpp' },
  386. { startIndex: 10, type: 'string.include.identifier.cpp' },
  387. { startIndex: 28, type: 'keyword.directive.include.end.cpp' }
  388. ]
  389. },
  390. {
  391. line: '',
  392. tokens: []
  393. },
  394. {
  395. line: '#ifdef VAR',
  396. tokens: [
  397. { startIndex: 0, type: 'keyword.directive.cpp' },
  398. { startIndex: 6, type: '' },
  399. { startIndex: 7, type: 'identifier.cpp' }
  400. ]
  401. },
  402. {
  403. line: '#define SUM(A,B) (A) + (B)',
  404. tokens: [
  405. { startIndex: 0, type: 'keyword.directive.cpp' },
  406. { startIndex: 7, type: '' },
  407. { startIndex: 8, type: 'identifier.cpp' },
  408. { startIndex: 11, type: 'delimiter.parenthesis.cpp' },
  409. { startIndex: 12, type: 'identifier.cpp' },
  410. { startIndex: 13, type: 'delimiter.cpp' },
  411. { startIndex: 14, type: 'identifier.cpp' },
  412. { startIndex: 15, type: 'delimiter.parenthesis.cpp' },
  413. { startIndex: 16, type: '' },
  414. { startIndex: 17, type: 'delimiter.parenthesis.cpp' },
  415. { startIndex: 18, type: 'identifier.cpp' },
  416. { startIndex: 19, type: 'delimiter.parenthesis.cpp' },
  417. { startIndex: 20, type: '' },
  418. { startIndex: 21, type: 'delimiter.cpp' },
  419. { startIndex: 22, type: '' },
  420. { startIndex: 23, type: 'delimiter.parenthesis.cpp' },
  421. { startIndex: 24, type: 'identifier.cpp' },
  422. { startIndex: 25, type: 'delimiter.parenthesis.cpp' }
  423. ]
  424. },
  425. {
  426. line: '',
  427. tokens: []
  428. },
  429. {
  430. line: 'int main(int argc, char** argv)',
  431. tokens: [
  432. { startIndex: 0, type: 'keyword.int.cpp' },
  433. { startIndex: 3, type: '' },
  434. { startIndex: 4, type: 'identifier.cpp' },
  435. { startIndex: 8, type: 'delimiter.parenthesis.cpp' },
  436. { startIndex: 9, type: 'keyword.int.cpp' },
  437. { startIndex: 12, type: '' },
  438. { startIndex: 13, type: 'identifier.cpp' },
  439. { startIndex: 17, type: 'delimiter.cpp' },
  440. { startIndex: 18, type: '' },
  441. { startIndex: 19, type: 'keyword.char.cpp' },
  442. { startIndex: 23, type: '' },
  443. { startIndex: 26, type: 'identifier.cpp' },
  444. { startIndex: 30, type: 'delimiter.parenthesis.cpp' }
  445. ]
  446. },
  447. {
  448. line: '{',
  449. tokens: [{ startIndex: 0, type: 'delimiter.curly.cpp' }]
  450. },
  451. {
  452. line: ' return 0;',
  453. tokens: [
  454. { startIndex: 0, type: '' },
  455. { startIndex: 1, type: 'keyword.return.cpp' },
  456. { startIndex: 7, type: '' },
  457. { startIndex: 8, type: 'number.cpp' },
  458. { startIndex: 9, type: 'delimiter.cpp' }
  459. ]
  460. },
  461. {
  462. line: '}',
  463. tokens: [{ startIndex: 0, type: 'delimiter.curly.cpp' }]
  464. },
  465. {
  466. line: '',
  467. tokens: []
  468. },
  469. {
  470. line: 'namespace TestSpace',
  471. tokens: [
  472. { startIndex: 0, type: 'keyword.namespace.cpp' },
  473. { startIndex: 9, type: '' },
  474. { startIndex: 10, type: 'identifier.cpp' }
  475. ]
  476. },
  477. {
  478. line: '{',
  479. tokens: [{ startIndex: 0, type: 'delimiter.curly.cpp' }]
  480. },
  481. {
  482. line: ' using Asdf.CDE;',
  483. tokens: [
  484. { startIndex: 0, type: '' },
  485. { startIndex: 1, type: 'keyword.using.cpp' },
  486. { startIndex: 6, type: '' },
  487. { startIndex: 7, type: 'identifier.cpp' },
  488. { startIndex: 11, type: 'delimiter.cpp' },
  489. { startIndex: 12, type: 'identifier.cpp' },
  490. { startIndex: 15, type: 'delimiter.cpp' }
  491. ]
  492. },
  493. {
  494. line: ' template <typename T>',
  495. tokens: [
  496. { startIndex: 0, type: '' },
  497. { startIndex: 1, type: 'keyword.template.cpp' },
  498. { startIndex: 9, type: '' },
  499. { startIndex: 10, type: 'delimiter.angle.cpp' },
  500. { startIndex: 11, type: 'keyword.typename.cpp' },
  501. { startIndex: 19, type: '' },
  502. { startIndex: 20, type: 'identifier.cpp' },
  503. { startIndex: 21, type: 'delimiter.angle.cpp' }
  504. ]
  505. },
  506. {
  507. line: ' class CoolClass : protected BaseClass',
  508. tokens: [
  509. { startIndex: 0, type: '' },
  510. { startIndex: 1, type: 'keyword.class.cpp' },
  511. { startIndex: 6, type: '' },
  512. { startIndex: 7, type: 'identifier.cpp' },
  513. { startIndex: 16, type: '' },
  514. { startIndex: 17, type: 'delimiter.cpp' },
  515. { startIndex: 18, type: '' },
  516. { startIndex: 19, type: 'keyword.protected.cpp' },
  517. { startIndex: 28, type: '' },
  518. { startIndex: 29, type: 'identifier.cpp' }
  519. ]
  520. },
  521. {
  522. line: ' {',
  523. tokens: [
  524. { startIndex: 0, type: '' },
  525. { startIndex: 1, type: 'delimiter.curly.cpp' }
  526. ]
  527. },
  528. {
  529. line: ' private:',
  530. tokens: [
  531. { startIndex: 0, type: '' },
  532. { startIndex: 2, type: 'keyword.private.cpp' },
  533. { startIndex: 9, type: 'delimiter.cpp' }
  534. ]
  535. },
  536. {
  537. line: ' ',
  538. tokens: [{ startIndex: 0, type: '' }]
  539. },
  540. {
  541. line: ' static T field;',
  542. tokens: [
  543. { startIndex: 0, type: '' },
  544. { startIndex: 2, type: 'keyword.static.cpp' },
  545. { startIndex: 8, type: '' },
  546. { startIndex: 9, type: 'identifier.cpp' },
  547. { startIndex: 10, type: '' },
  548. { startIndex: 11, type: 'identifier.cpp' },
  549. { startIndex: 16, type: 'delimiter.cpp' }
  550. ]
  551. },
  552. {
  553. line: ' ',
  554. tokens: [{ startIndex: 0, type: '' }]
  555. },
  556. {
  557. line: ' public:',
  558. tokens: [
  559. { startIndex: 0, type: '' },
  560. { startIndex: 2, type: 'keyword.public.cpp' },
  561. { startIndex: 8, type: 'delimiter.cpp' }
  562. ]
  563. },
  564. {
  565. line: ' ',
  566. tokens: [{ startIndex: 0, type: '' }]
  567. },
  568. {
  569. line: ' [[deprecated]]',
  570. tokens: [
  571. { startIndex: 0, type: '' },
  572. { startIndex: 2, type: 'annotation.cpp' }
  573. ]
  574. },
  575. {
  576. line: ' foo method() const override',
  577. tokens: [
  578. { startIndex: 0, type: '' },
  579. { startIndex: 2, type: 'identifier.cpp' },
  580. { startIndex: 5, type: '' },
  581. { startIndex: 6, type: 'identifier.cpp' },
  582. { startIndex: 12, type: 'delimiter.parenthesis.cpp' },
  583. { startIndex: 14, type: '' },
  584. { startIndex: 15, type: 'keyword.const.cpp' },
  585. { startIndex: 20, type: '' },
  586. { startIndex: 21, type: 'keyword.override.cpp' }
  587. ]
  588. },
  589. {
  590. line: ' {',
  591. tokens: [
  592. { startIndex: 0, type: '' },
  593. { startIndex: 2, type: 'delimiter.curly.cpp' }
  594. ]
  595. },
  596. {
  597. line: ' auto s = new Bar();',
  598. tokens: [
  599. { startIndex: 0, type: '' },
  600. { startIndex: 3, type: 'keyword.auto.cpp' },
  601. { startIndex: 7, type: '' },
  602. { startIndex: 8, type: 'identifier.cpp' },
  603. { startIndex: 9, type: '' },
  604. { startIndex: 10, type: 'delimiter.cpp' },
  605. { startIndex: 11, type: '' },
  606. { startIndex: 12, type: 'keyword.new.cpp' },
  607. { startIndex: 15, type: '' },
  608. { startIndex: 16, type: 'identifier.cpp' },
  609. { startIndex: 19, type: 'delimiter.parenthesis.cpp' },
  610. { startIndex: 21, type: 'delimiter.cpp' }
  611. ]
  612. },
  613. {
  614. line: ' ',
  615. tokens: [{ startIndex: 0, type: '' }]
  616. },
  617. {
  618. line: ' if (s.field) {',
  619. tokens: [
  620. { startIndex: 0, type: '' },
  621. { startIndex: 3, type: 'keyword.if.cpp' },
  622. { startIndex: 5, type: '' },
  623. { startIndex: 6, type: 'delimiter.parenthesis.cpp' },
  624. { startIndex: 7, type: 'identifier.cpp' },
  625. { startIndex: 8, type: 'delimiter.cpp' },
  626. { startIndex: 9, type: 'identifier.cpp' },
  627. { startIndex: 14, type: 'delimiter.parenthesis.cpp' },
  628. { startIndex: 15, type: '' },
  629. { startIndex: 16, type: 'delimiter.curly.cpp' }
  630. ]
  631. },
  632. {
  633. line: ' for(const auto & b : s.field) {',
  634. tokens: [
  635. { startIndex: 0, type: '' },
  636. { startIndex: 4, type: 'keyword.for.cpp' },
  637. { startIndex: 7, type: 'delimiter.parenthesis.cpp' },
  638. { startIndex: 8, type: 'keyword.const.cpp' },
  639. { startIndex: 13, type: '' },
  640. { startIndex: 14, type: 'keyword.auto.cpp' },
  641. { startIndex: 18, type: '' },
  642. { startIndex: 19, type: 'delimiter.cpp' },
  643. { startIndex: 20, type: '' },
  644. { startIndex: 21, type: 'identifier.cpp' },
  645. { startIndex: 22, type: '' },
  646. { startIndex: 23, type: 'delimiter.cpp' },
  647. { startIndex: 24, type: '' },
  648. { startIndex: 25, type: 'identifier.cpp' },
  649. { startIndex: 26, type: 'delimiter.cpp' },
  650. { startIndex: 27, type: 'identifier.cpp' },
  651. { startIndex: 32, type: 'delimiter.parenthesis.cpp' },
  652. { startIndex: 33, type: '' },
  653. { startIndex: 34, type: 'delimiter.curly.cpp' }
  654. ]
  655. },
  656. {
  657. line: ' break;',
  658. tokens: [
  659. { startIndex: 0, type: '' },
  660. { startIndex: 5, type: 'keyword.break.cpp' },
  661. { startIndex: 10, type: 'delimiter.cpp' }
  662. ]
  663. },
  664. {
  665. line: ' }',
  666. tokens: [
  667. { startIndex: 0, type: '' },
  668. { startIndex: 4, type: 'delimiter.curly.cpp' }
  669. ]
  670. },
  671. {
  672. line: ' }',
  673. tokens: [
  674. { startIndex: 0, type: '' },
  675. { startIndex: 3, type: 'delimiter.curly.cpp' }
  676. ]
  677. },
  678. {
  679. line: ' }',
  680. tokens: [
  681. { startIndex: 0, type: '' },
  682. { startIndex: 2, type: 'delimiter.curly.cpp' }
  683. ]
  684. },
  685. {
  686. line: ' ',
  687. tokens: [{ startIndex: 0, type: '' }]
  688. },
  689. {
  690. line: ' std::string s = "hello wordld\\n";',
  691. tokens: [
  692. { startIndex: 0, type: '' },
  693. { startIndex: 2, type: 'identifier.cpp' },
  694. { startIndex: 5, type: '' },
  695. { startIndex: 7, type: 'identifier.cpp' },
  696. { startIndex: 13, type: '' },
  697. { startIndex: 14, type: 'identifier.cpp' },
  698. { startIndex: 15, type: '' },
  699. { startIndex: 16, type: 'delimiter.cpp' },
  700. { startIndex: 17, type: '' },
  701. { startIndex: 18, type: 'string.cpp' },
  702. { startIndex: 31, type: 'string.escape.cpp' },
  703. { startIndex: 33, type: 'string.cpp' },
  704. { startIndex: 34, type: 'delimiter.cpp' }
  705. ]
  706. },
  707. {
  708. line: ' ',
  709. tokens: [{ startIndex: 0, type: '' }]
  710. },
  711. {
  712. line: " int number = 123'123'123Ull;",
  713. tokens: [
  714. { startIndex: 0, type: '' },
  715. { startIndex: 2, type: 'keyword.int.cpp' },
  716. { startIndex: 5, type: '' },
  717. { startIndex: 6, type: 'identifier.cpp' },
  718. { startIndex: 12, type: '' },
  719. { startIndex: 13, type: 'delimiter.cpp' },
  720. { startIndex: 14, type: '' },
  721. { startIndex: 15, type: 'number.cpp' },
  722. { startIndex: 29, type: 'delimiter.cpp' }
  723. ]
  724. },
  725. {
  726. line: ' }',
  727. tokens: [
  728. { startIndex: 0, type: '' },
  729. { startIndex: 1, type: 'delimiter.curly.cpp' }
  730. ]
  731. },
  732. {
  733. line: '}',
  734. tokens: [{ startIndex: 0, type: 'delimiter.curly.cpp' }]
  735. },
  736. {
  737. line: '',
  738. tokens: []
  739. },
  740. {
  741. line: '#endif',
  742. tokens: [{ startIndex: 0, type: 'keyword.directive.cpp' }]
  743. },
  744. {
  745. line: '# ifdef VAR',
  746. tokens: [
  747. { startIndex: 0, type: 'keyword.directive.cpp' },
  748. { startIndex: 10, type: '' },
  749. { startIndex: 11, type: 'identifier.cpp' }
  750. ]
  751. },
  752. {
  753. line: '# define SUM(A,B) (A) + (B)',
  754. tokens: [
  755. { startIndex: 0, type: 'keyword.directive.cpp' },
  756. { startIndex: 8, type: '' },
  757. { startIndex: 9, type: 'identifier.cpp' },
  758. { startIndex: 12, type: 'delimiter.parenthesis.cpp' },
  759. { startIndex: 13, type: 'identifier.cpp' },
  760. { startIndex: 14, type: 'delimiter.cpp' },
  761. { startIndex: 15, type: 'identifier.cpp' },
  762. { startIndex: 16, type: 'delimiter.parenthesis.cpp' },
  763. { startIndex: 17, type: '' },
  764. { startIndex: 18, type: 'delimiter.parenthesis.cpp' },
  765. { startIndex: 19, type: 'identifier.cpp' },
  766. { startIndex: 20, type: 'delimiter.parenthesis.cpp' },
  767. { startIndex: 21, type: '' },
  768. { startIndex: 22, type: 'delimiter.cpp' },
  769. { startIndex: 23, type: '' },
  770. { startIndex: 24, type: 'delimiter.parenthesis.cpp' },
  771. { startIndex: 25, type: 'identifier.cpp' },
  772. { startIndex: 26, type: 'delimiter.parenthesis.cpp' }
  773. ]
  774. },
  775. {
  776. line: 'uR"V0G0N(abc)V0G0N"def',
  777. tokens: [
  778. { startIndex: 0, type: 'string.raw.begin.cpp' },
  779. { startIndex: 9, type: 'string.raw.cpp' },
  780. { startIndex: 12, type: 'string.raw.end.cpp' },
  781. { startIndex: 19, type: 'identifier.cpp' }
  782. ]
  783. }
  784. ],
  785. // https://github.com/microsoft/monaco-editor/issues/1951
  786. [
  787. {
  788. line: 'auto sv = R"({ "message": "Hello World" })""\\n"sv;',
  789. tokens: [
  790. { startIndex: 0, type: 'keyword.auto.cpp' },
  791. { startIndex: 4, type: '' },
  792. { startIndex: 5, type: 'identifier.cpp' },
  793. { startIndex: 7, type: '' },
  794. { startIndex: 8, type: 'delimiter.cpp' },
  795. { startIndex: 9, type: '' },
  796. { startIndex: 10, type: 'string.raw.begin.cpp' },
  797. { startIndex: 13, type: 'string.raw.cpp' },
  798. { startIndex: 41, type: 'string.raw.end.cpp' },
  799. { startIndex: 43, type: 'string.cpp' },
  800. { startIndex: 44, type: 'string.escape.cpp' },
  801. { startIndex: 46, type: 'string.cpp' },
  802. { startIndex: 47, type: 'identifier.cpp' },
  803. { startIndex: 49, type: 'delimiter.cpp' }
  804. ]
  805. },
  806. {
  807. line: ' // This is a comment, not a string',
  808. tokens: [
  809. { startIndex: 0, type: '' },
  810. { startIndex: 4, type: 'comment.cpp' }
  811. ]
  812. }
  813. ],
  814. // Annotations
  815. [
  816. {
  817. line: '[[nodiscard]]',
  818. tokens: [{ startIndex: 0, type: 'annotation.cpp' }]
  819. }
  820. ],
  821. [
  822. {
  823. // Example from http://eel.is/c++draft/dcl.attr
  824. line: '[[using CC: opt(1), debug]]',
  825. tokens: [
  826. { startIndex: 0, type: 'annotation.cpp' }, // [[
  827. { startIndex: 2, type: 'keyword.cpp' }, // using
  828. { startIndex: 7, type: '' },
  829. { startIndex: 8, type: 'annotation.cpp' }, // CC
  830. { startIndex: 10, type: 'delimiter.cpp' }, // colon
  831. { startIndex: 11, type: '' },
  832. { startIndex: 12, type: 'annotation.cpp' }, // opt
  833. { startIndex: 15, type: 'delimiter.parenthesis.cpp' }, // (
  834. { startIndex: 16, type: 'annotation.cpp' }, // 1
  835. { startIndex: 17, type: 'delimiter.parenthesis.cpp' }, // )
  836. { startIndex: 18, type: 'delimiter.cpp' }, // ,
  837. { startIndex: 19, type: '' },
  838. { startIndex: 20, type: 'annotation.cpp' } // debug]]
  839. ]
  840. }
  841. ],
  842. [
  843. // Multiline and comments.
  844. {
  845. line: '[[nodiscard /*commented*/',
  846. tokens: [
  847. { startIndex: 0, type: 'annotation.cpp' },
  848. { startIndex: 11, type: '' },
  849. { startIndex: 12, type: 'comment.cpp' }
  850. ]
  851. },
  852. {
  853. line: ']] int i;',
  854. tokens: [
  855. { startIndex: 0, type: 'annotation.cpp' },
  856. { startIndex: 2, type: '' },
  857. { startIndex: 3, type: 'keyword.int.cpp' },
  858. { startIndex: 6, type: '' },
  859. { startIndex: 7, type: 'identifier.cpp' },
  860. { startIndex: 8, type: 'delimiter.cpp' }
  861. ]
  862. }
  863. ],
  864. [
  865. // We don't support newlines between annotation square brackets, but we do support other whitespace.
  866. {
  867. line: '[ [nodiscard] ]',
  868. tokens: [{ startIndex: 0, type: 'annotation.cpp' }]
  869. }
  870. ],
  871. // Preprocessor directives with whitespace inamongst the characters,
  872. // and crucially checking with whitespace before the initial #.
  873. [
  874. {
  875. line: ' # if defined(SOMETHING)',
  876. tokens: [
  877. { startIndex: 0, type: 'keyword.directive.cpp' },
  878. { startIndex: 5, type: '' },
  879. { startIndex: 6, type: 'identifier.cpp' },
  880. { startIndex: 13, type: 'delimiter.parenthesis.cpp' },
  881. { startIndex: 14, type: 'identifier.cpp' },
  882. { startIndex: 23, type: 'delimiter.parenthesis.cpp' }
  883. ]
  884. },
  885. {
  886. line: ' #include <io.h>',
  887. tokens: [
  888. { startIndex: 0, type: 'keyword.directive.include.cpp' },
  889. { startIndex: 16, type: '' },
  890. { startIndex: 17, type: 'keyword.directive.include.begin.cpp' },
  891. { startIndex: 18, type: 'string.include.identifier.cpp' },
  892. { startIndex: 22, type: 'keyword.directive.include.end.cpp' }
  893. ]
  894. },
  895. {
  896. line: ' # include <io.h>',
  897. tokens: [
  898. { startIndex: 0, type: 'keyword.directive.include.cpp' },
  899. { startIndex: 16, type: '' },
  900. { startIndex: 17, type: 'keyword.directive.include.begin.cpp' },
  901. { startIndex: 18, type: 'string.include.identifier.cpp' },
  902. { startIndex: 22, type: 'keyword.directive.include.end.cpp' }
  903. ]
  904. }
  905. ],
  906. [
  907. // microsoft/monaco-editor#2497 : comment continuation highlighting
  908. {
  909. line: '// this is a comment \\',
  910. tokens: [{ startIndex: 0, type: 'comment.cpp' }]
  911. },
  912. {
  913. line: 'this is still a comment',
  914. tokens: [{ startIndex: 0, type: 'comment.cpp' }]
  915. },
  916. {
  917. line: 'int x = 1;',
  918. tokens: [
  919. { startIndex: 0, type: 'keyword.int.cpp' },
  920. { startIndex: 3, type: '' },
  921. { startIndex: 4, type: 'identifier.cpp' },
  922. { startIndex: 5, type: '' },
  923. { startIndex: 6, type: 'delimiter.cpp' },
  924. { startIndex: 7, type: '' },
  925. { startIndex: 8, type: 'number.cpp' },
  926. { startIndex: 9, type: 'delimiter.cpp' }
  927. ]
  928. }
  929. ]
  930. ]);