|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- %YAML 1.2
- ---
- # http://www.sublimetext.com/docs/3/syntax.html
- name: Kotlin
- file_extensions:
- - kt
- - kts
- scope: source.Kotlin
- contexts:
- main:
- - include: comments
- - match: '^\s*(package)\b(?:\s*([^ ;$]+)\s*)?'
- captures:
- 1: keyword.other.kotlin
- 2: entity.name.package.kotlin
- - include: imports
- - include: statements
- classes:
- - match: (?=\s*(?:companion|class|object|interface))
- push:
- - match: "}|(?=$)"
- pop: true
- - match: \b(companion\s*)?(class|object|interface)\b
- captures:
- 1: keyword.other.kotlin
- push:
- - match: '(?=<|{|\(|:)'
- pop: true
- - match: \b(object)\b
- scope: keyword.other.kotlin
- - match: \w+
- scope: entity.name.type.class.kotlin
- - match: <
- push:
- - match: ">"
- pop: true
- - include: generics
- - match: \(
- push:
- - match: \)
- pop: true
- - include: parameters
- - match: (:)
- captures:
- 1: keyword.operator.declaration.kotlin
- push:
- - match: "(?={|$)"
- pop: true
- - match: \w+
- scope: entity.other.inherited-class.kotlin
- - match: \(
- push:
- - match: \)
- pop: true
- - include: expressions
- - match: '\{'
- push:
- - match: '\}'
- pop: true
- - include: statements
- comments:
- - match: /\*
- captures:
- 0: punctuation.definition.comment.kotlin
- push:
- - meta_scope: comment.block.kotlin
- - match: \*/
- captures:
- 0: punctuation.definition.comment.kotlin
- pop: true
- - match: \s*((//).*$\n?)
- captures:
- 1: comment.line.double-slash.kotlin
- 2: punctuation.definition.comment.kotlin
- constants:
- - match: \b(true|false|null|this|super)\b
- scope: constant.language.kotlin
- - match: '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)([LlFfUuDd]|UL|ul)?\b'
- scope: constant.numeric.kotlin
- - match: '\b([A-Z][A-Z0-9_]+)\b'
- scope: constant.other.kotlin
- expressions:
- - match: \(
- push:
- - match: \)
- pop: true
- - include: expressions
- - include: types
- - include: strings
- - include: constants
- - include: comments
- - include: keywords
- functions:
- - match: (?=\s*(?:fun))
- push:
- - match: "}|(?=$)"
- pop: true
- - match: \b(fun)\b
- captures:
- 1: keyword.other.kotlin
- push:
- - match: (?=\()
- pop: true
- - match: <
- push:
- - match: ">"
- pop: true
- - include: generics
- - match: '([\.<\?>\w]+\.)?(\w+)'
- captures:
- 2: entity.name.function.kotlin
- - match: \(
- push:
- - match: \)
- pop: true
- - include: parameters
- - match: (:)
- captures:
- 1: keyword.operator.declaration.kotlin
- push:
- - match: "(?={|=|$)"
- pop: true
- - include: types
- - match: '\{'
- push:
- - match: '(?=\})'
- pop: true
- - include: statements
- - match: (=)
- captures:
- 1: keyword.operator.assignment.kotlin
- push:
- - match: (?=$)
- pop: true
- - include: expressions
- generics:
- - match: (:)
- captures:
- 1: keyword.operator.declaration.kotlin
- push:
- - match: (?=,|>)
- pop: true
- - include: types
- - include: keywords
- - match: \w+
- scope: storage.type.generic.kotlin
- getters-and-setters:
- - match: \b(get)\b\s*\(\s*\)
- captures:
- 1: entity.name.function.kotlin
- push:
- - match: '\}|(?=\bset\b)|$'
- pop: true
- - match: (=)
- captures:
- 1: keyword.operator.assignment.kotlin
- push:
- - match: (?=$|\bset\b)
- pop: true
- - include: expressions
- - match: '\{'
- push:
- - match: '\}'
- pop: true
- - include: expressions
- - match: \b(set)\b\s*(?=\()
- captures:
- 1: entity.name.function.kotlin
- push:
- - match: '\}|(?=\bget\b)|$'
- pop: true
- - match: \(
- push:
- - match: \)
- pop: true
- - include: parameters
- - match: (=)
- captures:
- 1: keyword.operator.assignment.kotlin
- push:
- - match: (?=$|\bset\b)
- pop: true
- - include: expressions
- - match: '\{'
- push:
- - match: '\}'
- pop: true
- - include: expressions
- imports:
- - match: '^\s*(import)\s+[^ $]+\s+(as)?'
- captures:
- 1: keyword.other.kotlin
- 2: keyword.other.kotlin
- keywords:
- - 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
- scope: storage.modifier.kotlin
- - match: \b(try|catch|finally|throw)\b
- scope: keyword.control.catch-exception.kotlin
- - match: \b(if|else|while|for|do|return|when|where|break|continue)\b
- scope: keyword.control.kotlin
- - match: \b(in|is|as|assert)\b
- scope: keyword.operator.kotlin
- - match: (==|!=|===|!==|<=|>=|<|>)
- scope: keyword.operator.comparison.kotlin
- - match: (=)
- scope: keyword.operator.assignment.kotlin
- - match: (:)
- scope: keyword.operator.declaration.kotlin
- - match: (\.)
- scope: keyword.operator.dot.kotlin
- - match: (\-\-|\+\+)
- scope: keyword.operator.increment-decrement.kotlin
- - match: (\-|\+|\*|\/|%)
- scope: keyword.operator.arithmetic.kotlin
- - match: (\+=|\-=|\*=|\/=)
- scope: keyword.operator.arithmetic.assign.kotlin
- - match: (!|&&|\|\|)
- scope: keyword.operator.logical.kotlin
- - match: (\.\.)
- scope: keyword.operator.range.kotlin
- - match: (;)
- scope: punctuation.terminator.kotlin
- namespaces:
- - match: \b(namespace)\b
- scope: keyword.other.kotlin
- - match: '\{'
- push:
- - match: '\}'
- pop: true
- - include: statements
- parameters:
- - match: (:)
- captures:
- 1: keyword.operator.declaration.kotlin
- push:
- - match: (?=,|\)|=)
- pop: true
- - include: types
- - match: (=)
- captures:
- 1: keyword.operator.declaration.kotlin
- push:
- - match: (?=,|\))
- pop: true
- - include: expressions
- - include: keywords
- - match: \w+
- scope: variable.parameter.function.kotlin
- statements:
- - include: namespaces
- - include: typedefs
- - include: classes
- - include: functions
- - include: variables
- - include: getters-and-setters
- - include: expressions
- strings:
- - match: '"""'
- captures:
- 0: punctuation.definition.string.begin.kotlin
- push:
- - meta_scope: string.quoted.third.kotlin
- - match: '"""'
- captures:
- 0: punctuation.definition.string.end.kotlin
- pop: true
- - match: '(\$\w+|\$\{[^\}]+\})'
- scope: variable.parameter.template.kotlin
- - match: \\.
- scope: constant.character.escape.kotlin
- - match: '"'
- captures:
- 0: punctuation.definition.string.begin.kotlin
- push:
- - meta_scope: string.quoted.double.kotlin
- - match: '"'
- captures:
- 0: punctuation.definition.string.end.kotlin
- pop: true
- - match: '(\$\w+|\$\{[^\}]+\})'
- scope: variable.parameter.template.kotlin
- - match: \\.
- scope: constant.character.escape.kotlin
- - match: "'"
- captures:
- 0: punctuation.definition.string.begin.kotlin
- push:
- - meta_scope: string.quoted.single.kotlin
- - match: "'"
- captures:
- 0: punctuation.definition.string.end.kotlin
- pop: true
- - match: \\.
- scope: constant.character.escape.kotlin
- - match: "`"
- captures:
- 0: punctuation.definition.string.begin.kotlin
- push:
- - meta_scope: string.quoted.single.kotlin
- - match: "`"
- captures:
- 0: punctuation.definition.string.end.kotlin
- pop: true
- typedefs:
- - match: (?=\s*(?:type))
- push:
- - match: (?=$)
- pop: true
- - match: \b(type)\b
- scope: keyword.other.kotlin
- - match: <
- push:
- - match: ">"
- pop: true
- - include: generics
- - include: expressions
- types:
- - match: \b(Any|Unit|String|Int|Boolean|Char|Long|Double|Float|Short|Byte|dynamic)\b
- scope: storage.type.buildin.kotlin
- - match: \b(IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray)\b
- scope: storage.type.buildin.array.kotlin
- - match: \b(Array|List|Map)<\b
- captures:
- 1: storage.type.buildin.collection.kotlin
- push:
- - match: ">"
- pop: true
- - include: types
- - include: keywords
- - match: \w+<
- push:
- - match: ">"
- pop: true
- - include: types
- - include: keywords
- - match: (#)\(
- captures:
- 1: keyword.operator.tuple.kotlin
- push:
- - match: \)
- pop: true
- - include: expressions
- - match: '\{'
- push:
- - match: '\}'
- pop: true
- - include: statements
- - match: \(
- push:
- - match: \)
- pop: true
- - include: types
- - match: (->)
- scope: keyword.operator.declaration.kotlin
- variables:
- - match: (?=\s*(?:var|val))
- push:
- - match: (?=:|=|$)
- pop: true
- - match: \b(var|val)\b
- captures:
- 1: keyword.other.kotlin
- push:
- - match: (?=:|=|$)
- pop: true
- - match: <
- push:
- - match: ">"
- pop: true
- - include: generics
- - match: '([\.<\?>\w]+\.)?(\w+)'
- captures:
- 2: entity.name.variable.kotlin
- - match: (:)
- captures:
- 1: keyword.operator.declaration.kotlin
- push:
- - match: (?==|$)
- pop: true
- - include: types
- - include: getters-and-setters
- - match: (=)
- captures:
- 1: keyword.operator.assignment.kotlin
- push:
- - match: (?=$)
- pop: true
- - include: expressions
- - include: getters-and-setters
|