Skip to content

Commit 1752b11

Browse files
committed
Merge pull request #2886 from compnerd/vim-syntax-improvements
Vim syntax improvements
2 parents 19f7c3c + 6e155f9 commit 1752b11

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

utils/vim/syntax/swift.vim

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,46 @@ if exists("b:current_syntax")
77
finish
88
endif
99

10-
syn keyword swiftImport import skipwhite nextgroup=swiftImportModule
11-
12-
syn match swiftImportModule /\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent
13-
syn match swiftImportComponent /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent
14-
1510
syn keyword swiftKeyword
1611
\ associatedtype
1712
\ break
1813
\ case
1914
\ catch
2015
\ continue
21-
\ convenience
2216
\ default
2317
\ defer
2418
\ do
2519
\ else
26-
\ extension
27-
\ final
2820
\ for
2921
\ guard
3022
\ if
3123
\ in
32-
\ internal
3324
\ let
34-
\ mutating
35-
\ nonmutating
36-
\ override
37-
\ private
38-
\ protocol
39-
\ public
4025
\ repeat
41-
\ required
4226
\ return
43-
\ static
4427
\ switch
4528
\ throw
4629
\ try
4730
\ typealias
4831
\ var
4932
\ where
5033
\ while
34+
syn match swiftMultiwordKeyword
35+
\ "indirect case"
36+
37+
syn keyword swiftImport skipwhite nextgroup=swiftImportModule
38+
\ import
5139

5240
syn keyword swiftDefinitionModifier
41+
\ convenience
5342
\ dynamic
43+
\ final
5444
\ internal
45+
\ nonmutating
46+
\ override
5547
\ private
5648
\ public
49+
\ required
5750
\ rethrows
5851
\ static
5952
\ throws
@@ -75,6 +68,11 @@ syn keyword swiftFuncKeyword
7568
syn keyword swiftScope
7669
\ autoreleasepool
7770

71+
syn keyword swiftMutating skipwhite nextgroup=swiftFuncDefinition
72+
\ mutating
73+
syn keyword swiftFuncDefinition skipwhite nextgroup=swiftTypeName,swiftOperator
74+
\ func
75+
7876
syn keyword swiftTypeDefinition skipwhite nextgroup=swiftTypeName
7977
\ class
8078
\ enum
@@ -83,47 +81,57 @@ syn keyword swiftTypeDefinition skipwhite nextgroup=swiftTypeName
8381
\ struct
8482
\ typealias
8583

86-
syn keyword swiftNew skipwhite nextgroup=swiftTypeName
87-
\ new
84+
syn keyword swiftVarDefinition skipwhite nextgroup=swiftVarName
85+
\ let
86+
\ var
87+
88+
syn keyword swiftLabel
89+
\ get
90+
\ set
91+
92+
syn keyword swiftBoolean
93+
\ false
94+
\ true
95+
96+
syn keyword swiftNil
97+
\ nil
98+
99+
syn match swiftImportModule contained nextgroup=swiftImportComponent
100+
\ /\<[A-Za-z_][A-Za-z_0-9]*\>/
101+
syn match swiftImportComponent contained nextgroup=swiftImportComponent
102+
\ /\.\<[A-Za-z_][A-Za-z_0-9]*\>/
88103

89104
syn match swiftTypeName contained nextgroup=swiftTypeParameters
90105
\ /\<[A-Za-z_][A-Za-z_0-9\.]*\>/
106+
syn match swiftVarName contained skipwhite nextgroup=swiftTypeDeclaration
107+
\ /\<[A-Za-z_][A-Za-z_0-9]*\>/
108+
syn match swiftImplicitVarName
109+
\ /\$\<[A-Za-z_0-9]\+\>/
91110

92111
" TypeName[Optionality]?
93112
syn match swiftType contained nextgroup=swiftTypeParameters
94113
\ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/
95114
" [Type:Type] (dictionary) or [Type] (array)
96115
syn region swiftType contained contains=swiftTypePair,swiftType
97-
\ start=/\[/ end=/\]/
116+
\ matchgroup=Delimiter start=/\[/ end=/\]/
98117
syn match swiftTypePair contained nextgroup=swiftTypeParameters,swiftTypeDeclaration
99118
\ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/
100119
" (Type[, Type]) (tuple)
120+
" FIXME: we should be able to use skip="," and drop swiftParamDelim
101121
syn region swiftType contained contains=swiftType,swiftParamDelim
102-
\ start="[^@](" end=")"
122+
\ matchgroup=Delimiter start="[^@](" end=")" matchgroup=NONE skip=","
103123
syn match swiftParamDelim contained
104124
\ /,/
105125
" <Generic Clause> (generics)
106-
syn region swiftTypeParameters contained contains=swiftArchetype,swiftConstraint
107-
\ start="<" end=">"
108-
syn match swiftArchetype contained skipwhite nextgroup=swiftTypeDeclaration
109-
\ /\<[A-Za-z_][A-Za-z_0-9]*\>/
126+
syn region swiftTypeParameters contained contains=swiftVarName,swiftConstraint
127+
\ matchgroup=Delimiter start="<" end=">" matchgroup=NONE skip=","
110128
syn keyword swiftConstraint contained
111129
\ where
112130

