summaryrefslogtreecommitdiffstats
path: root/syntax/swift.vim
blob: e3c3dd078fe68d6fe85ff8dc84288674df6e138f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
" Language:    Swift<https://developer.apple.com/swift/>
" Maintainer:  toyama satoshi <toyamarinyon@gmail.com>
" URL:         http://github.com/toyamarinyon/vim-swift
" License:     GPL

" Bail if our syntax is already loaded.
if exists('b:current_syntax') && b:current_syntax == 'swift'
  finish
endif

" {{{ Whitespace and Comments
syntax region swiftComment start=#\/\*# end=#\*\/#
syntax match swiftComment /\/\/.*/
highlight default link swiftComment Comment
" }}}

" {{{ Identifiers
syntax match swiftIdentifier /[[:alpha:]_][[:alnum:]_]*/
highlight default link swiftIdentifier Identifier
" }}}

" {{{ Keywords
" Keywords used in declarations:
syntax keyword swiftDeclarationKeywords class deinit enum extension func import init let protocol static struct subscript typealias var
highlight default link swiftDeclarationKeywords Keyword
" Keywords used in statements:
syntax keyword swiftStatementKeywords break case continue default do else fallthrough if in for return switch where while
highlight default link swiftStatementKeywords Keyword
" Keywords used in expressions and types:
syntax keyword swiftExpressionTypeKeywords as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__
highlight default link swiftExpressionTypeKeywords Keyword
" Keywords reserved in particular contexts:
syntax keyword swiftReserveKeywords associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned unowned(safe) unowned(unsafe) weak willSet
highlight default link swiftReserveKeywords Keyword
" }}}

" {{{ Literals
" Integer literal
syntax match swiftIntegerLiteral /\<\d\+\%(_\d\+\)*\%(\.\d\+\%(_\d\+\)*\)\=\>/
syntax match swiftIntegerLiteral /\<\d\+\%(_\d\+\)*\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)\>/
syntax match swiftIntegerLiteral /\<0x\x\+\%(_\x\+\)*\>/
syntax match swiftIntegerLiteral /\<0o\o\+\%(_\o\+\)*\>/
syntax match swiftIntegerLiteral /\<0b[01]\+\%(_[01]\+\)*\>/
highlight default link swiftIntegerLiteral Number
" String literal
syntax region swiftStringLiteral start=/"/ skip=/\\"/ end=/"/
highlight default link swiftStringLiteral String
" }}}

" {{{ Operators
syntax keyword swiftOperatorKeywords / = - + ! * % < > & \| ^ ~ .
highlight default link swiftOperatorKeywords Operator
" }}}

" {{{ Type
syntax match swiftTypeIdentifier /\<[[:alpha:]_][[:alnum:]_.]*/ contained
syntax match swiftType /: .*/ contains=swiftTypeIdentifier
highlight default link swiftType Operator
highlight default link swiftTypeIdentifier Type
" }}}

if !exists('b:current_syntax')
  let b:current_syntax = 'swift'
endif