swift.vim (8828B)
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 <jgroff@apple.com> 12 " Last Change: 2018 Jan 21 13 " 14 " Vim maintainer: Emir SARI <bitigchi@me.com> 15 16 if exists("b:current_syntax") 17 finish 18 endif 19 20 let s:keepcpo = &cpo 21 set cpo&vim 22 23 syn 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 44 syn match swiftMultiwordKeyword 45 \ "indirect case" 46 47 syn keyword swiftCoreTypes 48 \ Any 49 \ AnyObject 50 51 syn keyword swiftImport skipwhite skipempty nextgroup=swiftImportModule 52 \ import 53 54 syn 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 73 syn keyword swiftInOutKeyword skipwhite skipempty nextgroup=swiftTypeName 74 \ inout 75 76 syn keyword swiftIdentifierKeyword 77 \ Self 78 \ metatype 79 \ self 80 \ super 81 82 syn keyword swiftFuncKeywordGeneral skipwhite skipempty nextgroup=swiftTypeParameters 83 \ init 84 85 syn keyword swiftFuncKeyword 86 \ deinit 87 \ subscript 88 89 syn keyword swiftScope 90 \ autoreleasepool 91 92 syn keyword swiftMutating skipwhite skipempty nextgroup=swiftFuncDefinition 93 \ mutating 94 syn keyword swiftFuncDefinition skipwhite skipempty nextgroup=swiftTypeName,swiftOperator 95 \ func 96 97 syn keyword swiftTypeDefinition skipwhite skipempty nextgroup=swiftTypeName 98 \ class 99 \ enum 100 \ extension 101 \ operator 102 \ precedencegroup 103 \ protocol 104 \ struct 105 106 syn keyword swiftTypeAliasDefinition skipwhite skipempty nextgroup=swiftTypeAliasName 107 \ associatedtype 108 \ typealias 109 110 syn match swiftMultiwordTypeDefinition skipwhite skipempty nextgroup=swiftTypeName 111 \ "indirect enum" 112 113 syn keyword swiftVarDefinition skipwhite skipempty nextgroup=swiftVarName 114 \ let 115 \ var 116 117 syn keyword swiftLabel 118 \ get 119 \ set 120 \ didSet 121 \ willSet 122 123 syn keyword swiftBoolean 124 \ false 125 \ true 126 127 syn keyword swiftNil 128 \ nil 129 130 syn match swiftImportModule contained nextgroup=swiftImportComponent 131 \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ 132 syn match swiftImportComponent contained nextgroup=swiftImportComponent 133 \ /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ 134 135 syn match swiftTypeAliasName contained skipwhite skipempty nextgroup=swiftTypeAliasValue 136 \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ 137 syn match swiftTypeName contained skipwhite skipempty nextgroup=swiftTypeParameters 138 \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>/ 139 syn match swiftVarName contained skipwhite skipempty nextgroup=swiftTypeDeclaration 140 \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ 141 syn match swiftImplicitVarName 142 \ /\$\<[A-Za-z_0-9]\+\>/ 143 144 " TypeName[Optionality]? 145 syn match swiftType contained skipwhite skipempty nextgroup=swiftTypeParameters 146 \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/ 147 " [Type:Type] (dictionary) or [Type] (array) 148 syn region swiftType contained contains=swiftTypePair,swiftType 149 \ matchgroup=Delimiter start=/\[/ end=/\]/ 150 syn 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 154 syn region swiftType contained contains=swiftType,swiftParamDelim 155 \ matchgroup=Delimiter start="[^@]\?(" end=")" matchgroup=NONE skip="," 156 syn match swiftParamDelim contained 157 \ /,/ 158 " <Generic Clause> (generics) 159 syn region swiftTypeParameters contained contains=swiftVarName,swiftConstraint 160 \ matchgroup=Delimiter start="<" end=">" matchgroup=NONE skip="," 161 syn keyword swiftConstraint contained 162 \ where 163 164 syn match swiftTypeAliasValue skipwhite skipempty nextgroup=swiftType 165 \ /=/ 166 syn match swiftTypeDeclaration skipwhite skipempty nextgroup=swiftType,swiftInOutKeyword 167 \ /:/ 168 syn match swiftTypeDeclaration skipwhite skipempty nextgroup=swiftType 169 \ /->/ 170 171 syn match swiftKeyword 172 \ /\<case\>/ 173 syn region swiftCaseLabelRegion 174 \ matchgroup=swiftKeyword start=/\<case\>/ matchgroup=Delimiter end=/:/ oneline contains=TOP 175 syn region swiftDefaultLabelRegion 176 \ matchgroup=swiftKeyword start=/\<default\>/ matchgroup=Delimiter end=/:/ oneline 177 178 syn region swiftParenthesisRegion contains=TOP 179 \ matchgroup=NONE start=/(/ end=/)/ 180 181 syn region swiftString contains=swiftInterpolationRegion 182 \ start=/"/ skip=/\\\\\|\\"/ end=/"/ 183 syn region swiftInterpolationRegion contained contains=TOP 184 \ matchgroup=swiftInterpolation start=/\\(/ end=/)/ 185 syn region swiftComment contains=swiftComment,swiftLineComment,swiftTodo 186 \ start="/\*" end="\*/" 187 syn region swiftLineComment contains=swiftComment,swiftTodo 188 \ start="//" end="$" 189 190 syn match swiftDecimal 191 \ /[+\-]\?\<\([0-9][0-9_]*\)\([.][0-9_]*\)\?\([eE][+\-]\?[0-9][0-9_]*\)\?\>/ 192 syn match swiftHex 193 \ /[+\-]\?\<0x[0-9A-Fa-f][0-9A-Fa-f_]*\(\([.][0-9A-Fa-f_]*\)\?[pP][+\-]\?[0-9][0-9_]*\)\?\>/ 194 syn match swiftOct 195 \ /[+\-]\?\<0o[0-7][0-7_]*\>/ 196 syn match swiftBin 197 \ /[+\-]\?\<0b[01][01_]*\>/ 198 199 syn match swiftOperator skipwhite skipempty nextgroup=swiftTypeParameters 200 \ "\.\@<!\.\.\.\@!\|[/=\-+*%<>!&|^~]\@<!\(/[/*]\@![/=\-+*%<>!&|^~]*\|*/\@![/=\-+*%<>!&|^~]*\|->\@![/=\-+*%<>!&|^~]*\|[=+%<>!&|^~][/=\-+*%<>!&|^~]*\)" 201 syn match swiftOperator skipwhite skipempty nextgroup=swiftTypeParameters 202 \ "\.\.[<.]" 203 204 syn match swiftChar 205 \ /'\([^'\\]\|\\\(["'tnr0\\]\|x[0-9a-fA-F]\{2}\|u[0-9a-fA-F]\{4}\|U[0-9a-fA-F]\{8}\)\)'/ 206 207 syn match swiftTupleIndexNumber contains=swiftDecimal 208 \ /\.[0-9]\+/ 209 syn match swiftDecimal contained 210 \ /[0-9]\+/ 211 212 syn match swiftPreproc 213 \ /#\(\<column\>\|\<dsohandle\>\|\<file\>\|\<line\>\|\<function\>\)/ 214 syn match swiftPreproc 215 \ /^\s*#\(\<if\>\|\<else\>\|\<elseif\>\|\<endif\>\|\<error\>\|\<warning\>\)/ 216 syn region swiftPreprocFalse 217 \ start="^\s*#\<if\>\s\+\<false\>" end="^\s*#\(\<else\>\|\<elseif\>\|\<endif\>\)" 218 219 syn match swiftAttribute 220 \ /@\<\w\+\>/ skipwhite skipempty nextgroup=swiftType,swiftTypeDefinition 221 222 syn keyword swiftTodo MARK TODO FIXME contained 223 224 syn match swiftCastOp skipwhite skipempty nextgroup=swiftType,swiftCoreTypes 225 \ "\<is\>" 226 syn match swiftCastOp skipwhite skipempty nextgroup=swiftType,swiftCoreTypes 227 \ "\<as\>[!?]\?" 228 229 syn match swiftNilOps 230 \ "??" 231 232 syn region swiftReservedIdentifier oneline 233 \ start=/`/ end=/`/ 234 235 hi def link swiftImport Include 236 hi def link swiftImportModule Title 237 hi def link swiftImportComponent Identifier 238 hi def link swiftKeyword Statement 239 hi def link swiftCoreTypes Type 240 hi def link swiftMultiwordKeyword Statement 241 hi def link swiftTypeDefinition Define 242 hi def link swiftMultiwordTypeDefinition Define 243 hi def link swiftType Type 244 hi def link swiftTypePair Type 245 hi def link swiftTypeAliasName Identifier 246 hi def link swiftTypeName Function 247 hi def link swiftConstraint Special 248 hi def link swiftFuncDefinition Define 249 hi def link swiftDefinitionModifier Operator 250 hi def link swiftInOutKeyword Define 251 hi def link swiftFuncKeyword Function 252 hi def link swiftFuncKeywordGeneral Function 253 hi def link swiftTypeAliasDefinition Define 254 hi def link swiftVarDefinition Define 255 hi def link swiftVarName Identifier 256 hi def link swiftImplicitVarName Identifier 257 hi def link swiftIdentifierKeyword Identifier 258 hi def link swiftTypeAliasValue Delimiter 259 hi def link swiftTypeDeclaration Delimiter 260 hi def link swiftTypeParameters Delimiter 261 hi def link swiftBoolean Boolean 262 hi def link swiftString String 263 hi def link swiftInterpolation Special 264 hi def link swiftComment Comment 265 hi def link swiftLineComment Comment 266 hi def link swiftDecimal Number 267 hi def link swiftHex Number 268 hi def link swiftOct Number 269 hi def link swiftBin Number 270 hi def link swiftOperator Function 271 hi def link swiftChar Character 272 hi def link swiftLabel Operator 273 hi def link swiftMutating Statement 274 hi def link swiftPreproc PreCondit 275 hi def link swiftPreprocFalse Comment 276 hi def link swiftAttribute Type 277 hi def link swiftTodo Todo 278 hi def link swiftNil Constant 279 hi def link swiftCastOp Operator 280 hi def link swiftNilOps Operator 281 hi def link swiftScope PreProc 282 283 let b:current_syntax = "swift" 284 285 let &cpo = s:keepcpo 286 unlet s:keepcpo