113-
syn keyword swiftMutating mutating skipwhite nextgroup=swiftFuncDefinition
114-
syn keyword swiftFuncDefinition func skipwhite nextgroup=swiftFuncName,swiftOperator
115-
syn match swiftFuncName /\<[A-Za-z_][A-Za-z_0-9]*\>/ contained skipwhite nextgroup=swiftTypeParameters
116-
117-
syn keyword swiftVarDefinition var skipwhite nextgroup=swiftVarName
118-
syn keyword swiftVarDefinition let skipwhite nextgroup=swiftVarName
119-
syn match swiftVarName /\<[A-Za-z_][A-Za-z_0-9]*\>/ contained
120-
121-
syn match swiftImplicitVarName /\$\<[A-Za-z_0-9]\+\>/
122-
123-
syn match swiftTypeDeclaration /:/ skipwhite nextgroup=swiftType
124-
syn match swiftTypeDeclaration /->/ skipwhite nextgroup=swiftType
125-
126-
syn keyword swiftBoolean true false
131+
syn match swiftTypeDeclaration skipwhite nextgroup=swiftType
132+
\ /:/
133+
syn match swiftTypeDeclaration skipwhite nextgroup=swiftType
134+
\ /->/
127135

128136
syn region swiftString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=swiftInterpolation
129137
syn region swiftInterpolation start=/\\(/ end=/)/ contained
@@ -140,16 +148,15 @@ syn match swiftOperator "\.\.[<.]" skipwhite nextgroup=swiftTypeParameters
140148

141149
syn match swiftChar /'\([^'\\]\|\\\(["'tnr0\\]\|x[0-9a-fA-F]\{2}\|u[0-9a-fA-F]\{4}\|U[0-9a-fA-F]\{8}\)\)'/
142150

143-
syn keyword swiftLabel get set
144-
151+
syn match swiftPreproc /#\(\<file\>\|\<line\>\)/
145152
syn match swiftPreproc /^\s*#\(\<if\>\|\<else\>\|\<elseif\>\|\<endif\>\)/
146153
syn region swiftPreprocFalse start="^\s*#\<if\>\s\+\<false\>" end="^\s*#\(\<else\>\|\<elseif\>\|\<endif\>\)"
147154

148155
syn match swiftAttribute /@\<\w\+\>/ skipwhite nextgroup=swiftType
149156

150157
syn keyword swiftTodo TODO FIXME contained
151-
syn keyword swiftNil nil
152158

159+
syn match swiftCastOp "\<is\>" skipwhite nextgroup=swiftType
153160
syn match swiftCastOp "\<as\>[!?]\?" skipwhite nextgroup=swiftType
154161

155162
syn match swiftNilOps "??"
@@ -161,15 +168,14 @@ hi def link swiftImport Include
161168
hi def link swiftImportModule Title
162169
hi def link swiftImportComponent Identifier
163170
hi def link swiftKeyword Statement
171+
hi def link swiftMultiwordKeyword Statement
164172
hi def link swiftTypeDefinition Define
165173
hi def link swiftType Type
166174
hi def link swiftTypePair Type
167175
hi def link swiftTypeName Function
168-
hi def link swiftArchetype Identifier
169176
hi def link swiftConstraint Special
170177
hi def link swiftFuncDefinition Define
171178
hi def link swiftDefinitionModifier Define
172-
hi def link swiftFuncName Function
173179
hi def link swiftFuncKeyword Function
174180
hi def link swiftFuncKeywordGeneral Function
175181
hi def link swiftVarDefinition Define
@@ -190,7 +196,6 @@ hi def link swiftBin Number
190196
hi def link swiftOperator Function
191197
hi def link swiftChar Character
192198
hi def link swiftLabel Operator
193-
hi def link swiftNew Operator
194199
hi def link swiftMutating Statement
195200
hi def link swiftPreproc PreCondit
196201
hi def link swiftPreprocFalse Comment

0 commit comments

Comments
 (0)