Skip to content

Commit a2cca58

Browse files
author
Akshay Hegde
committed
Add syntax highlighting for type casts
This commit separates `as` and `is` into their own keyword syntax, and contains them in a new syntax region for type casts. Also removes an extraneous `swiftGenericsWrapper` in the `swiftType` syntax match. Fixes #48
1 parent 9fb609e commit a2cca58

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

example/example.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,5 @@ self.init(className: "Item", dictionary: [
345345
"link": item.link,
346346
"date": item.date,
347347
"summary": item.summary])
348+
349+
XCAssertEqual(variables as NSDictionary, expectedVariables as NSDictionary, "\(template)")

syntax/swift.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ syntax keyword swiftAvailabilityArg renamed unavailable introduced deprecated ob
102102

103103
" Keywords {{{
104104
syntax keyword swiftKeywords
105-
\ as
106105
\ associatedtype
107106
\ atexit
108107
\ break
@@ -133,7 +132,6 @@ syntax keyword swiftKeywords
133132
\ init
134133
\ inout
135134
\ internal
136-
\ is
137135
\ lazy
138136
\ let
139137
\ mutating
@@ -214,13 +212,14 @@ syntax keyword swiftDebugIdentifier
214212
syntax keyword swiftLineDirective #setline
215213

216214
syntax region swiftTypeWrapper start="\v:\s*" skip="\s*,\s*$*\s*" end="$\|/"me=e-1 contains=ALLBUT,swiftInterpolatedWrapper transparent
215+
syntax region swiftTypeCastWrapper start="\(as\|is\)\(!\|?\)\=\s\+" end="\v(\s|$|\{)" contains=swiftType,swiftCastKeyword keepend transparent oneline
217216
syntax region swiftGenericsWrapper start="\v\<" end="\v\>" contains=swiftType transparent oneline
218217
syntax region swiftLiteralWrapper start="\v\=\s*" skip="\v[^\[\]]\(\)" end="\v(\[\]|\(\))" contains=ALL transparent oneline
219218
syntax region swiftReturnWrapper start="\v-\>\s*" end="\v(\{|$)" contains=swiftType transparent oneline
220-
syntax match swiftType "\v<\u\w*" contained containedin=swiftGenericsWrapper,swiftTypeWrapper,swiftLiteralWrapper,swiftGenericsWrapper
219+
syntax match swiftType "\v<\u\w*" contained containedin=swiftTypeWrapper,swiftLiteralWrapper,swiftGenericsWrapper,swiftTypeCastWrapper
221220

222221
syntax keyword swiftImports import
223-
222+
syntax keyword swiftCastKeyword is as contained
224223

225224
" 'preprocesor' stuff
226225
syntax keyword swiftPreprocessor
@@ -251,6 +250,7 @@ highlight default link swiftNumber Number
251250
highlight default link swiftBoolean Boolean
252251

253252
highlight default link swiftOperator Operator
253+
highlight default link swiftCastKeyword Keyword
254254
highlight default link swiftKeywords Keyword
255255
highlight default link swiftEscapedReservedWord Normal
256256
highlight default link swiftClosureArgument Operator

0 commit comments

Comments
 (0)