carbon.tmLanguage.json 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. {
  2. "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  3. "name": "carbon",
  4. "scopeName": "source.carbon",
  5. "foldingStartMarker": "\\{\\s*$",
  6. "foldingStopMarker": "^\\s*\\}",
  7. "fileTypes": ["carbon"],
  8. "patterns": [
  9. {
  10. "include": "#comments"
  11. },
  12. {
  13. "include": "#strings"
  14. },
  15. {
  16. "include": "#types"
  17. },
  18. {
  19. "include": "#functions"
  20. },
  21. {
  22. "include": "#variables"
  23. },
  24. {
  25. "include": "#operators"
  26. },
  27. {
  28. "include": "#special-keywords"
  29. },
  30. {
  31. "include": "#introducer-keywords"
  32. },
  33. {
  34. "include": "#modifier-keywords"
  35. },
  36. {
  37. "include": "#misc-keywords"
  38. },
  39. {
  40. "include": "#self-keywords"
  41. },
  42. {
  43. "include": "#underscore"
  44. },
  45. {
  46. "include": "#true-false"
  47. },
  48. {
  49. "include": "#type-literals"
  50. },
  51. {
  52. "include": "#numbers"
  53. },
  54. {
  55. "include": "#parameter-bindings"
  56. },
  57. {
  58. "include": "#customs"
  59. }
  60. ],
  61. "repository": {
  62. "comments": {
  63. "patterns": [
  64. {
  65. "name": "comment.line.carbon",
  66. "match": "^\\s*(?=//\\s).*$"
  67. },
  68. {
  69. "name": "comment.line.carbon",
  70. "match": "^\\s*//@dump-sem-ir-(begin|end)\\s*$"
  71. },
  72. {
  73. "name": "comment.line.carbon",
  74. "match": "^\\s*//@include-in-dumps\\s*$"
  75. }
  76. ]
  77. },
  78. "string_escapes": {
  79. "patterns": [
  80. {
  81. "name": "constant.character.escape.carbon",
  82. "match": "\\\\([tnr'\"0\\0]|x[0-9A-F]{2}|u\\{[0-9A-F]{4,}\\})"
  83. }
  84. ]
  85. },
  86. "strings": {
  87. "patterns": [
  88. {
  89. "name": "string.quoted.triple.carbon",
  90. "begin": "'''([^\\s'#]*\\n)?",
  91. "end": "'''",
  92. "beginCaptures": {
  93. "1": {
  94. "name": "constant.character.escape.carbon"
  95. }
  96. },
  97. "patterns": [
  98. {
  99. "include": "#string_escapes"
  100. }
  101. ]
  102. },
  103. {
  104. "name": "string.quoted.double.carbon",
  105. "begin": "\"",
  106. "end": "\"",
  107. "patterns": [
  108. {
  109. "include": "#string_escapes"
  110. }
  111. ]
  112. }
  113. ]
  114. },
  115. "types": {
  116. "name": "meta.type.carbon",
  117. "patterns": [
  118. {
  119. "comment": "Matches type, constraint, and implementation declarations, and explicit casts.",
  120. "begin": "\\b((adapt|alias|class|constraint|interface|impl)|(as|impls))\\b",
  121. "beginCaptures": {
  122. "2": { "name": "storage.type.carbon" },
  123. "3": { "name": "keyword.control.carbon" }
  124. },
  125. "end": "(?=[;{])",
  126. "patterns": [
  127. { "include": "#common" },
  128. { "include": "#parameter-bindings" },
  129. {
  130. "name": "support.type.carbon",
  131. "match": "\\w+"
  132. }
  133. ]
  134. },
  135. {
  136. "comment": "Matches types in bindings.",
  137. "begin": ":!?",
  138. "end": "(?=([;{=]|->|in|where))",
  139. "patterns": [
  140. { "include": "#common" },
  141. { "include": "#variables" },
  142. { "include": "#parameter-bindings" },
  143. {
  144. "name": "support.type.carbon",
  145. "match": "\\w+"
  146. }
  147. ]
  148. },
  149. {
  150. "comment": "Matches function return types.",
  151. "begin": "->",
  152. "end": "(?=([;{]|=>))",
  153. "patterns": [
  154. { "include": "#common" },
  155. {
  156. "name": "support.type.carbon",
  157. "match": "\\w+"
  158. }
  159. ]
  160. },
  161. {
  162. "comment": "Matches types in where clause.",
  163. "begin": "\\bwhere\\b",
  164. "beginCaptures": {
  165. "0": { "name": "keyword.control.carbon" }
  166. },
  167. "end": "(?=[;{])",
  168. "patterns": [
  169. { "include": "#common" },
  170. { "include": "#variables" },
  171. { "include": "#parameter-bindings" },
  172. {
  173. "name": "support.type.carbon",
  174. "match": "\\w+"
  175. }
  176. ]
  177. },
  178. {
  179. "comment": "Matches choices.",
  180. "begin": "\\bchoice\\b",
  181. "beginCaptures": {
  182. "0": { "name": "storage.type.carbon" }
  183. },
  184. "end": "(?=[;}])",
  185. "patterns": [
  186. { "include": "#common" },
  187. { "include": "#variables" },
  188. { "include": "#parameter-bindings" },
  189. {
  190. "name": "support.type.carbon",
  191. "match": "\\w+"
  192. },
  193. {
  194. "comment": "Matches the choice values.",
  195. "begin": "\\{",
  196. "end": "(?=})",
  197. "patterns": [
  198. { "include": "#common" },
  199. {
  200. "name": "variable.other.enummember.carbon",
  201. "match": "\\w+"
  202. }
  203. ]
  204. }
  205. ]
  206. }
  207. ]
  208. },
  209. "functions": {
  210. "name": "meta.function.carbon",
  211. "patterns": [
  212. {
  213. "comment": "Matches function declarations.",
  214. "begin": "\\bfn\\b",
  215. "beginCaptures": {
  216. "0": { "name": "storage.type.carbon" }
  217. },
  218. "end": "(?=[\\[\\(])",
  219. "patterns": [
  220. { "include": "#common" },
  221. {
  222. "name": "support.function.carbon",
  223. "match": "\\w+"
  224. }
  225. ]
  226. }
  227. ]
  228. },
  229. "variables": {
  230. "name": "meta.variable.carbon",
  231. "patterns": [
  232. {
  233. "comment": "Matches variable declarations.",
  234. "begin": "\\b(var|let)\\b",
  235. "beginCaptures": {
  236. "0": { "name": "storage.type.carbon" }
  237. },
  238. "end": "(?=:)",
  239. "patterns": [
  240. { "include": "#common" },
  241. {
  242. "name": "support.variable.carbon",
  243. "match": "\\w+"
  244. }
  245. ]
  246. }
  247. ]
  248. },
  249. "operators": {
  250. "patterns": [
  251. {
  252. "name": "keyword.operator.carbon",
  253. "match": "\\b(>>=|<=>|<<=|\\&=|==|!=|>=|>>|<=|<<|-=|->|--|%=|\\|=|\\+=|\\+\\+|/=|\\*=|\\&|\\^|=|>|<|-|%|\\.|\\||\\+|/|\\*)\\b"
  254. },
  255. {
  256. "name": "keyword.control.carbon",
  257. "match": "\\b(and|as|impls|in|like|not|or|partial|ref|template|where)\\b"
  258. }
  259. ]
  260. },
  261. "special-keywords": {
  262. "patterns": [
  263. {
  264. "name": "keyword.control.carbon",
  265. "match": "\\b(break|case|continue|else|if|for|match|return|returned|then|while)\\b"
  266. },
  267. {
  268. "name": "keyword.control.carbon",
  269. "match": "\\b(default)\\b(?=\\s*=>)"
  270. }
  271. ]
  272. },
  273. "introducer-keywords": {
  274. "patterns": [
  275. {
  276. "name": "storage.type.carbon",
  277. "match": "\\b(adapt|alias|choice|class|constraint|fn|import|interface|let|library|namespace|var)\\b"
  278. },
  279. {
  280. "name": "storage.type.carbon",
  281. "match": "\\b(base)\\b(?!\\s*class\\b)"
  282. },
  283. {
  284. "name": "storage.type.carbon",
  285. "match": "\\b(export)\\b(?!\\s*import\\b)"
  286. },
  287. {
  288. "name": "storage.type.carbon",
  289. "match": "\\b(impl)\\b(?!\\s*(fn|library|package)\\b)"
  290. },
  291. {
  292. "name": "storage.type.carbon",
  293. "match": "\\b(package)\\b(?!\\.)"
  294. }
  295. ]
  296. },
  297. "modifier-keywords": {
  298. "patterns": [
  299. {
  300. "name": "storage.modifier.carbon",
  301. "match": "\\b(abstract|const|extend|extern|final|private|protected|static|virtual)\\b"
  302. },
  303. {
  304. "name": "storage.modifier.carbon",
  305. "match": "\\b(base)\\b(?=\\s*class\\b)"
  306. },
  307. {
  308. "name": "storage.modifier.carbon",
  309. "match": "\\b(default)\\b(?!\\s*=>)"
  310. },
  311. {
  312. "name": "storage.modifier.carbon",
  313. "match": "\\b(export)\\b(?=\\s*import\\b)"
  314. },
  315. {
  316. "name": "storage.modifier.carbon",
  317. "match": "\\b(impl)\\b(?=\\s*(fn|library|package)\\b)"
  318. }
  319. ]
  320. },
  321. "misc-keywords": {
  322. "patterns": [
  323. {
  324. "name": "keyword.other.carbon",
  325. "match": "\\b(auto|destructor|forall|friend|observe|override|require)\\b"
  326. },
  327. {
  328. "name": "keyword.other.carbon",
  329. "match": "(?<=\\.)\\b(base)\\b"
  330. }
  331. ]
  332. },
  333. "self-keywords": {
  334. "patterns": [
  335. {
  336. "name": "variable.language.carbon",
  337. "match": "\\b(self|Self)\\b"
  338. }
  339. ]
  340. },
  341. "underscore": {
  342. "patterns": [
  343. {
  344. "name": "variable.language.carbon",
  345. "match": "\\b(_)\\b"
  346. }
  347. ]
  348. },
  349. "true-false": {
  350. "patterns": [
  351. {
  352. "name": "constant.language.carbon",
  353. "match": "\\b(true|false)\\b"
  354. }
  355. ]
  356. },
  357. "type-literals": {
  358. "patterns": [
  359. {
  360. "name": "constant.language.carbon",
  361. "match": "\\b(array|bool|char|str|type)\\b"
  362. },
  363. {
  364. "name": "constant.language.carbon",
  365. "comment": "Match common numeric type literals. Language server should highlight other valid literals.",
  366. "match": "\\b[iuf](8|16|32|64|128)\\b"
  367. }
  368. ]
  369. },
  370. "numbers": {
  371. "comment": "Invalid formats are also highlighted. Language server handles error highlighting",
  372. "patterns": [
  373. {
  374. "name": "constant.numeric.carbon",
  375. "match": "0x[_0-9a-fA-F]*(\\.[_0-9a-fA-F]+(p[-+]?[0-9]+)?)?"
  376. },
  377. {
  378. "name": "constant.numeric.carbon",
  379. "match": "0b[_01]*"
  380. },
  381. {
  382. "name": "constant.numeric.carbon",
  383. "match": "[0-9][_0-9]*(\\.[_0-9]+(e[-+]?[0-9]+)?)?"
  384. }
  385. ]
  386. },
  387. "parameter-bindings": {
  388. "patterns": [
  389. {
  390. "comment": "Matches parameter bindings.",
  391. "match": "\\b(\\w+)\\s*(?=:)",
  392. "captures": {
  393. "1": { "name": "support.variable.carbon" }
  394. }
  395. }
  396. ]
  397. },
  398. "customs": {
  399. "comment": "For rules that should be checked last.",
  400. "patterns": [
  401. {
  402. "name": "support.class.carbon",
  403. "match": "(?<=\\b(package|Core)\\s)\\w+"
  404. },
  405. {
  406. "name": "support.type.property-name.carbon",
  407. "match": "(?<=\\bimport\\s)\\w+"
  408. },
  409. {
  410. "comment": "Matches function calls.",
  411. "name": "support.function.carbon",
  412. "match": "\\b\\w+\\s*\\("
  413. },
  414. {
  415. "comment": "Matches unidentified words as variables.",
  416. "name": "support.variable.carbon",
  417. "match": "\\b\\w+\\b"
  418. }
  419. ]
  420. },
  421. "common": {
  422. "comments": [
  423. "For including comments, operators, keywords, literals, and language constants ",
  424. "in other rules that use begin/end. This way we do not accidentally override their ",
  425. "highlighting in complex rules."
  426. ],
  427. "patterns": [
  428. { "include": "#comments" },
  429. { "include": "#strings" },
  430. { "include": "#operators" },
  431. { "include": "#special-keywords" },
  432. { "include": "#introducer-keywords" },
  433. { "include": "#modifier-keywords" },
  434. { "include": "#misc-keywords" },
  435. { "include": "#self-keywords" },
  436. { "include": "#true-false" },
  437. { "include": "#type-literals" },
  438. { "include": "#numbers" }
  439. ]
  440. }
  441. }
  442. }