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