diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b44c43 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.env +.env.yaml +/*.xcodeproj +/.build +/Packages +/build +/docs/**/docsets/ +/docs/**/undocumented.json diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..54cbae1 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +education, socio-economic status, nationality, personal appearance, race, +religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at code@bryantluk.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c19320b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,22 @@ +# Contributing + +## License + +By submitting a pull request, you represent that you have the right to license +your contribution to the community, and agree by submitting the patch +that your contributions are licensed under the [Apache-2.0 license][license]. + +## Pull Requests + +Pull requests are the preferred method for contributing to the project. +If there are issues, please open a PR to either make a suggestion or add a +test to reproduce the issue. + +## Security + +If there is a security issue, please email security@bryantluk.com . You can +use this [PGP public key][pgpkey] to encrypt any message +if desired. + +[license]: LICENSE +[pgpkey]: https://bryantluk.com/gpg.key diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f66e383 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# ⌨️ vim-swift + +A [Swift][swift] plugin for [vim][vim]. + +## License + +[Apache-2.0 License][license] + +[license]: LICENSE +[swift]: https://swift.org +[vim]: https://www.vim.org diff --git a/ftdetect/sil.vim b/ftdetect/sil.vim new file mode 100644 index 0000000..0515f35 --- /dev/null +++ b/ftdetect/sil.vim @@ -0,0 +1,12 @@ +" This source file was originally part of the Swift.org open source project +" +" Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +" Licensed under Apache License v2.0 with Runtime Library Exception +" +" See https://swift.org/LICENSE.txt for license information +" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project +" authors +" +" Original file: +" https://github.com/apple/swift/blob/d128dad3ff1ca24f7a7ca4f0c6c8203b3b87982c/utils/vim/ftdetect/sil.vim +autocmd BufNewFile,BufRead *.sil set filetype=sil diff --git a/ftdetect/swift.vim b/ftdetect/swift.vim new file mode 100644 index 0000000..06b123f --- /dev/null +++ b/ftdetect/swift.vim @@ -0,0 +1,12 @@ +" This source file was originally part of the Swift.org open source project +" +" Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +" Licensed under Apache License v2.0 with Runtime Library Exception +" +" See https://swift.org/LICENSE.txt for license information +" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project +" authors +" +" Original file: +" https://github.com/apple/swift/blob/11874988289e2afb443a156dae45aedb3f5fd1b7/utils/vim/ftdetect/swift.vim +autocmd BufNewFile,BufRead *.swift set filetype=swift diff --git a/ftdetect/swiftgyb.vim b/ftdetect/swiftgyb.vim new file mode 100644 index 0000000..4b5de31 --- /dev/null +++ b/ftdetect/swiftgyb.vim @@ -0,0 +1,12 @@ +" This source file was originally part of the Swift.org open source project +" +" Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +" Licensed under Apache License v2.0 with Runtime Library Exception +" +" See https://swift.org/LICENSE.txt for license information +" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project +" authors +" +" Original file: +" https://github.com/apple/swift/blob/6044c97318f768a3971198545e8b6e7e6dd80d0c/utils/vim/ftdetect/swiftgyb.vim +autocmd BufNewFile,BufRead *.swift.gyb set filetype=swiftgyb diff --git a/ftplugin/swift.vim b/ftplugin/swift.vim new file mode 100644 index 0000000..755d364 --- /dev/null +++ b/ftplugin/swift.vim @@ -0,0 +1,5 @@ +setlocal comments=s1:/*,mb:*,ex:*/,:///,:// +setlocal smartindent +setlocal expandtab +setlocal ts=4 +setlocal sw=4 diff --git a/syntax/sil.vim b/syntax/sil.vim new file mode 100644 index 0000000..53b043a --- /dev/null +++ b/syntax/sil.vim @@ -0,0 +1,172 @@ +" Vim syntax file +" Language: sil +" +" This source file was originally part of the Swift.org open source project +" +" Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +" Licensed under Apache License v2.0 with Runtime Library Exception +" +" See https://swift.org/LICENSE.txt for license information +" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project +" authors +" +" Original file: +" https://github.com/apple/swift/blob/73df12c09f052f34985b62834f8f0fd2de4c8f10/utils/vim/syntax/sil.vim + +if exists("b:current_syntax") + finish +endif + +syn keyword silStage skipwhite nextgroup=silStages + \ sil_stage +syn keyword silStages + \ canonical + \ raw + +syn match silIdentifier skipwhite + \ /@\<[A-Za-z_0-9]\+\>/ + +syn match silConvention skipwhite + \ /$\?@convention/ +syn region silConvention contained contains=silConventions + \ start="@convention(" end=")" +syn keyword silConventions + \ block + \ c + \ method + \ objc_method + \ thick + \ thin + \ witness_method + +syn match silFunctionType skipwhite + \ /@\(\\|\\|\\|\\|\\|\\|\\|\\|\\|\\|\\|\\|\\)/ +syn match silMetatypeType skipwhite + \ /@\(\\|\\|\\)/ + +" TODO: handle [tail_elems sil-type * sil-operand] +syn region silAttribute contains=silAttributes + \ start="\[" end="\]" +syn keyword silAttributes contained containedin=silAttribute + \ abort + \ deinit + \ delegatingself + \ derivedself + \ derivedselfonly + \ dynamic + \ exact + \ init + \ modify + \ objc + \ read + \ rootself + \ stack + \ static + \ strict + \ unknown + \ unsafe + \ var + +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 region swiftComment start="/\*" end="\*/" contains=swiftComment,swiftLineComment,swiftTodo +syn region swiftLineComment start="//" end="$" contains=swiftComment,swiftTodo + +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_global alloc_stack alloc_ref alloc_ref_dynamic alloc_box alloc_existential_box alloc_value_buffer dealloc_stack dealloc_box dealloc_existential_box dealloc_ref dealloc_partial_ref dealloc_value_buffer skipwhite +syn keyword swiftKeyword debug_value debug_value_addr skipwhite +syn keyword swiftKeyword load load_unowned store assign mark_uninitialized mark_function_escape copy_addr destroy_addr index_addr index_raw_pointer bind_memory to skipwhite +syn keyword swiftKeyword strong_retain strong_release strong_retain_unowned ref_to_unowned unowned_to_ref unowned_retain unowned_release load_weak store_unowned store_weak fix_lifetime autorelease_value set_deallocating is_unique is_escaping_closure skipwhite +syn keyword swiftKeyword function_ref integer_literal float_literal string_literal global_addr skipwhite +syn keyword swiftKeyword class_method super_method witness_method objc_method objc_super_method skipwhite +syn keyword swiftKeyword partial_apply builtin skipwhite +syn keyword swiftApplyKeyword apply try_apply skipwhite +syn keyword swiftKeyword metatype value_metatype existential_metatype skipwhite +syn keyword swiftKeyword retain_value release_value retain_value_addr release_value_addr 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 init_existential_value init_existential_metatype deinit_existential_addr deinit_existential_value open_existential_addr open_existential_box open_existential_box_value open_existential_metatype init_existential_ref open_existential_ref open_existential_value skipwhite +syn keyword swiftKeyword upcast address_to_pointer pointer_to_address pointer_to_thin_function unchecked_addr_cast unchecked_ref_cast unchecked_ref_cast_addr ref_to_raw_pointer ref_to_bridge_object ref_to_unmanaged unmanaged_to_ref raw_pointer_to_ref skipwhite +syn keyword swiftKeyword convert_function thick_to_objc_metatype thin_function_to_pointer objc_to_thick_metatype thin_to_thick_function unchecked_ref_bit_cast unchecked_trivial_bit_cast bridge_object_to_ref bridge_object_to_word unchecked_bitwise_cast skipwhite +syn keyword swiftKeyword objc_existential_metatype_to_object objc_metatype_to_object objc_protocol skipwhite +syn keyword swiftKeyword unconditional_checked_cast unconditional_checked_cast_addr unconditional_checked_cast_value skipwhite +syn keyword swiftKeyword cond_fail skipwhite +syn keyword swiftKeyword unreachable return throw br cond_br switch_value select_enum select_enum_addr select_value switch_enum switch_enum_addr dynamic_method_br checked_cast_br checked_cast_value_br checked_cast_addr_br skipwhite +syn keyword swiftKeyword project_box project_existential_box project_value_buffer project_block_storage init_block_storage_header copy_block mark_dependence 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 swiftApplyKeyword Statement +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 silStage Special +hi def link silStages Type +hi def link silConvention Special +hi def link silConventionParameter Special +hi def link silConventions Type +hi def link silIdentifier Identifier +hi def link silFunctionType Special +hi def link silMetatypeType Special +hi def link silAttribute PreProc + +let b:current_syntax = "sil" diff --git a/syntax/swift.vim b/syntax/swift.vim new file mode 100644 index 0000000..99a7a82 --- /dev/null +++ b/syntax/swift.vim @@ -0,0 +1,241 @@ +" Vim syntax file +" Language: swift + +" This source file was originally part of the Swift.org open source project +" +" Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +" Licensed under Apache License v2.0 with Runtime Library Exception +" +" See https://swift.org/LICENSE.txt for license information +" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project +" authors +" +" Original file: +" https://github.com/apple/swift/blob/ea2c860ddb4817dc83c7152035aa05569f3a2770/utils/vim/syntax/swift.vim + +if exists("b:current_syntax") + finish +endif + +syn keyword swiftKeyword + \ associatedtype + \ break + \ catch + \ continue + \ defer + \ do + \ else + \ fallthrough + \ for + \ guard + \ if + \ in + \ repeat + \ return + \ switch + \ throw + \ try + \ where + \ while +syn match swiftMultiwordKeyword + \ "indirect case" + +syn keyword swiftImport skipwhite skipempty nextgroup=swiftImportModule + \ import + +syn keyword swiftDefinitionModifier + \ convenience + \ dynamic + \ fileprivate + \ final + \ internal + \ nonmutating + \ open + \ override + \ private + \ public + \ required + \ rethrows + \ static + \ throws + \ weak + +syn keyword swiftInOutKeyword skipwhite skipempty nextgroup=swiftTypeName + \ inout + +syn keyword swiftIdentifierKeyword + \ Self + \ metatype + \ self + \ super + +syn keyword swiftFuncKeywordGeneral skipwhite skipempty nextgroup=swiftTypeParameters + \ init + +syn keyword swiftFuncKeyword + \ deinit + \ subscript + +syn keyword swiftScope + \ autoreleasepool + +syn keyword swiftMutating skipwhite skipempty nextgroup=swiftFuncDefinition + \ mutating +syn keyword swiftFuncDefinition skipwhite skipempty nextgroup=swiftTypeName,swiftOperator + \ func + +syn keyword swiftTypeDefinition skipwhite skipempty nextgroup=swiftTypeName + \ class + \ enum + \ extension + \ protocol + \ struct + \ typealias + +syn match swiftMultiwordTypeDefinition skipwhite skipempty nextgroup=swiftTypeName + \ "indirect enum" + +syn keyword swiftVarDefinition skipwhite skipempty nextgroup=swiftVarName + \ let + \ var + +syn keyword swiftLabel + \ get + \ set + \ didSet + \ willSet + +syn keyword swiftBoolean + \ false + \ true + +syn keyword swiftNil + \ nil + +syn match swiftImportModule contained nextgroup=swiftImportComponent + \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ +syn match swiftImportComponent contained nextgroup=swiftImportComponent + \ /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ + +syn match swiftTypeName contained skipwhite skipempty nextgroup=swiftTypeParameters + \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>/ +syn match swiftVarName contained skipwhite skipempty nextgroup=swiftTypeDeclaration + \ /\<[A-Za-z_][A-Za-z_0-9]*\>/ +syn match swiftImplicitVarName + \ /\$\<[A-Za-z_0-9]\+\>/ + +" TypeName[Optionality]? +syn match swiftType contained skipwhite skipempty nextgroup=swiftTypeParameters + \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/ +" [Type:Type] (dictionary) or [Type] (array) +syn region swiftType contained contains=swiftTypePair,swiftType + \ matchgroup=Delimiter start=/\[/ end=/\]/ +syn match swiftTypePair contained skipwhite skipempty nextgroup=swiftTypeParameters,swiftTypeDeclaration + \ /\<[A-Za-z_][A-Za-z_0-9\.]*\>[!?]\?/ +" (Type[, Type]) (tuple) +" FIXME: we should be able to use skip="," and drop swiftParamDelim +syn region swiftType contained contains=swiftType,swiftParamDelim + \ matchgroup=Delimiter start="[^@]\?(" end=")" matchgroup=NONE skip="," +syn match swiftParamDelim contained + \ /,/ +" (generics) +syn region swiftTypeParameters contained contains=swiftVarName,swiftConstraint + \ matchgroup=Delimiter start="<" end=">" matchgroup=NONE skip="," +syn keyword swiftConstraint contained + \ where + +syn match swiftTypeDeclaration skipwhite skipempty nextgroup=swiftType,swiftInOutKeyword + \ /:/ +syn match swiftTypeDeclaration skipwhite skipempty nextgroup=swiftType + \ /->/ + +syn match swiftKeyword + \ /\/ +syn region swiftCaseLabelRegion + \ matchgroup=swiftKeyword start=/\/ matchgroup=Delimiter end=/:/ oneline contains=TOP +syn region swiftDefaultLabelRegion + \ matchgroup=swiftKeyword start=/\/ matchgroup=Delimiter end=/:/ + +syn region swiftParenthesisRegion matchgroup=NONE start=/(/ end=/)/ contains=TOP + +syn region swiftString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=swiftInterpolationRegion +syn region swiftInterpolationRegion matchgroup=swiftInterpolation start=/\\(/ end=/)/ contained contains=TOP +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 skipempty nextgroup=swiftTypeParameters +syn match swiftOperator "\.\.[<.]" skipwhite skipempty 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 swiftTupleIndexNumber contains=swiftDecimal + \ /\.[0-9]\+/ +syn match swiftDecimal contained + \ /[0-9]\+/ + +syn match swiftPreproc /#\(\\|\\|\\)/ +syn match swiftPreproc /^\s*#\(\\|\\|\\|\\|\\|\\)/ +syn region swiftPreprocFalse start="^\s*#\\s\+\" end="^\s*#\(\\|\\|\\)" + +syn match swiftAttribute /@\<\w\+\>/ skipwhite skipempty nextgroup=swiftType + +syn keyword swiftTodo MARK TODO FIXME contained + +syn match swiftCastOp "\" skipwhite skipempty nextgroup=swiftType +syn match swiftCastOp "\[!?]\?" skipwhite skipempty nextgroup=swiftType + +syn match swiftNilOps "??" + +syn region swiftReservedIdentifier oneline + \ start=/`/ end=/`/ + +hi def link swiftImport Include +hi def link swiftImportModule Title +hi def link swiftImportComponent Identifier +hi def link swiftKeyword Statement +hi def link swiftMultiwordKeyword Statement +hi def link swiftTypeDefinition Define +hi def link swiftMultiwordTypeDefinition Define +hi def link swiftType Type +hi def link swiftTypePair Type +hi def link swiftTypeName Function +hi def link swiftConstraint Special +hi def link swiftFuncDefinition Define +hi def link swiftDefinitionModifier Define +hi def link swiftInOutKeyword Define +hi def link swiftFuncKeyword Function +hi def link swiftFuncKeywordGeneral 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 swiftTypeParameters 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 Operator +hi def link swiftMutating Statement +hi def link swiftPreproc PreCondit +hi def link swiftPreprocFalse Comment +hi def link swiftAttribute Type +hi def link swiftTodo Todo +hi def link swiftNil Constant +hi def link swiftCastOp Operator +hi def link swiftNilOps Operator +hi def link swiftScope PreProc + +let b:current_syntax = "swift" diff --git a/syntax/swiftgyb.vim b/syntax/swiftgyb.vim new file mode 100644 index 0000000..6ef9618 --- /dev/null +++ b/syntax/swiftgyb.vim @@ -0,0 +1,25 @@ +" Vim syntax file +" Language: gyb on swift + +" This source file was originally part of the Swift.org open source project +" +" Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +" Licensed under Apache License v2.0 with Runtime Library Exception +" +" See https://swift.org/LICENSE.txt for license information +" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project +" authors +" +" Original file: +" https://github.com/apple/swift/blob/6044c97318f768a3971198545e8b6e7e6dd80d0c/utils/vim/syntax/swiftgyb.vim + +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"