You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
11KB

  1. %YAML 1.2
  2. ---
  3. # http://www.sublimetext.com/docs/3/syntax.html
  4. name: Kotlin
  5. file_extensions:
  6. - kt
  7. - kts
  8. scope: source.Kotlin
  9. contexts:
  10. main:
  11. - include: comments
  12. - match: '^\s*(package)\b(?:\s*([^ ;$]+)\s*)?'
  13. captures:
  14. 1: keyword.other.kotlin
  15. 2: entity.name.package.kotlin
  16. - include: imports
  17. - include: statements
  18. classes:
  19. - match: (?=\s*(?:companion|class|object|interface))
  20. push:
  21. - match: "}|(?=$)"
  22. pop: true
  23. - match: \b(companion\s*)?(class|object|interface)\b
  24. captures:
  25. 1: keyword.other.kotlin
  26. push:
  27. - match: '(?=<|{|\(|:)'
  28. pop: true
  29. - match: \b(object)\b
  30. scope: keyword.other.kotlin
  31. - match: \w+
  32. scope: entity.name.type.class.kotlin
  33. - match: <
  34. push:
  35. - match: ">"
  36. pop: true
  37. - include: generics
  38. - match: \(
  39. push:
  40. - match: \)
  41. pop: true
  42. - include: parameters
  43. - match: (:)
  44. captures:
  45. 1: keyword.operator.declaration.kotlin
  46. push:
  47. - match: "(?={|$)"
  48. pop: true
  49. - match: \w+
  50. scope: entity.other.inherited-class.kotlin
  51. - match: \(
  52. push:
  53. - match: \)
  54. pop: true
  55. - include: expressions
  56. - match: '\{'
  57. push:
  58. - match: '\}'
  59. pop: true
  60. - include: statements
  61. comments:
  62. - match: /\*
  63. captures:
  64. 0: punctuation.definition.comment.kotlin
  65. push:
  66. - meta_scope: comment.block.kotlin
  67. - match: \*/
  68. captures:
  69. 0: punctuation.definition.comment.kotlin
  70. pop: true
  71. - match: \s*((//).*$\n?)
  72. captures:
  73. 1: comment.line.double-slash.kotlin
  74. 2: punctuation.definition.comment.kotlin
  75. constants:
  76. - match: \b(true|false|null|this|super)\b
  77. scope: constant.language.kotlin
  78. - match: '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)([LlFfUuDd]|UL|ul)?\b'
  79. scope: constant.numeric.kotlin
  80. - match: '\b([A-Z][A-Z0-9_]+)\b'
  81. scope: constant.other.kotlin
  82. expressions:
  83. - match: \(
  84. push:
  85. - match: \)
  86. pop: true
  87. - include: expressions
  88. - include: types
  89. - include: strings
  90. - include: constants
  91. - include: comments
  92. - include: keywords
  93. functions:
  94. - match: (?=\s*(?:fun))
  95. push:
  96. - match: "}|(?=$)"
  97. pop: true
  98. - match: \b(fun)\b
  99. captures:
  100. 1: keyword.other.kotlin
  101. push:
  102. - match: (?=\()
  103. pop: true
  104. - match: <
  105. push:
  106. - match: ">"
  107. pop: true
  108. - include: generics
  109. - match: '([\.<\?>\w]+\.)?(\w+)'
  110. captures:
  111. 2: entity.name.function.kotlin
  112. - match: \(
  113. push:
  114. - match: \)
  115. pop: true
  116. - include: parameters
  117. - match: (:)
  118. captures:
  119. 1: keyword.operator.declaration.kotlin
  120. push:
  121. - match: "(?={|=|$)"
  122. pop: true
  123. - include: types
  124. - match: '\{'
  125. push:
  126. - match: '(?=\})'
  127. pop: true
  128. - include: statements
  129. - match: (=)
  130. captures:
  131. 1: keyword.operator.assignment.kotlin
  132. push:
  133. - match: (?=$)
  134. pop: true
  135. - include: expressions
  136. generics:
  137. - match: (:)
  138. captures:
  139. 1: keyword.operator.declaration.kotlin
  140. push:
  141. - match: (?=,|>)
  142. pop: true
  143. - include: types
  144. - include: keywords
  145. - match: \w+
  146. scope: storage.type.generic.kotlin
  147. getters-and-setters:
  148. - match: \b(get)\b\s*\(\s*\)
  149. captures:
  150. 1: entity.name.function.kotlin
  151. push:
  152. - match: '\}|(?=\bset\b)|$'
  153. pop: true
  154. - match: (=)
  155. captures:
  156. 1: keyword.operator.assignment.kotlin
  157. push:
  158. - match: (?=$|\bset\b)
  159. pop: true
  160. - include: expressions
  161. - match: '\{'
  162. push:
  163. - match: '\}'
  164. pop: true
  165. - include: expressions
  166. - match: \b(set)\b\s*(?=\()
  167. captures:
  168. 1: entity.name.function.kotlin
  169. push:
  170. - match: '\}|(?=\bget\b)|$'
  171. pop: true
  172. - match: \(
  173. push:
  174. - match: \)
  175. pop: true
  176. - include: parameters
  177. - match: (=)
  178. captures:
  179. 1: keyword.operator.assignment.kotlin
  180. push:
  181. - match: (?=$|\bset\b)
  182. pop: true
  183. - include: expressions
  184. - match: '\{'
  185. push:
  186. - match: '\}'
  187. pop: true
  188. - include: expressions
  189. imports:
  190. - match: '^\s*(import)\s+[^ $]+\s+(as)?'
  191. captures:
  192. 1: keyword.other.kotlin
  193. 2: keyword.other.kotlin
  194. keywords:
  195. - match: \b(var|val|public|private|protected|abstract|final|enum|open|attribute|annotation|override|inline|var|val|vararg|lazy|in|out|internal|data|tailrec|operator|infix|const|yield|typealias|typeof)\b
  196. scope: storage.modifier.kotlin
  197. - match: \b(try|catch|finally|throw)\b
  198. scope: keyword.control.catch-exception.kotlin
  199. - match: \b(if|else|while|for|do|return|when|where|break|continue)\b
  200. scope: keyword.control.kotlin
  201. - match: \b(in|is|as|assert)\b
  202. scope: keyword.operator.kotlin
  203. - match: (==|!=|===|!==|<=|>=|<|>)
  204. scope: keyword.operator.comparison.kotlin
  205. - match: (=)
  206. scope: keyword.operator.assignment.kotlin
  207. - match: (:)
  208. scope: keyword.operator.declaration.kotlin
  209. - match: (\.)
  210. scope: keyword.operator.dot.kotlin
  211. - match: (\-\-|\+\+)
  212. scope: keyword.operator.increment-decrement.kotlin
  213. - match: (\-|\+|\*|\/|%)
  214. scope: keyword.operator.arithmetic.kotlin
  215. - match: (\+=|\-=|\*=|\/=)
  216. scope: keyword.operator.arithmetic.assign.kotlin
  217. - match: (!|&&|\|\|)
  218. scope: keyword.operator.logical.kotlin
  219. - match: (\.\.)
  220. scope: keyword.operator.range.kotlin
  221. - match: (;)
  222. scope: punctuation.terminator.kotlin
  223. namespaces:
  224. - match: \b(namespace)\b
  225. scope: keyword.other.kotlin
  226. - match: '\{'
  227. push:
  228. - match: '\}'
  229. pop: true
  230. - include: statements
  231. parameters:
  232. - match: (:)
  233. captures:
  234. 1: keyword.operator.declaration.kotlin
  235. push:
  236. - match: (?=,|\)|=)
  237. pop: true
  238. - include: types
  239. - match: (=)
  240. captures:
  241. 1: keyword.operator.declaration.kotlin
  242. push:
  243. - match: (?=,|\))
  244. pop: true
  245. - include: expressions
  246. - include: keywords
  247. - match: \w+
  248. scope: variable.parameter.function.kotlin
  249. statements:
  250. - include: namespaces
  251. - include: typedefs
  252. - include: classes
  253. - include: functions
  254. - include: variables
  255. - include: getters-and-setters
  256. - include: expressions
  257. strings:
  258. - match: '"""'
  259. captures:
  260. 0: punctuation.definition.string.begin.kotlin
  261. push:
  262. - meta_scope: string.quoted.third.kotlin
  263. - match: '"""'
  264. captures:
  265. 0: punctuation.definition.string.end.kotlin
  266. pop: true
  267. - match: '(\$\w+|\$\{[^\}]+\})'
  268. scope: variable.parameter.template.kotlin
  269. - match: \\.
  270. scope: constant.character.escape.kotlin
  271. - match: '"'
  272. captures:
  273. 0: punctuation.definition.string.begin.kotlin
  274. push:
  275. - meta_scope: string.quoted.double.kotlin
  276. - match: '"'
  277. captures:
  278. 0: punctuation.definition.string.end.kotlin
  279. pop: true
  280. - match: '(\$\w+|\$\{[^\}]+\})'
  281. scope: variable.parameter.template.kotlin
  282. - match: \\.
  283. scope: constant.character.escape.kotlin
  284. - match: "'"
  285. captures:
  286. 0: punctuation.definition.string.begin.kotlin
  287. push:
  288. - meta_scope: string.quoted.single.kotlin
  289. - match: "'"
  290. captures:
  291. 0: punctuation.definition.string.end.kotlin
  292. pop: true
  293. - match: \\.
  294. scope: constant.character.escape.kotlin
  295. - match: "`"
  296. captures:
  297. 0: punctuation.definition.string.begin.kotlin
  298. push:
  299. - meta_scope: string.quoted.single.kotlin
  300. - match: "`"
  301. captures:
  302. 0: punctuation.definition.string.end.kotlin
  303. pop: true
  304. typedefs:
  305. - match: (?=\s*(?:type))
  306. push:
  307. - match: (?=$)
  308. pop: true
  309. - match: \b(type)\b
  310. scope: keyword.other.kotlin
  311. - match: <
  312. push:
  313. - match: ">"
  314. pop: true
  315. - include: generics
  316. - include: expressions
  317. types:
  318. - match: \b(Any|Unit|String|Int|Boolean|Char|Long|Double|Float|Short|Byte|dynamic)\b
  319. scope: storage.type.buildin.kotlin
  320. - match: \b(IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray)\b
  321. scope: storage.type.buildin.array.kotlin
  322. - match: \b(Array|List|Map)<\b
  323. captures:
  324. 1: storage.type.buildin.collection.kotlin
  325. push:
  326. - match: ">"
  327. pop: true
  328. - include: types
  329. - include: keywords
  330. - match: \w+<
  331. push:
  332. - match: ">"
  333. pop: true
  334. - include: types
  335. - include: keywords
  336. - match: (#)\(
  337. captures:
  338. 1: keyword.operator.tuple.kotlin
  339. push:
  340. - match: \)
  341. pop: true
  342. - include: expressions
  343. - match: '\{'
  344. push:
  345. - match: '\}'
  346. pop: true
  347. - include: statements
  348. - match: \(
  349. push:
  350. - match: \)
  351. pop: true
  352. - include: types
  353. - match: (->)
  354. scope: keyword.operator.declaration.kotlin
  355. variables:
  356. - match: (?=\s*(?:var|val))
  357. push:
  358. - match: (?=:|=|$)
  359. pop: true
  360. - match: \b(var|val)\b
  361. captures:
  362. 1: keyword.other.kotlin
  363. push:
  364. - match: (?=:|=|$)
  365. pop: true
  366. - match: <
  367. push:
  368. - match: ">"
  369. pop: true
  370. - include: generics
  371. - match: '([\.<\?>\w]+\.)?(\w+)'
  372. captures:
  373. 2: entity.name.variable.kotlin
  374. - match: (:)
  375. captures:
  376. 1: keyword.operator.declaration.kotlin
  377. push:
  378. - match: (?==|$)
  379. pop: true
  380. - include: types
  381. - include: getters-and-setters
  382. - match: (=)
  383. captures:
  384. 1: keyword.operator.assignment.kotlin
  385. push:
  386. - match: (?=$)
  387. pop: true
  388. - include: expressions
  389. - include: getters-and-setters