View raw

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