From d385d419eccff316671115b6a74a009ebea92292 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 5 Dec 2015 10:11:21 -0800 Subject: [PATCH] [vim] Add official Apple swift plugin --- vim/bundle/apple-swift/ftdetect/sil.vim | 1 + vim/bundle/apple-swift/ftdetect/swift.vim | 1 + vim/bundle/apple-swift/ftdetect/swiftgyb.vim | 2 + vim/bundle/apple-swift/ftplugin/swift.vim | 5 + vim/bundle/apple-swift/ftplugin/swiftgyb.vim | 1 + vim/bundle/apple-swift/syntax/sil.vim | 93 ++++++++++++++++ vim/bundle/apple-swift/syntax/swift.vim | 105 +++++++++++++++++++ vim/bundle/apple-swift/syntax/swiftgyb.vim | 14 +++ vimrc | 1 + 9 files changed, 223 insertions(+) create mode 100644 vim/bundle/apple-swift/ftdetect/sil.vim create mode 100644 vim/bundle/apple-swift/ftdetect/swift.vim create mode 100644 vim/bundle/apple-swift/ftdetect/swiftgyb.vim create mode 100644 vim/bundle/apple-swift/ftplugin/swift.vim create mode 100644 vim/bundle/apple-swift/ftplugin/swiftgyb.vim create mode 100644 vim/bundle/apple-swift/syntax/sil.vim create mode 100644 vim/bundle/apple-swift/syntax/swift.vim create mode 100644 vim/bundle/apple-swift/syntax/swiftgyb.vim diff --git a/vim/bundle/apple-swift/ftdetect/sil.vim b/vim/bundle/apple-swift/ftdetect/sil.vim new file mode 100644 index 0000000..3d856ed --- /dev/null +++ b/vim/bundle/apple-swift/ftdetect/sil.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.sil set ft=sil diff --git a/vim/bundle/apple-swift/ftdetect/swift.vim b/vim/bundle/apple-swift/ftdetect/swift.vim new file mode 100644 index 0000000..c9dc512 --- /dev/null +++ b/vim/bundle/apple-swift/ftdetect/swift.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.swift set ft=swift diff --git a/vim/bundle/apple-swift/ftdetect/swiftgyb.vim b/vim/bundle/apple-swift/ftdetect/swiftgyb.vim new file mode 100644 index 0000000..fc8919f --- /dev/null +++ b/vim/bundle/apple-swift/ftdetect/swiftgyb.vim @@ -0,0 +1,2 @@ +au BufNewFile,BufRead *.swift.gyb set ft=swiftgyb + diff --git a/vim/bundle/apple-swift/ftplugin/swift.vim b/vim/bundle/apple-swift/ftplugin/swift.vim new file mode 100644 index 0000000..acbb283 --- /dev/null +++ b/vim/bundle/apple-swift/ftplugin/swift.vim @@ -0,0 +1,5 @@ +setlocal comments=s1:/*,mb:*,ex:*/,:///,:// +setlocal expandtab +setlocal ts=2 +setlocal sw=2 +setlocal smartindent diff --git a/vim/bundle/apple-swift/ftplugin/swiftgyb.vim b/vim/bundle/apple-swift/ftplugin/swiftgyb.vim new file mode 100644 index 0000000..2785702 --- /dev/null +++ b/vim/bundle/apple-swift/ftplugin/swiftgyb.vim @@ -0,0 +1 @@ +runtime! ftplugin/swift.vim diff --git a/vim/bundle/apple-swift/syntax/sil.vim b/vim/bundle/apple-swift/syntax/sil.vim new file mode 100644 index 0000000..7474292 --- /dev/null +++ b/vim/bundle/apple-swift/syntax/sil.vim @@ -0,0 +1,93 @@ +" Vim syntax file +" Language: sil + +if exists("b:current_syntax") + finish +endif + +syn keyword swiftImport import skipwhite nextgroup=swiftImportModule +syn match swiftImportModule /\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent +syn match swiftImportComponent /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent + +syn match swiftLineComment /^#!.*/ +syn match swiftTypeName /\<[A-Z][a-zA-Z_0-9]*\>/ +syn match swiftDecimal /\<[-]\?[0-9]\+\>/ +syn match swiftDecimal /\<[-+]\?[0-9]\+\>/ + +syn match swiftTypeName /\$\*\<\?[A-Z][a-zA-Z0-9_]*\>/ +syn match swiftVarName /%\<[A-z[a-z_0-9]\+\(#[0-9]\+\)\?\>/ + +syn keyword swiftKeyword break case continue default do else for if in static switch repeat return where while skipwhite + +syn keyword swiftKeyword sil internal thunk skipwhite +syn keyword swiftKeyword public hidden private shared public_external hidden_external skipwhite +syn keyword swiftKeyword getter setter allocator initializer enumelt destroyer globalaccessor objc skipwhite +syn keyword swiftKeyword alloc_stack alloc_ref alloc_ref_dynamic alloc_box dealloc_stack dealloc_box dealloc_ref skipwhite +syn keyword swiftKeyword debug_value debug_value_addr skipwhite +syn keyword swiftKeyword load store assign mark_uninitialized mark_function_escape copy_addr destroy_addr index_addr index_raw_pointer to skipwhite +syn keyword swiftKeyword strong_retain strong_retain_autoreleased strong_release strong_retain_unowned ref_to_unowned unowned_to_ref unowned_retain unowned_release load_weak store_weak fix_lifetime skipwhite +syn keyword swiftKeyword function_ref integer_literal float_literal string_literal global_addr skipwhite +syn keyword swiftKeyword class_method super_method witness_method dynamic_method skipwhite +syn keyword swiftKeyword apply partial_apply builtin skipwhite +syn keyword swiftKeyword metatype value_metatype existential_metatype skipwhite +syn keyword swiftKeyword retain_value release_value tuple tuple_extract tuple_element_addr struct struct_extract struct_element_addr ref_element_addr skipwhite +syn keyword swiftKeyword init_enum_data_addr unchecked_enum_data unchecked_take_enum_data_addr inject_enum_addr skipwhite +syn keyword swiftKeyword init_existential_addr deinit_existential_addr open_existential_addr init_existential_ref open_existential_ref skipwhite +syn keyword swiftKeyword upcast address_to_pointer pointer_to_address unchecked_addr_cast unchecked_ref_cast ref_to_raw_pointer raw_pointer_to_ref convert_function thick_to_objc_metatype objc_to_thick_metatype thin_to_thick_function is_nonnull unchecked_ref_bit_cast unchecked_trivial_bit_cast skipwhite +syn keyword swiftKeyword unconditional_checked_cast skipwhite +syn keyword swiftKeyword cond_fail skipwhite +syn keyword swiftKeyword unreachable return autorelease_return br cond_br switch_value select_value switch_enum switch_enum_addr dynamic_method_br checked_cast_br skipwhite +syn keyword swiftKeyword project_block_storage init_block_storage_header copy_block skipwhite + +syn keyword swiftTypeDefinition class extension protocol struct typealias enum skipwhite nextgroup=swiftTypeName +syn region swiftTypeAttributes start="\[" end="\]" skipwhite contained nextgroup=swiftTypeName +syn match swiftTypeName /\<[A-Za-z_][A-Za-z_0-9\.]*\>/ contained nextgroup=swiftTypeParameters + +syn region swiftTypeParameters start="<" end=">" skipwhite contained + +syn keyword swiftFuncDefinition func skipwhite nextgroup=swiftFuncAttributes,swiftFuncName,swiftOperator +syn region swiftFuncAttributes start="\[" end="\]" skipwhite contained nextgroup=swiftFuncName,swiftOperator +syn match swiftFuncName /\<[A-Za-z_][A-Za-z_0-9]*\>/ skipwhite contained nextgroup=swiftTypeParameters +syn keyword swiftFuncKeyword subscript init destructor nextgroup=swiftTypeParameters + +syn keyword swiftVarDefinition var skipwhite nextgroup=swiftVarName +syn keyword swiftVarDefinition let skipwhite nextgroup=swiftVarName +syn match swiftVarName /\<[A-Za-z_][A-Za-z_0-9]*\>/ skipwhite contained + +syn keyword swiftDefinitionModifier static + +syn match swiftImplicitVarName /\$\<[A-Za-z_0-9]\+\>/ + +hi def link swiftImport Include +hi def link swiftImportModule Title +hi def link swiftImportComponent Identifier +hi def link swiftKeyword Statement +hi def link swiftTypeDefinition Define +hi def link swiftTypeName Type +hi def link swiftTypeParameters Special +hi def link swiftTypeAttributes PreProc +hi def link swiftFuncDefinition Define +hi def link swiftDefinitionModifier Define +hi def link swiftFuncName Function +hi def link swiftFuncAttributes PreProc +hi def link swiftFuncKeyword Function +hi def link swiftVarDefinition Define +hi def link swiftVarName Identifier +hi def link swiftImplicitVarName Identifier +hi def link swiftIdentifierKeyword Identifier +hi def link swiftTypeDeclaration Delimiter +hi def link swiftBoolean Boolean +hi def link swiftString String +hi def link swiftInterpolation Special +hi def link swiftComment Comment +hi def link swiftLineComment Comment +hi def link swiftDecimal Number +hi def link swiftHex Number +hi def link swiftOct Number +hi def link swiftBin Number +hi def link swiftOperator Function +hi def link swiftChar Character +hi def link swiftLabel Label +hi def link swiftNew Operator + +let b:current_syntax = "sil" diff --git a/vim/bundle/apple-swift/syntax/swift.vim b/vim/bundle/apple-swift/syntax/swift.vim new file mode 100644 index 0000000..407aed1 --- /dev/null +++ b/vim/bundle/apple-swift/syntax/swift.vim @@ -0,0 +1,105 @@ +" Vim syntax file +" Language: swift +" Maintainer: Joe Groff +" Last Change: 2013 Feb 2 + +if exists("b:current_syntax") + finish +endif + +syn keyword swiftImport import skipwhite nextgroup=swiftImportModule + +syn match swiftImportModule /\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent +syn match swiftImportComponent /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent + +syn keyword swiftKeyword break case continue default do else for if in static switch repeat return where while public internal private mutating nonmutating var let typealias protocol extension skipwhite + +syn keyword swiftTypeDefinition class extension protocol struct typealias enum skipwhite nextgroup=swiftTypeName +syn region swiftTypeAttributes start="\[" end="\]" skipwhite contained nextgroup=swiftTypeName +syn match swiftTypeName /\<[A-Za-z_][A-Za-z_0-9\.]*\>/ contained nextgroup=swiftTypeParameters + +syn region swiftTypeParameters start="<" end=">" skipwhite contained + +syn keyword swiftMutating mutating skipwhite nextgroup=swiftFuncDefinition +syn keyword swiftFuncDefinition func skipwhite nextgroup=swiftFuncAttributes,swiftFuncName,swiftOperator +syn region swiftFuncAttributes start="\[" end="\]" skipwhite contained nextgroup=swiftFuncName,swiftOperator +syn match swiftFuncName /\<[A-Za-z_][A-Za-z_0-9]*\>/ skipwhite contained nextgroup=swiftTypeParameters +syn keyword swiftFuncKeyword subscript init destructor nextgroup=swiftTypeParameters + +syn keyword swiftVarDefinition var skipwhite nextgroup=swiftVarName +syn keyword swiftVarDefinition let skipwhite nextgroup=swiftVarName +syn match swiftVarName /\<[A-Za-z_][A-Za-z_0-9]*\>/ skipwhite contained + +syn keyword swiftDefinitionModifier static public internal private + +syn match swiftImplicitVarName /\$\<[A-Za-z_0-9]\+\>/ + +syn match swiftTypeDeclaration /:/ nextgroup=swiftTypeAttributes,swiftTypeName skipwhite +syn match swiftTypeDeclaration /->/ nextgroup=swiftTypeAttributes,swiftTypeName skipwhite + +syn keyword swiftIdentifierKeyword metatype super self Self + +syn keyword swiftNew new skipwhite nextgroup=swiftTypeName + +syn keyword swiftBoolean true false + +syn region swiftString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=swiftInterpolation +syn region swiftInterpolation start=/\\(/ end=/)/ contained +syn region swiftComment start="/\*" end="\*/" contains=swiftComment,swiftLineComment,swiftTodo +syn region swiftLineComment start="//" end="$" contains=swiftComment,swiftTodo + +syn match swiftDecimal /[+\-]\?\<\([0-9][0-9_]*\)\([.][0-9_]*\)\?\([eE][+\-]\?[0-9][0-9_]*\)\?\>/ +syn match swiftHex /[+\-]\?\<0x[0-9A-Fa-f][0-9A-Fa-f_]*\(\([.][0-9A-Fa-f_]*\)\?[pP][+\-]\?[0-9][0-9_]*\)\?\>/ +syn match swiftOct /[+\-]\?\<0o[0-7][0-7_]*\>/ +syn match swiftBin /[+\-]\?\<0b[01][01_]*\>/ + +syn match swiftOperator +\.\@!&|^~]\@!&|^~]*\|*/\@![/=\-+*%<>!&|^~]*\|->\@![/=\-+*%<>!&|^~]*\|[=+%<>!&|^~][/=\-+*%<>!&|^~]*\)+ skipwhite nextgroup=swiftTypeParameters +syn match swiftOperator "\.\.[<.]" skipwhite nextgroup=swiftTypeParameters + +syn match swiftChar /'\([^'\\]\|\\\(["'tnr0\\]\|x[0-9a-fA-F]\{2}\|u[0-9a-fA-F]\{4}\|U[0-9a-fA-F]\{8}\)\)'/ + +syn match swiftLabel /\(\\|\\):\@=/ + +syn match swiftPreproc /^#\\|^#\/ + +syn match swiftAttribute /@\<\w\+\>/ skipwhite + +syn keyword swiftTodo TODO FIXME contained + +hi def link swiftImport Include +hi def link swiftImportModule Title +hi def link swiftImportComponent Identifier +hi def link swiftKeyword Statement +hi def link swiftTypeDefinition Define +hi def link swiftTypeName Type +hi def link swiftTypeParameters Special +hi def link swiftTypeAttributes PreProc +hi def link swiftFuncDefinition Define +hi def link swiftDefinitionModifier Define +hi def link swiftFuncName Function +hi def link swiftFuncAttributes PreProc +hi def link swiftFuncKeyword Function +hi def link swiftVarDefinition Define +hi def link swiftVarName Identifier +hi def link swiftImplicitVarName Identifier +hi def link swiftIdentifierKeyword Identifier +hi def link swiftTypeDeclaration Delimiter +hi def link swiftBoolean Boolean +hi def link swiftString String +hi def link swiftInterpolation Special +hi def link swiftComment Comment +hi def link swiftLineComment Comment +hi def link swiftDecimal Number +hi def link swiftHex Number +hi def link swiftOct Number +hi def link swiftBin Number +hi def link swiftOperator Function +hi def link swiftChar Character +hi def link swiftLabel Label +hi def link swiftNew Operator +hi def link swiftMutating Statement +hi def link swiftPreproc PreCondit +hi def link swiftAttribute Type +hi def link swiftTodo Todo + +let b:current_syntax = "swift" diff --git a/vim/bundle/apple-swift/syntax/swiftgyb.vim b/vim/bundle/apple-swift/syntax/swiftgyb.vim new file mode 100644 index 0000000..44e925b --- /dev/null +++ b/vim/bundle/apple-swift/syntax/swiftgyb.vim @@ -0,0 +1,14 @@ +" Vim syntax file +" Language: gyb on swift + +runtime! syntax/swift.vim +unlet b:current_syntax + +syn include @Python syntax/python.vim +syn region pythonCode matchgroup=gybPythonCode start=+^ *%+ end=+$+ contains=@Python keepend +syn region pythonCode matchgroup=gybPythonCode start=+%{+ end=+}%+ contains=@Python keepend +syn match gybPythonCode /\${[^}]*}/ +hi def link gybPythonCode CursorLineNr + +let b:current_syntax = "swiftgyb" + diff --git a/vimrc b/vimrc index 933375e..23a4658 100644 --- a/vimrc +++ b/vimrc @@ -37,6 +37,7 @@ Plugin 'scrooloose/nerdtree' Plugin 'wincent/command-t' "Plugin 'erynofwales/vim-fancyfolds' +Plugin 'apple-swift', {'pinned': 1} " Colors~ Plugin 'altercation/vim-colors-solarized'