dkearns | e30d8e4 | 2023-09-18 02:51:22 +1000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Kotlin |
| 3 | " Maintainer: Alexander Udalov |
| 4 | " URL: https://github.com/udalov/kotlin-vim |
| 5 | " Last Change: 30 December 2022 |
| 6 | |
| 7 | if exists('b:current_syntax') |
| 8 | finish |
| 9 | endif |
| 10 | |
| 11 | syn keyword ktStatement break continue return |
| 12 | syn keyword ktConditional if else when |
| 13 | syn keyword ktRepeat do for while |
| 14 | syn keyword ktOperator in is by |
| 15 | syn keyword ktKeyword get set out super this where |
| 16 | syn keyword ktException try catch finally throw |
| 17 | |
| 18 | syn keyword ktInclude import package |
| 19 | |
| 20 | " Generated stdlib class names {{{ |
| 21 | " The following is generated by https://github.com/udalov/kotlin-vim/blob/master/extra/generate-stdlib-class-names.main.kts |
| 22 | syn keyword ktType AbstractCollection AbstractCoroutineContextElement AbstractCoroutineContextKey AbstractDoubleTimeSource AbstractIterator AbstractList AbstractLongTimeSource |
| 23 | syn keyword ktType AbstractMap AbstractMutableCollection AbstractMutableList AbstractMutableMap AbstractMutableSet AbstractSet AccessDeniedException Accessor Annotation |
| 24 | syn keyword ktType AnnotationRetention AnnotationTarget Any Appendable ArithmeticException Array ArrayDeque ArrayList AssertionError Boolean BooleanArray BooleanIterator |
| 25 | syn keyword ktType BuilderInference Byte ByteArray ByteIterator CName CallsInPlace CancellationException Char CharArray CharCategory CharDirectionality CharIterator CharProgression |
| 26 | syn keyword ktType CharRange CharSequence CharacterCodingException Charsets ClassCastException Cloneable ClosedFloatingPointRange ClosedRange Collection Comparable |
| 27 | syn keyword ktType ComparableTimeMark Comparator ConcurrentModificationException ConditionalEffect ContextFunctionTypeParams Continuation ContinuationInterceptor ContractBuilder |
| 28 | syn keyword ktType CopyActionContext CopyActionResult CoroutineContext DeepRecursiveFunction DeepRecursiveScope Delegates Deprecated DeprecatedSinceKotlin DeprecationLevel |
| 29 | syn keyword ktType Destructured Double DoubleArray DoubleIterator DslMarker Duration DurationUnit Effect Element EmptyCoroutineContext Entry Enum EnumEntries Error Exception |
| 30 | syn keyword ktType ExperimentalContracts ExperimentalJsExport ExperimentalMultiplatform ExperimentalObjCName ExperimentalObjCRefinement ExperimentalPathApi ExperimentalStdlibApi |
| 31 | syn keyword ktType ExperimentalSubclassOptIn ExperimentalTime ExperimentalTypeInference ExperimentalUnsignedTypes ExtensionFunctionType FileAlreadyExistsException |
| 32 | syn keyword ktType FileSystemException FileTreeWalk FileVisitorBuilder FileWalkDirection Float FloatArray FloatIterator FreezingIsDeprecated Function Function0 Function1 Function10 |
| 33 | syn keyword ktType Function11 Function12 Function13 Function14 Function15 Function16 Function17 Function18 Function19 Function2 Function20 Function21 Function22 Function3 Function4 |
| 34 | syn keyword ktType Function5 Function6 Function7 Function8 Function9 FunctionN Getter Grouping HashMap HashSet HiddenFromObjC HidesFromObjC Ignore IllegalArgumentException |
| 35 | syn keyword ktType IllegalStateException IndexOutOfBoundsException IndexedValue Int IntArray IntIterator IntProgression IntRange InvocationKind Iterable Iterator JsExport JsName |
| 36 | syn keyword ktType JvmDefault JvmDefaultWithCompatibility JvmDefaultWithoutCompatibility JvmField JvmInline JvmMultifileClass JvmName JvmOverloads JvmRecord JvmSerializableLambda |
| 37 | syn keyword ktType JvmStatic JvmSuppressWildcards JvmSynthetic JvmWildcard KAnnotatedElement KCallable KClass KClassifier KDeclarationContainer KFunction KMutableProperty |
| 38 | syn keyword ktType KMutableProperty0 KMutableProperty1 KMutableProperty2 KParameter KProperty KProperty0 KProperty1 KProperty2 KType KTypeParameter KTypeProjection KVariance |
| 39 | syn keyword ktType KVisibility Key Kind KotlinNullPointerException KotlinReflectionNotSupportedError KotlinVersion Lazy LazyThreadSafetyMode Level LinkedHashMap LinkedHashSet List |
| 40 | syn keyword ktType ListIterator Long LongArray LongIterator LongProgression LongRange Map MatchGroup MatchGroupCollection MatchNamedGroupCollection MatchResult Metadata Monotonic |
| 41 | syn keyword ktType MustBeDocumented MutableCollection MutableEntry MutableIterable MutableIterator MutableList MutableListIterator MutableMap MutableSet NoSuchElementException |
| 42 | syn keyword ktType NoSuchFileException NoWhenBranchMatchedException NotImplementedError Nothing NullPointerException Number NumberFormatException ObjCName ObservableProperty |
| 43 | syn keyword ktType OnErrorAction OnErrorResult OpenEndRange OptIn OptionalExpectation OverloadResolutionByLambdaReturnType Pair ParameterName PathWalkOption |
| 44 | syn keyword ktType PropertyDelegateProvider PublishedApi PurelyImplements Random RandomAccess ReadOnlyProperty ReadWriteProperty RefinesInSwift Regex RegexOption Repeatable |
| 45 | syn keyword ktType ReplaceWith RequiresOptIn RestrictsSuspension Result Retention Returns ReturnsNotNull RuntimeException Sequence SequenceScope Set Setter SharedImmutable Short |
| 46 | syn keyword ktType ShortArray ShortIterator ShouldRefineInSwift SimpleEffect SinceKotlin Strictfp String StringBuilder SubclassOptInRequired Suppress Synchronized Target |
| 47 | syn keyword ktType TestTimeSource ThreadLocal Throwable Throws TimeMark TimeSource TimedValue Transient Triple TypeCastException Typography UByte UByteArray UInt UIntArray |
| 48 | syn keyword ktType UIntProgression UIntRange ULong ULongArray ULongProgression ULongRange UShort UShortArray UninitializedPropertyAccessException Unit UnsafeVariance |
| 49 | syn keyword ktType UnsupportedOperationException ValueTimeMark Volatile WithComparableMarks |
| 50 | " }}} |
| 51 | |
| 52 | syn keyword ktModifier annotation companion enum inner abstract final open override sealed vararg dynamic expect actual suspend |
| 53 | syn keyword ktStructure class object interface typealias fun val var constructor init |
| 54 | |
| 55 | syn keyword ktReservedKeyword typeof |
| 56 | |
| 57 | syn keyword ktBoolean true false |
| 58 | syn keyword ktConstant null |
| 59 | |
| 60 | syn keyword ktModifier reified external inline noinline crossinline |
| 61 | |
| 62 | syn match ktModifier "\v<data>\ze\@=.*<(class|object)>" |
| 63 | syn match ktModifier "\v<value>\ze\@=.*<class>" |
| 64 | syn match ktModifier "\v<(tailrec|operator|infix)>\ze\@=.*<fun>" |
| 65 | syn match ktModifier "\v<const>\ze\@=.*<val>" |
| 66 | syn match ktModifier "\v<lateinit>\ze\@=.*<var>" |
| 67 | syn match ktModifier "\v<(internal|private|protected|public)>\ze\@=.*<(class|object|interface|typealias|fun|val|var|constructor|get|set)>" |
| 68 | |
| 69 | syn match ktOperator "\v\?:|::|\<\=? | \>\=?|[!=]\=\=?|<as>\??|[-*+/%]\=?|[!&|]" |
| 70 | |
| 71 | syn keyword ktTodo TODO FIXME XXX contained |
| 72 | syn match ktShebang "\v^#!.*$" |
| 73 | syn match ktLineComment "\v//.*$" contains=ktTodo,@Spell |
| 74 | syn region ktComment matchgroup=ktCommentMatchGroup start="/\*" end="\*/" contains=ktComment,ktTodo,@Spell |
| 75 | |
| 76 | syn region ktDocComment start="/\*\*" end="\*/" contains=ktDocTag,ktTodo,@Spell |
| 77 | syn match ktDocTag "\v\@(author|constructor|receiver|return|since|suppress)>" contained |
| 78 | syn match ktDocTag "\v\@(exception|param|property|throws|see|sample)>\s*\S+" contains=ktDocTagParam contained |
| 79 | syn match ktDocTagParam "\v(\s|\[)\S+" contained |
| 80 | syn match ktComment "/\*\*/" |
| 81 | |
| 82 | syn match ktSpecialCharError "\v\\." contained |
| 83 | syn match ktSpecialChar "\v\\([tbnr'"$\\]|u\x{4})" contained |
| 84 | syn region ktString start='"' skip='\\"' end='"' contains=ktSimpleInterpolation,ktComplexInterpolation,ktSpecialChar,ktSpecialCharError,@Spell |
| 85 | syn region ktString start='"""' end='""""*' contains=ktSimpleInterpolation,ktComplexInterpolation,@Spell |
| 86 | syn match ktCharacter "\v'[^']*'" contains=ktSpecialChar,ktSpecialCharError |
| 87 | syn match ktCharacter "\v'\\''" contains=ktSpecialChar |
| 88 | syn match ktCharacter "\v'[^\\]'" |
| 89 | |
| 90 | syn match ktAnnotation "\v(\w)@<!\@[[:alnum:]_.]*(:[[:alnum:]_.]*)?" |
| 91 | syn match ktLabel "\v\w+\@" |
| 92 | syn match ktLabel "\v(\w)@<=\@\w+" |
| 93 | |
| 94 | syn match ktSimpleInterpolation "\v\$\h\w*" contained |
| 95 | syn region ktComplexInterpolation matchgroup=ktComplexInterpolationBrace start="\v\$\{" end="\v\}" contains=ALLBUT,ktSimpleInterpolation,ktTodo,ktSpecialCharError,ktSpecialChar,ktDocTag,ktDocTagParam |
| 96 | |
| 97 | syn match ktNumber "\v<\d+[_[:digit:]]*(uL?|UL?|[LFf])?" |
| 98 | syn match ktNumber "\v<0[Xx]\x+[_[:xdigit:]]*(uL?|UL?|L)?" |
| 99 | syn match ktNumber "\v<0[Bb][01]+[_01]*(uL?|UL?|L)?" |
| 100 | syn match ktFloat "\v<\d*(\d[eE][-+]?\d+|\.\d+([eE][-+]?\d+)?)[Ff]?" |
| 101 | |
| 102 | syn match ktEscapedName "\v`.*`" |
| 103 | |
| 104 | syn match ktExclExcl "!!" |
| 105 | syn match ktArrow "->" |
| 106 | |
| 107 | syn region ktFold start="{" end="}" transparent fold |
| 108 | |
| 109 | exec "syntax sync ccomment ktComment minlines=10" |
| 110 | |
| 111 | hi def link ktStatement Statement |
| 112 | hi def link ktConditional Conditional |
| 113 | hi def link ktRepeat Repeat |
| 114 | hi def link ktOperator Operator |
| 115 | hi def link ktKeyword Keyword |
| 116 | hi def link ktException Exception |
| 117 | hi def link ktReservedKeyword Error |
| 118 | |
| 119 | hi def link ktInclude Include |
| 120 | |
| 121 | hi def link ktType Type |
| 122 | hi def link ktModifier StorageClass |
| 123 | hi def link ktStructure Structure |
| 124 | hi def link ktTypedef Typedef |
| 125 | |
| 126 | hi def link ktBoolean Boolean |
| 127 | hi def link ktConstant Constant |
| 128 | |
| 129 | hi def link ktTodo Todo |
| 130 | hi def link ktShebang Comment |
| 131 | hi def link ktLineComment Comment |
| 132 | hi def link ktComment Comment |
| 133 | hi def link ktCommentMatchGroup Comment |
| 134 | hi def link ktDocComment Comment |
| 135 | hi def link ktDocTag Special |
| 136 | hi def link ktDocTagParam Identifier |
| 137 | |
| 138 | hi def link ktSpecialChar SpecialChar |
| 139 | hi def link ktSpecialCharError Error |
| 140 | hi def link ktString String |
| 141 | hi def link ktCharacter Character |
| 142 | |
| 143 | hi def link ktAnnotation Identifier |
| 144 | hi def link ktLabel Identifier |
| 145 | |
| 146 | hi def link ktSimpleInterpolation Identifier |
| 147 | hi def link ktComplexInterpolationBrace Identifier |
| 148 | |
| 149 | hi def link ktNumber Number |
| 150 | hi def link ktFloat Float |
| 151 | |
| 152 | hi def link ktExclExcl Special |
| 153 | hi def link ktArrow Structure |
| 154 | |
| 155 | let b:current_syntax = 'kotlin' |
| 156 | |
| 157 | " vim:foldmethod=marker |