| 1 |
{ |
| 2 |
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", |
| 3 |
"name": "kotlin", |
| 4 |
"scopeName": "source.kotlin", |
| 5 |
"patterns": [ |
| 6 |
{ |
| 7 |
"include": "#import" |
| 8 |
}, |
| 9 |
{ |
| 10 |
"include": "#package" |
| 11 |
}, |
| 12 |
{ |
| 13 |
"include": "#code" |
| 14 |
} |
| 15 |
], |
| 16 |
"fileTypes": ["kt", "kts"], |
| 17 |
"repository": { |
| 18 |
"import": { |
| 19 |
"begin": "\\b(import)\\b\\s*", |
| 20 |
"beginCaptures": { |
| 21 |
"1": { |
| 22 |
"name": "storage.type.import.kotlin" |
| 23 |
} |
| 24 |
}, |
| 25 |
"end": ";|$", |
| 26 |
"name": "meta.import.kotlin", |
| 27 |
"contentName": "entity.name.package.kotlin", |
| 28 |
"patterns": [ |
| 29 |
{ |
| 30 |
"include": "#comments" |
| 31 |
}, |
| 32 |
{ |
| 33 |
"include": "#hard-keywords" |
| 34 |
}, |
| 35 |
{ |
| 36 |
"match": "\\*", |
| 37 |
"name": "variable.language.wildcard.kotlin" |
| 38 |
} |
| 39 |
] |
| 40 |
}, |
| 41 |
"package": { |
| 42 |
"begin": "\\b(package)\\b\\s*", |
| 43 |
"beginCaptures": { |
| 44 |
"1": { |
| 45 |
"name": "storage.type.package.kotlin" |
| 46 |
} |
| 47 |
}, |
| 48 |
"end": ";|$", |
| 49 |
"name": "meta.package.kotlin", |
| 50 |
"contentName": "entity.name.package.kotlin", |
| 51 |
"patterns": [ |
| 52 |
{ |
| 53 |
"include": "#comments" |
| 54 |
} |
| 55 |
] |
| 56 |
}, |
| 57 |
"code": { |
| 58 |
"patterns": [ |
| 59 |
{ |
| 60 |
"include": "#comments" |
| 61 |
}, |
| 62 |
{ |
| 63 |
"include": "#keywords" |
| 64 |
}, |
| 65 |
{ |
| 66 |
"include": "#annotation-simple" |
| 67 |
}, |
| 68 |
{ |
| 69 |
"include": "#annotation-site-list" |
| 70 |
}, |
| 71 |
{ |
| 72 |
"include": "#annotation-site" |
| 73 |
}, |
| 74 |
{ |
| 75 |
"include": "#class-declaration" |
| 76 |
}, |
| 77 |
{ |
| 78 |
"include": "#object-declaration" |
| 79 |
}, |
| 80 |
{ |
| 81 |
"include": "#type-alias" |
| 82 |
}, |
| 83 |
{ |
| 84 |
"include": "#function-declaration" |
| 85 |
}, |
| 86 |
{ |
| 87 |
"include": "#variable-declaration" |
| 88 |
}, |
| 89 |
{ |
| 90 |
"include": "#type-constraint" |
| 91 |
}, |
| 92 |
{ |
| 93 |
"include": "#type-annotation" |
| 94 |
}, |
| 95 |
{ |
| 96 |
"include": "#function-call" |
| 97 |
}, |
| 98 |
{ |
| 99 |
"include": "#method-reference" |
| 100 |
}, |
| 101 |
{ |
| 102 |
"include": "#key" |
| 103 |
}, |
| 104 |
{ |
| 105 |
"include": "#string" |
| 106 |
}, |
| 107 |
{ |
| 108 |
"include": "#string-empty" |
| 109 |
}, |
| 110 |
{ |
| 111 |
"include": "#string-multiline" |
| 112 |
}, |
| 113 |
{ |
| 114 |
"include": "#character" |
| 115 |
}, |
| 116 |
{ |
| 117 |
"include": "#lambda-arrow" |
| 118 |
}, |
| 119 |
{ |
| 120 |
"include": "#operators" |
| 121 |
}, |
| 122 |
{ |
| 123 |
"include": "#self-reference" |
| 124 |
}, |
| 125 |
{ |
| 126 |
"include": "#decimal-literal" |
| 127 |
}, |
| 128 |
{ |
| 129 |
"include": "#hex-literal" |
| 130 |
}, |
| 131 |
{ |
| 132 |
"include": "#binary-literal" |
| 133 |
}, |
| 134 |
{ |
| 135 |
"include": "#boolean-literal" |
| 136 |
}, |
| 137 |
{ |
| 138 |
"include": "#null-literal" |
| 139 |
} |
| 140 |
] |
| 141 |
}, |
| 142 |
"comments": { |
| 143 |
"patterns": [ |
| 144 |
{ |
| 145 |
"include": "#comment-line" |
| 146 |
}, |
| 147 |
{ |
| 148 |
"include": "#comment-block" |
| 149 |
}, |
| 150 |
{ |
| 151 |
"include": "#comment-javadoc" |
| 152 |
} |
| 153 |
] |
| 154 |
}, |
| 155 |
"comment-line": { |
| 156 |
"begin": "//", |
| 157 |
"end": "$", |
| 158 |
"name": "comment.line.double-slash.kotlin" |
| 159 |
}, |
| 160 |
"comment-block": { |
| 161 |
"begin": "/\\*(?!\\*)", |
| 162 |
"end": "\\*/", |
| 163 |
"name": "comment.block.kotlin" |
| 164 |
}, |
| 165 |
"comment-javadoc": { |
| 166 |
"patterns": [ |
| 167 |
{ |
| 168 |
"begin": "/\\*\\*", |
| 169 |
"end": "\\*/", |
| 170 |
"name": "comment.block.javadoc.kotlin", |
| 171 |
"patterns": [ |
| 172 |
{ |
| 173 |
"match": "@(return|constructor|receiver|sample|see|author|since|suppress)\\b", |
| 174 |
"name": "keyword.other.documentation.javadoc.kotlin" |
| 175 |
}, |
| 176 |
{ |
| 177 |
"match": "(@param|@property)\\s+(\\S+)", |
| 178 |
"captures": { |
| 179 |
"1": { |
| 180 |
"name": "keyword.other.documentation.javadoc.kotlin" |
| 181 |
}, |
| 182 |
"2": { |
| 183 |
"name": "variable.parameter.kotlin" |
| 184 |
} |
| 185 |
} |
| 186 |
}, |
| 187 |
{ |
| 188 |
"match": "(@param)\\[(\\S+)\\]", |
| 189 |
"captures": { |
| 190 |
"1": { |
| 191 |
"name": "keyword.other.documentation.javadoc.kotlin" |
| 192 |
}, |
| 193 |
"2": { |
| 194 |
"name": "variable.parameter.kotlin" |
| 195 |
} |
| 196 |
} |
| 197 |
}, |
| 198 |
{ |
| 199 |
"match": "(@(?:exception|throws))\\s+(\\S+)", |
| 200 |
"captures": { |
| 201 |
"1": { |
| 202 |
"name": "keyword.other.documentation.javadoc.kotlin" |
| 203 |
}, |
| 204 |
"2": { |
| 205 |
"name": "entity.name.type.class.kotlin" |
| 206 |
} |
| 207 |
} |
| 208 |
}, |
| 209 |
{ |
| 210 |
"match": "{(@link)\\s+(\\S+)?#([\\w$]+\\s*\\([^\\(\\)]*\\)).*}", |
| 211 |
"captures": { |
| 212 |
"1": { |
| 213 |
"name": "keyword.other.documentation.javadoc.kotlin" |
| 214 |
}, |
| 215 |
"2": { |
| 216 |
"name": "entity.name.type.class.kotlin" |
| 217 |
}, |
| 218 |
"3": { |
| 219 |
"name": "variable.parameter.kotlin" |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
] |
| 224 |
} |
| 225 |
] |
| 226 |
}, |
| 227 |
"keywords": { |
| 228 |
"patterns": [ |
| 229 |
{ |
| 230 |
"include": "#prefix-modifiers" |
| 231 |
}, |
| 232 |
{ |
| 233 |
"include": "#postfix-modifiers" |
| 234 |
}, |
| 235 |
{ |
| 236 |
"include": "#soft-keywords" |
| 237 |
}, |
| 238 |
{ |
| 239 |
"include": "#hard-keywords" |
| 240 |
}, |
| 241 |
{ |
| 242 |
"include": "#control-keywords" |
| 243 |
} |
| 244 |
] |
| 245 |
}, |
| 246 |
"prefix-modifiers": { |
| 247 |
"match": "\\b(abstract|final|enum|open|annotation|sealed|data|override|final|lateinit|private|protected|public|internal|inner|companion|noinline|crossinline|vararg|reified|tailrec|operator|infix|inline|external|const|suspend|value)\\b", |
| 248 |
"name": "storage.modifier.other.kotlin" |
| 249 |
}, |
| 250 |
"postfix-modifiers": { |
| 251 |
"match": "\\b(where|by|get|set)\\b", |
| 252 |
"name": "storage.modifier.other.kotlin" |
| 253 |
}, |
| 254 |
"soft-keywords": { |
| 255 |
"match": "\\b(catch|finally|field)\\b", |
| 256 |
"name": "keyword.soft.kotlin" |
| 257 |
}, |
| 258 |
"hard-keywords": { |
| 259 |
"match": "\\b(as|typeof|is|in)\\b", |
| 260 |
"name": "keyword.hard.kotlin" |
| 261 |
}, |
| 262 |
"control-keywords": { |
| 263 |
"match": "\\b(if|else|while|do|when|try|throw|break|continue|return|for)\\b", |
| 264 |
"name": "keyword.control.kotlin" |
| 265 |
}, |
| 266 |
"annotation-simple": { |
| 267 |
"match": "(?<!\\w)@[\\w\\.]+\\b(?!:)", |
| 268 |
"name": "entity.name.type.annotation.kotlin" |
| 269 |
}, |
| 270 |
"annotation-site-list": { |
| 271 |
"begin": "(?<!\\w)(@\\w+):\\s*\\[", |
| 272 |
"end": "\\]", |
| 273 |
"beginCaptures": { |
| 274 |
"1": { |
| 275 |
"name": "entity.name.type.annotation-site.kotlin" |
| 276 |
} |
| 277 |
}, |
| 278 |
"patterns": [ |
| 279 |
{ |
| 280 |
"include": "#unescaped-annotation" |
| 281 |
} |
| 282 |
] |
| 283 |
}, |
| 284 |
"annotation-site": { |
| 285 |
"begin": "(?<!\\w)(@\\w+):\\s*(?!\\[)", |
| 286 |
"end": "$", |
| 287 |
"beginCaptures": { |
| 288 |
"1": { |
| 289 |
"name": "entity.name.type.annotation-site.kotlin" |
| 290 |
} |
| 291 |
}, |
| 292 |
"patterns": [ |
| 293 |
{ |
| 294 |
"include": "#unescaped-annotation" |
| 295 |
} |
| 296 |
] |
| 297 |
}, |
| 298 |
"unescaped-annotation": { |
| 299 |
"match": "\\b[\\w\\.]+\\b", |
| 300 |
"name": "entity.name.type.annotation.kotlin" |
| 301 |
}, |
| 302 |
"class-declaration": { |
| 303 |
"match": "\\b(class|(?:fun\\s+)?interface)\\s+(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?", |
| 304 |
"captures": { |
| 305 |
"1": { |
| 306 |
"name": "storage.type.class.kotlin" |
| 307 |
}, |
| 308 |
"2": { |
| 309 |
"name": "entity.name.type.class.kotlin" |
| 310 |
}, |
| 311 |
"3": { |
| 312 |
"patterns": [ |
| 313 |
{ |
| 314 |
"include": "#type-parameter" |
| 315 |
} |
| 316 |
] |
| 317 |
} |
| 318 |
} |
| 319 |
}, |
| 320 |
"object-declaration": { |
| 321 |
"match": "\\b(object)\\s+(\\b\\w+\\b|`[^`]+`)", |
| 322 |
"captures": { |
| 323 |
"1": { |
| 324 |
"name": "storage.type.object.kotlin" |
| 325 |
}, |
| 326 |
"2": { |
| 327 |
"name": "entity.name.type.object.kotlin" |
| 328 |
} |
| 329 |
} |
| 330 |
}, |
| 331 |
"type-alias": { |
| 332 |
"match": "\\b(typealias)\\s+(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?", |
| 333 |
"captures": { |
| 334 |
"1": { |
| 335 |
"name": "storage.type.alias.kotlin" |
| 336 |
}, |
| 337 |
"2": { |
| 338 |
"name": "entity.name.type.kotlin" |
| 339 |
}, |
| 340 |
"3": { |
| 341 |
"patterns": [ |
| 342 |
{ |
| 343 |
"include": "#type-parameter" |
| 344 |
} |
| 345 |
] |
| 346 |
} |
| 347 |
} |
| 348 |
}, |
| 349 |
"function-declaration": { |
| 350 |
"match": "\\b(fun)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?:(\\w+)\\.)?(\\b\\w+\\b|`[^`]+`)", |
| 351 |
"captures": { |
| 352 |
"1": { |
| 353 |
"name": "storage.type.function.kotlin" |
| 354 |
}, |
| 355 |
"2": { |
| 356 |
"patterns": [ |
| 357 |
{ |
| 358 |
"include": "#type-parameter" |
| 359 |
} |
| 360 |
] |
| 361 |
}, |
| 362 |
"4": { |
| 363 |
"name": "entity.name.type.class.extension.kotlin" |
| 364 |
}, |
| 365 |
"5": { |
| 366 |
"name": "entity.name.function.declaration.kotlin" |
| 367 |
} |
| 368 |
} |
| 369 |
}, |
| 370 |
"variable-declaration": { |
| 371 |
"match": "\\b(val|var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?", |
| 372 |
"captures": { |
| 373 |
"1": { |
| 374 |
"name": "storage.type.variable.kotlin" |
| 375 |
}, |
| 376 |
"2": { |
| 377 |
"patterns": [ |
| 378 |
{ |
| 379 |
"include": "#type-parameter" |
| 380 |
} |
| 381 |
] |
| 382 |
} |
| 383 |
} |
| 384 |
}, |
| 385 |
"type-parameter": { |
| 386 |
"patterns": [ |
| 387 |
{ |
| 388 |
"match": "\\b\\w+\\b", |
| 389 |
"name": "entity.name.type.kotlin" |
| 390 |
}, |
| 391 |
{ |
| 392 |
"match": "\\b(in|out)\\b", |
| 393 |
"name": "storage.modifier.kotlin" |
| 394 |
} |
| 395 |
] |
| 396 |
}, |
| 397 |
"type-annotation": { |
| 398 |
"match": "(?<![:?]):\\s*(\\w|\\?|\\s|->|(?<GROUP>[<(]([^<>()\"']|\\g<GROUP>)+[)>]))+", |
| 399 |
"captures": { |
| 400 |
"0": { |
| 401 |
"patterns": [ |
| 402 |
{ |
| 403 |
"include": "#type-parameter" |
| 404 |
} |
| 405 |
] |
| 406 |
} |
| 407 |
} |
| 408 |
}, |
| 409 |
"function-call": { |
| 410 |
"match": "\\??\\.?(\\b\\w+\\b|`[^`]+`)\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?\\s*(?=[({])", |
| 411 |
"captures": { |
| 412 |
"1": { |
| 413 |
"name": "entity.name.function.call.kotlin" |
| 414 |
}, |
| 415 |
"2": { |
| 416 |
"patterns": [ |
| 417 |
{ |
| 418 |
"include": "#type-parameter" |
| 419 |
} |
| 420 |
] |
| 421 |
} |
| 422 |
} |
| 423 |
}, |
| 424 |
"method-reference": { |
| 425 |
"match": "\\??::(\\b\\w+\\b|`[^`]+`)", |
| 426 |
"captures": { |
| 427 |
"1": { |
| 428 |
"name": "entity.name.function.reference.kotlin" |
| 429 |
} |
| 430 |
} |
| 431 |
}, |
| 432 |
"key": { |
| 433 |
"match": "\\b(\\w=)\\s*(=)", |
| 434 |
"captures": { |
| 435 |
"1": { |
| 436 |
"name": "variable.parameter.kotlin" |
| 437 |
}, |
| 438 |
"2": { |
| 439 |
"name": "keyword.operator.assignment.kotlin" |
| 440 |
} |
| 441 |
} |
| 442 |
}, |
| 443 |
"string-empty": { |
| 444 |
"match": "(?<!\")\"\"(?!\")", |
| 445 |
"name": "string.quoted.double.kotlin" |
| 446 |
}, |
| 447 |
"string": { |
| 448 |
"begin": "(?<!\")\"(?!\")", |
| 449 |
"end": "\"", |
| 450 |
"name": "string.quoted.double.kotlin", |
| 451 |
"patterns": [ |
| 452 |
{ |
| 453 |
"match": "\\\\.", |
| 454 |
"name": "constant.character.escape.kotlin" |
| 455 |
}, |
| 456 |
{ |
| 457 |
"include": "#string-escape-simple" |
| 458 |
}, |
| 459 |
{ |
| 460 |
"include": "#string-escape-bracketed" |
| 461 |
} |
| 462 |
] |
| 463 |
}, |
| 464 |
"string-multiline": { |
| 465 |
"begin": "\"\"\"", |
| 466 |
"end": "\"\"\"", |
| 467 |
"name": "string.quoted.double.kotlin", |
| 468 |
"patterns": [ |
| 469 |
{ |
| 470 |
"match": "\\\\.", |
| 471 |
"name": "constant.character.escape.kotlin" |
| 472 |
}, |
| 473 |
{ |
| 474 |
"include": "#string-escape-simple" |
| 475 |
}, |
| 476 |
{ |
| 477 |
"include": "#string-escape-bracketed" |
| 478 |
} |
| 479 |
] |
| 480 |
}, |
| 481 |
"string-escape-simple": { |
| 482 |
"match": "(?<!\\\\)\\$\\w+\\b", |
| 483 |
"name": "variable.string-escape.kotlin" |
| 484 |
}, |
| 485 |
"string-escape-bracketed": { |
| 486 |
"begin": "(?<!\\\\)(\\$\\{)", |
| 487 |
"end": "(\\})", |
| 488 |
"name": "meta.template.expression.kotlin", |
| 489 |
"beginCaptures": { |
| 490 |
"1": { |
| 491 |
"name": "punctuation.definition.template-expression.begin" |
| 492 |
} |
| 493 |
}, |
| 494 |
"endCaptures": { |
| 495 |
"1": { |
| 496 |
"name": "punctuation.definition.template-expression.end" |
| 497 |
} |
| 498 |
}, |
| 499 |
"patterns": [ |
| 500 |
{ |
| 501 |
"include": "#code" |
| 502 |
} |
| 503 |
] |
| 504 |
}, |
| 505 |
"character": { |
| 506 |
"begin": "'", |
| 507 |
"end": "'", |
| 508 |
"name": "string.quoted.single.kotlin", |
| 509 |
"patterns": [ |
| 510 |
{ |
| 511 |
"match": "\\\\.", |
| 512 |
"name": "constant.character.escape.kotlin" |
| 513 |
} |
| 514 |
] |
| 515 |
}, |
| 516 |
"decimal-literal": { |
| 517 |
"match": "\\b\\d[\\d_]*(\\.[\\d_]+)?((e|E)\\d+)?(u|U)?(L|F|f)?\\b", |
| 518 |
"name": "constant.numeric.decimal.kotlin" |
| 519 |
}, |
| 520 |
"hex-literal": { |
| 521 |
"match": "0(x|X)[A-Fa-f0-9][A-Fa-f0-9_]*(u|U)?", |
| 522 |
"name": "constant.numeric.hex.kotlin" |
| 523 |
}, |
| 524 |
"binary-literal": { |
| 525 |
"match": "0(b|B)[01][01_]*", |
| 526 |
"name": "constant.numeric.binary.kotlin" |
| 527 |
}, |
| 528 |
"boolean-literal": { |
| 529 |
"match": "\\b(true|false)\\b", |
| 530 |
"name": "constant.language.boolean.kotlin" |
| 531 |
}, |
| 532 |
"null-literal": { |
| 533 |
"match": "\\bnull\\b", |
| 534 |
"name": "constant.language.null.kotlin" |
| 535 |
}, |
| 536 |
"lambda-arrow": { |
| 537 |
"match": "->", |
| 538 |
"name": "storage.type.function.arrow.kotlin" |
| 539 |
}, |
| 540 |
"operators": { |
| 541 |
"patterns": [ |
| 542 |
{ |
| 543 |
"match": "(===?|\\!==?|<=|>=|<|>)", |
| 544 |
"name": "keyword.operator.comparison.kotlin" |
| 545 |
}, |
| 546 |
{ |
| 547 |
"match": "([+*/%-]=)", |
| 548 |
"name": "keyword.operator.assignment.arithmetic.kotlin" |
| 549 |
}, |
| 550 |
{ |
| 551 |
"match": "(=)", |
| 552 |
"name": "keyword.operator.assignment.kotlin" |
| 553 |
}, |
| 554 |
{ |
| 555 |
"match": "([+*/%-])", |
| 556 |
"name": "keyword.operator.arithmetic.kotlin" |
| 557 |
}, |
| 558 |
{ |
| 559 |
"match": "(!|&&|\\|\\|)", |
| 560 |
"name": "keyword.operator.logical.kotlin" |
| 561 |
}, |
| 562 |
{ |
| 563 |
"match": "(--|\\+\\+)", |
| 564 |
"name": "keyword.operator.increment-decrement.kotlin" |
| 565 |
}, |
| 566 |
{ |
| 567 |
"match": "(\\.\\.)", |
| 568 |
"name": "keyword.operator.range.kotlin" |
| 569 |
} |
| 570 |
] |
| 571 |
}, |
| 572 |
"self-reference": { |
| 573 |
"match": "\\b(this|super)(@\\w+)?\\b", |
| 574 |
"name": "variable.language.this.kotlin" |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
|