[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | module.exports = kotlin
|
---|
| 4 | kotlin.displayName = 'kotlin'
|
---|
| 5 | kotlin.aliases = ['kt', 'kts']
|
---|
| 6 | function kotlin(Prism) {
|
---|
| 7 | ;(function (Prism) {
|
---|
| 8 | Prism.languages.kotlin = Prism.languages.extend('clike', {
|
---|
| 9 | keyword: {
|
---|
| 10 | // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
|
---|
| 11 | pattern:
|
---|
| 12 | /(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,
|
---|
| 13 | lookbehind: true
|
---|
| 14 | },
|
---|
| 15 | function: [
|
---|
| 16 | {
|
---|
| 17 | pattern: /(?:`[^\r\n`]+`|\b\w+)(?=\s*\()/,
|
---|
| 18 | greedy: true
|
---|
| 19 | },
|
---|
| 20 | {
|
---|
| 21 | pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,
|
---|
| 22 | lookbehind: true,
|
---|
| 23 | greedy: true
|
---|
| 24 | }
|
---|
| 25 | ],
|
---|
| 26 | number:
|
---|
| 27 | /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
|
---|
| 28 | operator:
|
---|
| 29 | /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
|
---|
| 30 | })
|
---|
| 31 | delete Prism.languages.kotlin['class-name']
|
---|
| 32 | var interpolationInside = {
|
---|
| 33 | 'interpolation-punctuation': {
|
---|
| 34 | pattern: /^\$\{?|\}$/,
|
---|
| 35 | alias: 'punctuation'
|
---|
| 36 | },
|
---|
| 37 | expression: {
|
---|
| 38 | pattern: /[\s\S]+/,
|
---|
| 39 | inside: Prism.languages.kotlin
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | Prism.languages.insertBefore('kotlin', 'string', {
|
---|
| 43 | // https://kotlinlang.org/spec/expressions.html#string-interpolation-expressions
|
---|
| 44 | 'string-literal': [
|
---|
| 45 | {
|
---|
| 46 | pattern: /"""(?:[^$]|\$(?:(?!\{)|\{[^{}]*\}))*?"""/,
|
---|
| 47 | alias: 'multiline',
|
---|
| 48 | inside: {
|
---|
| 49 | interpolation: {
|
---|
| 50 | pattern: /\$(?:[a-z_]\w*|\{[^{}]*\})/i,
|
---|
| 51 | inside: interpolationInside
|
---|
| 52 | },
|
---|
| 53 | string: /[\s\S]+/
|
---|
| 54 | }
|
---|
| 55 | },
|
---|
| 56 | {
|
---|
| 57 | pattern: /"(?:[^"\\\r\n$]|\\.|\$(?:(?!\{)|\{[^{}]*\}))*"/,
|
---|
| 58 | alias: 'singleline',
|
---|
| 59 | inside: {
|
---|
| 60 | interpolation: {
|
---|
| 61 | pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:[a-z_]\w*|\{[^{}]*\})/i,
|
---|
| 62 | lookbehind: true,
|
---|
| 63 | inside: interpolationInside
|
---|
| 64 | },
|
---|
| 65 | string: /[\s\S]+/
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | ],
|
---|
| 69 | char: {
|
---|
| 70 | // https://kotlinlang.org/spec/expressions.html#character-literals
|
---|
| 71 | pattern: /'(?:[^'\\\r\n]|\\(?:.|u[a-fA-F0-9]{0,4}))'/,
|
---|
| 72 | greedy: true
|
---|
| 73 | }
|
---|
| 74 | })
|
---|
| 75 | delete Prism.languages.kotlin['string']
|
---|
| 76 | Prism.languages.insertBefore('kotlin', 'keyword', {
|
---|
| 77 | annotation: {
|
---|
| 78 | pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
|
---|
| 79 | alias: 'builtin'
|
---|
| 80 | }
|
---|
| 81 | })
|
---|
| 82 | Prism.languages.insertBefore('kotlin', 'function', {
|
---|
| 83 | label: {
|
---|
| 84 | pattern: /\b\w+@|@\w+\b/,
|
---|
| 85 | alias: 'symbol'
|
---|
| 86 | }
|
---|
| 87 | })
|
---|
| 88 | Prism.languages.kt = Prism.languages.kotlin
|
---|
| 89 | Prism.languages.kts = Prism.languages.kotlin
|
---|
| 90 | })(Prism)
|
---|
| 91 | }
|
---|