1" This source file is part of the Swift.org open source project 2" 3" Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors 4" Licensed under Apache License v2.0 with Runtime Library Exception 5" 6" See https://swift.org/LICENSE.txt for license information 7" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 8" 9" Vim syntax file 10" Language: swift 11" Maintainer: Joe Groff <[email protected]> 12" Last Change: 2018 Jan 21 13" 14" Vim maintainer: Emir SARI <[email protected]> 15 16if exists("b:current_syntax") 17 finish 18endif 19 20let s:keepcpo = &cpo 21set cpo&vim 22 23syn keyword swiftKeyword 24 \ break 25 \ case 26 \ catch 27 \ continue 28 \ default 29 \ defer 30 \ do 31 \ else 32 \ fallthrough 33 \ for 34 \ guard 35 \ if 36 \ in 37 \ repeat 38 \ return 39 \ switch 40 \ throw 41 \ try 42 \ where 43 \ while 44syn match swiftMultiwordKeyword 45 \ "indirect case" 46 47syn keyword swiftCoreTypes 48 \ Any 49 \ AnyObject 50 51syn keyword swiftImport skipwhite skipempty nextgroup=swiftImportModule 52 \ import 53 54syn keyword swiftDefinitionModifier 55 \ convenience 56 \ dynamic 57 \ fileprivate 58 \ final 59 \ internal 60 \ lazy 61 \ nonmutating 62 \ open 63 \ override 64 \ prefix 65 \ private 66 \ public 67 \ required 68 \ rethrows 69 \ static 70 \ throws 71 \ weak 72 73syn keyword swiftInOutKeyword skipwhite skipempty nextgroup=swiftTypeName 74 \ inout 75 76syn keyword swiftIdentifierKeyword 77 \ Self 78 \ metatype 79 \ self 80 \ super 81 82syn keyword swiftFuncKeywordGeneral skipwhite skipempty nextgroup=swiftTypeParameters 83 \ init 84 85syn keyword swiftFuncKeyword 86 \ deinit 87 \ subscript 88 89syn keyword swiftScope 90 \ autoreleasepool 91 92syn keyword swiftMutating skipwhite skipempty nextgroup=swiftFuncDefinition 93 \ mutating 94syn keyword swiftFuncDefinition skipwhite skipempty nextgroup=swiftTypeName,swiftOperator 95 \ func 96 97syn keyword swiftTypeDefinition skipwhite skipempty nextgroup=swiftTypeName 98 \ class 99 \ enum 100 \ extension 101 \ operator 102 \ precedencegroup 103 \ protocol 104 \ struct 105 106syn keyword swiftTypeAliasDefinition skipwhite skipempty nextgroup=swiftTypeAliasName 107 \ associatedtype 108 \ typealias 109 110syn match swiftMultiwordTypeDefinition skipwhite skipempty nextgroup=swiftTypeName 111 \ "indirect enum" 112 113syn keyword swiftVarDefinition skipwhite skipempty nextgroup=swiftVarName 114 \ let 115 \ var 116 117syn keyword swiftLabel 118 \ get 119 \ set 120 \ didSet 121 \ willSet 122 123syn keyword swiftBoolean 124 \ false 125 \ true 126 127syn keyword swiftNil 128 \ nil 129 130syn match swiftImportModule contained nextgroup=swiftImportComponent 131 \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ 132syn match swiftImportComponent contained nextgroup=swiftImportComponent 133 \ /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ 134 135syn match swiftTypeAliasName contained skipwhite skipempty nextgroup=swiftTypeAliasValue 136 \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ 137syn match swiftTypeName contained skipwhite skipempty nextgroup=swiftTypeParameters 138 \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>/ 139syn match swiftVarName contained skipwhite skipempty nextgroup=swiftTypeDeclaration 140 \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ 141syn match swiftImplicitVarName 142 \ /\$\<[A-Za-z_0-9]\+\>/ 143 144" TypeName[Optionality]? 145syn match swiftType contained skipwhite skipempty nextgroup=swiftTypeParameters 146 \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/ 147" [Type:Type] (dictionary) or [Type] (array) 148syn region swiftType contained contains=swiftTypePair,swiftType 149 \ matchgroup=Delimiter start=/\[/ end=/\]/ 150syn match swiftTypePair contained skipwhite skipempty nextgroup=swiftTypeParameters,swiftTypeDeclaration 151 \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/ 152" (Type[, Type]) (tuple) 153" FIXME: we should be able to use skip="," and drop swiftParamDelim 154syn region swiftType contained contains=swiftType,swiftParamDelim 155 \ matchgroup=Delimiter start="[^@]\?(" end=")" matchgroup=NONE skip="," 156syn match swiftParamDelim contained 157 \ /,/ 158" <Generic Clause> (generics) 159syn region swiftTypeParameters contained contains=swiftVarName,swiftConstraint 160 \ matchgroup=Delimiter start="<" end=">" matchgroup=NONE skip="," 161syn keyword swiftConstraint contained 162 \ where 163 164syn match swiftTypeAliasValue skipwhite skipempty nextgroup=swiftType 165 \ /=/ 166syn match swiftTypeDeclaration skipwhite skipempty nextgroup=swiftType,swiftInOutKeyword 167 \ /:/ 168syn match swiftTypeDeclaration skipwhite skipempty nextgroup=swiftType 169 \ /->/ 170 171syn match swiftKeyword 172 \ /\<case\>/ 173syn region swiftCaseLabelRegion 174 \ matchgroup=swiftKeyword start=/\<case\>/ matchgroup=Delimiter end=/:/ oneline contains=TOP 175syn region swiftDefaultLabelRegion 176 \ matchgroup=swiftKeyword start=/\<default\>/ matchgroup=Delimiter end=/:/ oneline 177 178syn region swiftParenthesisRegion contains=TOP 179 \ matchgroup=NONE start=/(/ end=/)/ 180 181syn region swiftString contains=swiftInterpolationRegion 182 \ start=/"/ skip=/\\\\\|\\"/ end=/"/ 183syn region swiftInterpolationRegion contained contains=TOP 184 \ matchgroup=swiftInterpolation start=/\\(/ end=/)/ 185syn region swiftComment contains=swiftComment,swiftLineComment,swiftTodo 186 \ start="/\*" end="\*/" 187syn region swiftLineComment contains=swiftComment,swiftTodo 188 \ start="//" end="$" 189 190syn match swiftDecimal 191 \ /[+\-]\?\<\([0-9][0-9_]*\)\([.][0-9_]*\)\?\([eE][+\-]\?[0-9][0-9_]*\)\?\>/ 192syn match swiftHex 193 \ /[+\-]\?\<0x[0-9A-Fa-f][0-9A-Fa-f_]*\(\([.][0-9A-Fa-f_]*\)\?[pP][+\-]\?[0-9][0-9_]*\)\?\>/ 194syn match swiftOct 195 \ /[+\-]\?\<0o[0-7][0-7_]*\>/ 196syn match swiftBin 197 \ /[+\-]\?\<0b[01][01_]*\>/ 198 199syn match swiftOperator skipwhite skipempty nextgroup=swiftTypeParameters 200 \ "\.\@<!\.\.\.\@!\|[/=\-+*%<>!&|^~]\@<!\(/[/*]\@![/=\-+*%<>!&|^~]*\|*/\@![/=\-+*%<>!&|^~]*\|->\@![/=\-+*%<>!&|^~]*\|[=+%<>!&|^~][/=\-+*%<>!&|^~]*\)" 201syn match swiftOperator skipwhite skipempty nextgroup=swiftTypeParameters 202 \ "\.\.[<.]" 203 204syn match swiftChar 205 \ /'\([^'\\]\|\\\(["'tnr0\\]\|x[0-9a-fA-F]\{2}\|u[0-9a-fA-F]\{4}\|U[0-9a-fA-F]\{8}\)\)'/ 206 207syn match swiftTupleIndexNumber contains=swiftDecimal 208 \ /\.[0-9]\+/ 209syn match swiftDecimal contained 210 \ /[0-9]\+/ 211 212syn match swiftPreproc 213 \ /#\(\<column\>\|\<dsohandle\>\|\<file\>\|\<line\>\|\<function\>\)/ 214syn match swiftPreproc 215 \ /^\s*#\(\<if\>\|\<else\>\|\<elseif\>\|\<endif\>\|\<error\>\|\<warning\>\)/ 216syn region swiftPreprocFalse 217 \ start="^\s*#\<if\>\s\+\<false\>" end="^\s*#\(\<else\>\|\<elseif\>\|\<endif\>\)" 218 219syn match swiftAttribute 220 \ /@\<\w\+\>/ skipwhite skipempty nextgroup=swiftType,swiftTypeDefinition 221 222syn keyword swiftTodo MARK TODO FIXME contained 223 224syn match swiftCastOp skipwhite skipempty nextgroup=swiftType,swiftCoreTypes 225 \ "\<is\>" 226syn match swiftCastOp skipwhite skipempty nextgroup=swiftType,swiftCoreTypes 227 \ "\<as\>[!?]\?" 228 229syn match swiftNilOps 230 \ "??" 231 232syn region swiftReservedIdentifier oneline 233 \ start=/`/ end=/`/ 234 235hi def link swiftImport Include 236hi def link swiftImportModule Title 237hi def link swiftImportComponent Identifier 238hi def link swiftKeyword Statement 239hi def link swiftCoreTypes Type 240hi def link swiftMultiwordKeyword Statement 241hi def link swiftTypeDefinition Define 242hi def link swiftMultiwordTypeDefinition Define 243hi def link swiftType Type 244hi def link swiftTypePair Type 245hi def link swiftTypeAliasName Identifier 246hi def link swiftTypeName Function 247hi def link swiftConstraint Special 248hi def link swiftFuncDefinition Define 249hi def link swiftDefinitionModifier Operator 250hi def link swiftInOutKeyword Define 251hi def link swiftFuncKeyword Function 252hi def link swiftFuncKeywordGeneral Function 253hi def link swiftTypeAliasDefinition Define 254hi def link swiftVarDefinition Define 255hi def link swiftVarName Identifier 256hi def link swiftImplicitVarName Identifier 257hi def link swiftIdentifierKeyword Identifier 258hi def link swiftTypeAliasValue Delimiter 259hi def link swiftTypeDeclaration Delimiter 260hi def link swiftTypeParameters Delimiter 261hi def link swiftBoolean Boolean 262hi def link swiftString String 263hi def link swiftInterpolation Special 264hi def link swiftComment Comment 265hi def link swiftLineComment Comment 266hi def link swiftDecimal Number 267hi def link swiftHex Number 268hi def link swiftOct Number 269hi def link swiftBin Number 270hi def link swiftOperator Function 271hi def link swiftChar Character 272hi def link swiftLabel Operator 273hi def link swiftMutating Statement 274hi def link swiftPreproc PreCondit 275hi def link swiftPreprocFalse Comment 276hi def link swiftAttribute Type 277hi def link swiftTodo Todo 278hi def link swiftNil Constant 279hi def link swiftCastOp Operator 280hi def link swiftNilOps Operator 281hi def link swiftScope PreProc 282 283let b:current_syntax = "swift" 284 285let &cpo = s:keepcpo 286unlet s:keepcpo 287