├── .github └── workflows │ └── nodejs.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── NOTICE ├── README.md ├── dist ├── Kotlin.JSON-tmLanguage ├── Kotlin.YAML-tmLanguage └── Kotlin.tmLanguage ├── package-lock.json ├── package.json ├── scripts ├── build.js ├── coverage.js ├── format.js └── util.js ├── snapshots ├── corpus.kt └── corpus.kt.snap ├── src ├── annotations.YAML-tmLanguage ├── classes.YAML-tmLanguage ├── comments.YAML-tmLanguage ├── functions.YAML-tmLanguage ├── generic.YAML-tmLanguage ├── ident.YAML-tmLanguage ├── imports.YAML-tmLanguage ├── index.YAML-tmLanguage ├── keywords.YAML-tmLanguage ├── literals.YAML-tmLanguage ├── objects.YAML-tmLanguage ├── package.YAML-tmLanguage └── types.YAML-tmLanguage └── test ├── ClassDeclaration.test.kt ├── Comments.test.kt ├── Functions.test.kt ├── Generic.test.kt ├── Imports.test.kt ├── Keywords.test.kt ├── Objects.test.kt ├── Package.test.kt ├── Types.test.kt ├── VariableDeclaration.test.kt ├── annotations.test.kt ├── literals.test.kt └── regression ├── 12.test.kt ├── 15.test.kt ├── 19.test.kt ├── 20.test.kt ├── 21.test.kt ├── 23.test.kt ├── 26.test.kt ├── 4.test.kt ├── 42.test.kt ├── 44.test.kt ├── 47.test.kt ├── 50.test.kt ├── 57.test.kt ├── 59.test.kt ├── 63.test.kt ├── 67.test.kt └── 71.test.kt /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [master, develop] 9 | pull_request: 10 | branches: [master, develop] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | node-version: [18.x] 18 | steps: 19 | - uses: actions/checkout@v4 20 | - uses: actions/setup-python@v2 21 | with: 22 | python-version: "3.x" 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm ci 28 | - run: npm run build --if-present 29 | - run: npm test 30 | - run: npm run coverage 31 | - name: Upload to Codecov 32 | uses: codecov/codecov-action@v4 33 | with: 34 | token: ${{ secrets.CODECOV_TOKEN }} 35 | fail_ci_if_error: true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /build 3 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.fontLigatures": false, 3 | "files.associations": { 4 | "*.YAML-tmLanguage": "yaml", 5 | "*.JSON-tmLanguage": "json" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ### Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ### Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ### Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ### Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ### Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at nishtahir at outlook dot com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ### Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Nish Tahir 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | NOTICE file corresponding to the section 4 d of the Apache License, Version 2.0 2 | 3 | This product includes software developed as part of: 4 | Kotlin Sublime Text 2 Package (https://github.com/vkostyukov/kotlin-sublime-package). 5 | 6 | This product includes software developed as part of: 7 | VSCode Kotlin project (https://github.com/mathiasfrohlich/vscode-kotlin). 8 | 9 | Copyright for portions of project `language-kotlin` are held by 10 | 11 | 1. Vladimir Kostyukov, 2017 as part of project `vkostyukov/kotlin-sublime-package` 12 | 2. Mathias Frøhlich, 2018 as part of project `mathiasfrohlich/vscode-kotlin` 13 | 14 | All other copyright for project `language-kotlin` are held by Nish Tahir 2018. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Language Kotlin 2 | 3 | A textmate compatible grammar for the Kotlin language. 4 | 5 | ![Node.js CI](https://github.com/nishtahir/language-kotlin/workflows/Node.js%20CI/badge.svg?branch=master) 6 | [![codecov](https://codecov.io/gh/nishtahir/language-kotlin/branch/master/graph/badge.svg)](https://codecov.io/gh/nishtahir/language-kotlin) 7 | 8 | ## Setup 9 | 10 | This project is built using a couple of handy node scripts. Begin by installing the 11 | required dependencies. 12 | 13 | ``` 14 | $ npm install 15 | ``` 16 | 17 | ## Build 18 | 19 | Changes to the grammar should be made in the `src` folder. These are merged at build 20 | time and used to produce the final artifact. 21 | 22 | Once you are satisfied with your changes, you will need to generate 23 | `xml` and `json` variants for distribution. 24 | There's a handy build script available to automate this process. 25 | 26 | ``` 27 | $ npm run build 28 | ``` 29 | 30 | This will outputs the merged sources to the `dist` directory. At this point 31 | it's highly recommended that you test your changes using [GitHub Lightshow](https://github-lightshow.herokuapp.com/). There's some manual work involved in doing this however this is the closest 32 | representation of what it would look like when it is deployed that is available at this time. 33 | 34 | You can format your sources using the code formatting script. 35 | 36 | ``` 37 | $ npm run format 38 | ``` 39 | 40 | ## Testing 41 | 42 | > All changes to the grammar must be accompanied by tests covering relevant scopes. 43 | 44 | Tests are run using [`vscode-tmgrammar-test`](https://github.com/PanAeon/vscode-tmgrammar-test). 45 | Test cases and regression tests are available in the `/test` folder. 46 | 47 | Generated snapshots are available in the `/snapshots` folder and should be updated with changes 48 | to the grammar. 49 | 50 | The test suite can be run using `npm` 51 | 52 | ``` 53 | $ npm test 54 | ``` 55 | 56 | ## Useful resources 57 | 58 | - [NovaLightshow](https://novalightshow.netlify.app/) - Useful for testing Grammar sources against Code to inspect the highlighting behavior. Thanks to [Nixinova](https://github.com/Nixinova/NovaLightshow) 59 | - [Sublime Text scope naming reference](https://www.sublimetext.com/docs/3/scope_naming.html) - Reference on Textmate scope naming 60 | 61 | ## Code of Conduct 62 | 63 | Please note we have a [code of conduct](./CODE_OF_CONDUCT.md) which _must_ be observed in interactions with the project. 64 | -------------------------------------------------------------------------------- /dist/Kotlin.JSON-tmLanguage: -------------------------------------------------------------------------------- 1 | { 2 | "repository": { 3 | "annotations": { 4 | "patterns": [ 5 | { 6 | "comment": "Use-site annotation", 7 | "match": "@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:\\s*?[a-zA-Z_]\\w*", 8 | "name": "meta.annotation.kotlin" 9 | }, 10 | { 11 | "begin": "@[a-zA-Z_]\\w*\\s*(\\()", 12 | "beginCaptures": { 13 | "1": { 14 | "name": "punctuation.definition.arguments.begin.kotlin" 15 | } 16 | }, 17 | "end": "\\)", 18 | "endCaptures": { 19 | "0": { 20 | "name": "punctuation.definition.arguments.end.kotlin" 21 | } 22 | }, 23 | "name": "meta.annotation.kotlin", 24 | "patterns": [ 25 | { 26 | "include": "#code" 27 | }, 28 | { 29 | "match": ",", 30 | "name": "punctuation.seperator.property.kotlin" 31 | } 32 | ] 33 | }, 34 | { 35 | "match": "@[a-zA-Z_]\\w*", 36 | "name": "meta.annotation.kotlin" 37 | } 38 | ] 39 | }, 40 | "class-literal": { 41 | "patterns": [ 42 | { 43 | "begin": "(?=\\b(?:(?:(?:data|value)\\s+)?class|(?:data\\s+)?object|(?:(?:fun|value)\\s+)?interface)\\s+\\w+)\\b", 44 | "end": "(?=\\}|$)", 45 | "name": "meta.class.kotlin", 46 | "patterns": [ 47 | { 48 | "include": "#keywords" 49 | }, 50 | { 51 | "begin": "\\b((?:(?:data|value)\\s+)?class|(?:data\\s+)?object|(?:(?:fun|value)\\s+)?interface)\\b\\s+(\\w+)", 52 | "beginCaptures": { 53 | "1": { 54 | "name": "storage.modifier.kotlin" 55 | }, 56 | "2": { 57 | "name": "entity.name.class.kotlin" 58 | } 59 | }, 60 | "end": "(?=\\(|\\{|$)", 61 | "patterns": [ 62 | { 63 | "include": "#comments" 64 | }, 65 | { 66 | "include": "#annotations" 67 | }, 68 | { 69 | "include": "#types" 70 | } 71 | ] 72 | }, 73 | { 74 | "begin": "(\\()", 75 | "beginCaptures": { 76 | "0": { 77 | "name": "punctuation.section.group.begin.kotlin" 78 | }, 79 | "1": { 80 | "name": "punctuation.definition.parameters.begin.kotlin" 81 | } 82 | }, 83 | "end": "(\\))", 84 | "endCaptures": { 85 | "0": { 86 | "name": "punctuation.section.group.end.kotlin" 87 | }, 88 | "1": { 89 | "name": "punctuation.definition.parameters.end.kotlin" 90 | } 91 | }, 92 | "name": "meta.parameters.kotlin", 93 | "patterns": [ 94 | { 95 | "include": "#class-parameter-list" 96 | }, 97 | { 98 | "include": "#comments" 99 | } 100 | ] 101 | }, 102 | { 103 | "begin": "\\{", 104 | "beginCaptures": { 105 | "0": { 106 | "name": "punctuation.section.group.begin.kotlin" 107 | } 108 | }, 109 | "end": "\\}", 110 | "endCaptures": { 111 | "0": { 112 | "name": "punctuation.section.group.end.kotlin" 113 | } 114 | }, 115 | "name": "meta.block.kotlin", 116 | "patterns": [ 117 | { 118 | "include": "#code" 119 | } 120 | ] 121 | } 122 | ] 123 | } 124 | ], 125 | "repository": { 126 | "class-parameter-list": { 127 | "patterns": [ 128 | { 129 | "include": "#generic" 130 | }, 131 | { 132 | "include": "#annotations" 133 | }, 134 | { 135 | "include": "#keywords" 136 | }, 137 | { 138 | "match": "(\\w+)\\s*(:)", 139 | "captures": { 140 | "1": { 141 | "name": "variable.parameter.function.kotlin" 142 | }, 143 | "2": { 144 | "name": "keyword.operator.declaration.kotlin" 145 | } 146 | } 147 | }, 148 | { 149 | "match": ",", 150 | "name": "punctuation.seperator.kotlin" 151 | }, 152 | { 153 | "include": "#types" 154 | }, 155 | { 156 | "include": "#literals" 157 | } 158 | ] 159 | } 160 | } 161 | }, 162 | "comments": { 163 | "patterns": [ 164 | { 165 | "include": "#inline" 166 | }, 167 | { 168 | "begin": "/\\*", 169 | "beginCaptures": { 170 | "0": { 171 | "name": "punctuation.definition.comment.begin.kotlin" 172 | } 173 | }, 174 | "end": "\\*/", 175 | "endCaptures": { 176 | "0": { 177 | "name": "punctuation.definition.comment.end.kotlin" 178 | } 179 | }, 180 | "name": "comment.block.kotlin", 181 | "patterns": [ 182 | { 183 | "include": "#nested" 184 | } 185 | ] 186 | } 187 | ], 188 | "repository": { 189 | "inline": { 190 | "patterns": [ 191 | { 192 | "match": "(//).*$\\n?", 193 | "captures": { 194 | "0": { 195 | "name": "punctuation.definition.comment.kotlin" 196 | }, 197 | "1": { 198 | "name": "comment.line.double-slash.kotlin" 199 | } 200 | } 201 | } 202 | ] 203 | }, 204 | "nested": { 205 | "patterns": [ 206 | { 207 | "begin": "/\\*", 208 | "end": "\\*/", 209 | "patterns": [ 210 | { 211 | "include": "#nested" 212 | } 213 | ] 214 | } 215 | ] 216 | } 217 | } 218 | }, 219 | "builtin-functions": { 220 | "patterns": [ 221 | { 222 | "match": "\\b(apply|also|let|run|takeIf|takeWhile|takeUnless|with|print|println)\\b\\s*(?={|\\()", 223 | "captures": { 224 | "1": { 225 | "name": "support.function.kotlin" 226 | } 227 | } 228 | }, 229 | { 230 | "match": "\\b(arrayListOf|mutableListOf|listOf|mutableMapOf|mapOf|mutableSetOf|setOf)\\b\\s*(?={|\\()", 231 | "captures": { 232 | "1": { 233 | "name": "support.function.kotlin" 234 | } 235 | } 236 | } 237 | ] 238 | }, 239 | "literal-functions": { 240 | "patterns": [ 241 | { 242 | "begin": "(?=\\b(?:fun)\\b)", 243 | "end": "(?<=$|=|\\})", 244 | "name": "meta.function.kotlin", 245 | "patterns": [ 246 | { 247 | "include": "#keywords" 248 | }, 249 | { 250 | "begin": "\\bfun\\b", 251 | "beginCaptures": { 252 | "0": { 253 | "name": "keyword.other.kotlin" 254 | } 255 | }, 256 | "end": "(?=\\()", 257 | "patterns": [ 258 | { 259 | "include": "#generic" 260 | }, 261 | { 262 | "match": "(`[^`]*`)", 263 | "comment": "Backtick quoted function names", 264 | "captures": { 265 | "0": { 266 | "name": "entity.name.function.kotlin" 267 | }, 268 | "1": { 269 | "name": "string.quoted.backtick.kotlin" 270 | } 271 | } 272 | }, 273 | { 274 | "match": "([\\.<\\?>\\w]+\\.)?(\\w+)", 275 | "captures": { 276 | "2": { 277 | "name": "entity.name.function.kotlin" 278 | } 279 | } 280 | }, 281 | { 282 | "include": "#types" 283 | } 284 | ] 285 | }, 286 | { 287 | "begin": "(\\()", 288 | "beginCaptures": { 289 | "0": { 290 | "name": "punctuation.section.group.begin.kotlin" 291 | }, 292 | "1": { 293 | "name": "punctuation.definition.parameters.begin.kotlin" 294 | } 295 | }, 296 | "end": "(\\))", 297 | "endCaptures": { 298 | "0": { 299 | "name": "punctuation.section.group.end.kotlin" 300 | }, 301 | "1": { 302 | "name": "punctuation.definition.parameters.end.kotlin" 303 | } 304 | }, 305 | "name": "meta.parameters.kotlin", 306 | "patterns": [ 307 | { 308 | "include": "#function-parameter-list" 309 | } 310 | ] 311 | }, 312 | { 313 | "match": "=", 314 | "name": "keyword.operator.single-expression.kotlin" 315 | }, 316 | { 317 | "begin": "\\{", 318 | "beginCaptures": { 319 | "0": { 320 | "name": "punctuation.section.group.begin.kotlin" 321 | } 322 | }, 323 | "end": "\\}", 324 | "endCaptures": { 325 | "0": { 326 | "name": "punctuation.section.group.end.kotlin" 327 | } 328 | }, 329 | "name": "meta.block.kotlin", 330 | "patterns": [ 331 | { 332 | "include": "#code" 333 | } 334 | ] 335 | }, 336 | { 337 | "include": "#return-type" 338 | } 339 | ] 340 | } 341 | ], 342 | "repository": { 343 | "function-parameter-list": { 344 | "patterns": [ 345 | { 346 | "include": "#comments" 347 | }, 348 | { 349 | "include": "#annotations" 350 | }, 351 | { 352 | "include": "#keywords" 353 | }, 354 | { 355 | "match": "(\\w+)\\s*(:)", 356 | "captures": { 357 | "1": { 358 | "name": "variable.parameter.function.kotlin" 359 | }, 360 | "2": { 361 | "name": "keyword.operator.declaration.kotlin" 362 | } 363 | } 364 | }, 365 | { 366 | "match": ",", 367 | "name": "punctuation.seperator.kotlin" 368 | }, 369 | { 370 | "include": "#types" 371 | } 372 | ] 373 | }, 374 | "return-type": { 375 | "patterns": [ 376 | { 377 | "name": "meta.return.type.kotlin", 378 | "begin": "(?<=\\))\\s*(:)(?=\\s*\\S)", 379 | "end": "(?)(?!\\>)", 395 | "patterns": [ 396 | { 397 | "match": "<", 398 | "name": "punctuation.bracket.angle.begin.kotlin" 399 | }, 400 | { 401 | "match": ">", 402 | "name": "punctuation.bracket.angle.end.kotlin" 403 | }, 404 | { 405 | "match": "\\*", 406 | "name": "entity.name.type.generic.wildcard.kotlin" 407 | }, 408 | { 409 | "include": "#generic-parameter-list" 410 | }, 411 | { 412 | "match": ",", 413 | "name": "punctuation.seperator.kotlin" 414 | } 415 | ] 416 | } 417 | ], 418 | "repository": { 419 | "generic-parameter-list": { 420 | "patterns": [ 421 | { 422 | "include": "#annotations" 423 | }, 424 | { 425 | "match": "\\b(in|out)\\b", 426 | "name": "storage.modifier.generic.variance.kotlin" 427 | }, 428 | { 429 | "include": "#built-in-types" 430 | }, 431 | { 432 | "include": "#class-ident" 433 | }, 434 | { 435 | "include": "#generic" 436 | }, 437 | { 438 | "include": "#operators" 439 | } 440 | ] 441 | } 442 | } 443 | }, 444 | "class-ident": { 445 | "patterns": [ 446 | { 447 | "match": "\\b[A-Z_]\\w*\\b", 448 | "name": "entity.name.type.class.kotlin", 449 | "comment": "Classes generally start with an Uppercase Char" 450 | } 451 | ] 452 | }, 453 | "imports": { 454 | "patterns": [ 455 | { 456 | "match": "^\\s*(import)\\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\\s+(as)\\s+([`][^$`]+[`]|[^` $.]+))?", 457 | "captures": { 458 | "1": { 459 | "name": "keyword.other.import.kotlin" 460 | }, 461 | "2": { 462 | "name": "storage.modifier.import.kotlin" 463 | }, 464 | "3": { 465 | "name": "keyword.other.kotlin" 466 | }, 467 | "4": { 468 | "name": "entity.name.type" 469 | } 470 | }, 471 | "name": "meta.import.kotlin" 472 | } 473 | ] 474 | }, 475 | "parens": { 476 | "patterns": [ 477 | { 478 | "begin": "\\(", 479 | "beginCaptures": { 480 | "0": { 481 | "name": "punctuation.section.group.begin.kotlin" 482 | } 483 | }, 484 | "end": "\\)", 485 | "endCaptures": { 486 | "0": { 487 | "name": "punctuation.section.group.end.kotlin" 488 | } 489 | }, 490 | "name": "meta.group.kotlin", 491 | "patterns": [ 492 | { 493 | "include": "#code" 494 | } 495 | ] 496 | } 497 | ] 498 | }, 499 | "braces": { 500 | "patterns": [ 501 | { 502 | "begin": "\\{", 503 | "beginCaptures": { 504 | "0": { 505 | "name": "punctuation.section.group.begin.kotlin" 506 | } 507 | }, 508 | "end": "\\}", 509 | "endCaptures": { 510 | "0": { 511 | "name": "punctuation.section.group.end.kotlin" 512 | } 513 | }, 514 | "name": "meta.block.kotlin", 515 | "patterns": [ 516 | { 517 | "include": "#code" 518 | } 519 | ] 520 | } 521 | ] 522 | }, 523 | "brackets": { 524 | "patterns": [ 525 | { 526 | "begin": "\\[", 527 | "beginCaptures": { 528 | "0": { 529 | "name": "punctuation.section.brackets.begin.kotlin" 530 | } 531 | }, 532 | "end": "\\]", 533 | "endCaptures": { 534 | "0": { 535 | "name": "punctuation.section.brackets.end.kotlin" 536 | } 537 | }, 538 | "name": "meta.brackets.kotlin", 539 | "patterns": [ 540 | { 541 | "include": "#code" 542 | } 543 | ] 544 | } 545 | ] 546 | }, 547 | "code": { 548 | "patterns": [ 549 | { 550 | "include": "#comments" 551 | }, 552 | { 553 | "include": "#annotations" 554 | }, 555 | { 556 | "include": "#parens" 557 | }, 558 | { 559 | "include": "#braces" 560 | }, 561 | { 562 | "include": "#brackets" 563 | }, 564 | { 565 | "include": "#class-literal" 566 | }, 567 | { 568 | "include": "#literal-functions" 569 | }, 570 | { 571 | "include": "#literals" 572 | }, 573 | { 574 | "include": "#keywords" 575 | }, 576 | { 577 | "include": "#types" 578 | }, 579 | { 580 | "include": "#operators" 581 | }, 582 | { 583 | "include": "#constants" 584 | }, 585 | { 586 | "include": "#punctuations" 587 | }, 588 | { 589 | "include": "#builtin-functions" 590 | } 591 | ] 592 | }, 593 | "keywords": { 594 | "patterns": [ 595 | { 596 | "match": "(\\!in|\\!is|as\\?)\\b", 597 | "name": "keyword.operator.kotlin" 598 | }, 599 | { 600 | "match": "\\b(in|is|as|assert)\\b", 601 | "name": "keyword.operator.kotlin" 602 | }, 603 | { 604 | "match": "\\b(val|var)\\b", 605 | "name": "storage.type.kotlin" 606 | }, 607 | { 608 | "match": "\\b(\\_)\\b", 609 | "name": "punctuation.definition.variable.kotlin" 610 | }, 611 | { 612 | "match": "\\b(tailrec|operator|infix|typealias|reified|copy(?=\\s+fun|\\s+var))\\b", 613 | "name": "storage.type.kotlin" 614 | }, 615 | { 616 | "match": "\\b(out|in|yield|typealias|override)\\b", 617 | "name": "storage.modifier.kotlin" 618 | }, 619 | { 620 | "match": "\\b(?=|<|>)", 664 | "name": "keyword.operator.comparison.kotlin" 665 | }, 666 | { 667 | "match": "(=)", 668 | "name": "keyword.operator.assignment.kotlin" 669 | }, 670 | { 671 | "match": "(:(?!:))", 672 | "name": "keyword.operator.declaration.kotlin" 673 | }, 674 | { 675 | "match": "(\\?:)", 676 | "name": "keyword.operator.elvis.kotlin" 677 | }, 678 | { 679 | "match": "(\\-\\-|\\+\\+)", 680 | "name": "keyword.operator.increment-decrement.kotlin" 681 | }, 682 | { 683 | "match": "(\\-|\\+|\\*|\\/|%)", 684 | "name": "keyword.operator.arithmetic.kotlin" 685 | }, 686 | { 687 | "match": "(\\+\\=|\\-\\=|\\*\\=|\\/\\=)", 688 | "name": "keyword.operator.arithmetic.assign.kotlin" 689 | }, 690 | { 691 | "match": "(\\!|\\&\\&|\\|\\|)", 692 | "name": "keyword.operator.logical.kotlin" 693 | }, 694 | { 695 | "match": "(\\.\\.)", 696 | "name": "keyword.operator.range.kotlin" 697 | } 698 | ] 699 | }, 700 | "constants": { 701 | "patterns": [ 702 | { 703 | "match": "\\b(class)\\b", 704 | "name": "constant.language.kotlin" 705 | }, 706 | { 707 | "match": "\\b(this|super)\\b", 708 | "name": "variable.language.kotlin" 709 | } 710 | ] 711 | }, 712 | "punctuations": { 713 | "patterns": [ 714 | { 715 | "match": "::", 716 | "name": "punctuation.accessor.reference.kotlin" 717 | }, 718 | { 719 | "match": "\\?\\.", 720 | "name": "punctuation.accessor.dot.safe.kotlin" 721 | }, 722 | { 723 | "match": "(?&|\\^~.])(->)(?![/=\\-+!*%<>&|\\^~.])", 1067 | "captures": { 1068 | "1": { 1069 | "name": "keyword.operator.type.function.kotlin" 1070 | } 1071 | } 1072 | }, 1073 | { 1074 | "match": "\\?(?!\\.)", 1075 | "name": "keyword.operator.type.nullable.kotlin" 1076 | }, 1077 | { 1078 | "begin": "\\(", 1079 | "beginCaptures": { 1080 | "0": { 1081 | "name": "punctuation.section.group.begin.kotlin" 1082 | } 1083 | }, 1084 | "end": "\\)", 1085 | "endCaptures": { 1086 | "0": { 1087 | "name": "punctuation.section.group.end.kotlin" 1088 | } 1089 | }, 1090 | "patterns": [ 1091 | { 1092 | "include": "#types" 1093 | } 1094 | ] 1095 | } 1096 | ], 1097 | "repository": { 1098 | "built-in-types": { 1099 | "patterns": [ 1100 | { 1101 | "match": "\\b(Nothing|Any|Unit|String|CharSequence|Int|Boolean|Char|Long|Double|Float|Short|Byte|UByte|UShort|UInt|ULong|Array|List|Map|Set|dynamic)\\b(\\?)?", 1102 | "name": "support.class.kotlin" 1103 | }, 1104 | { 1105 | "match": "\\b(IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray|UByteArray|UShortArray|UIntArray|ULongArray)\\b(\\?)?", 1106 | "name": "support.class.kotlin" 1107 | } 1108 | ] 1109 | } 1110 | } 1111 | } 1112 | }, 1113 | "fileTypes": [ 1114 | "kt", 1115 | "kts" 1116 | ], 1117 | "foldingStartMarker": "(\\{\\s*(//.*)?$|^\\s*// \\{\\{\\{)", 1118 | "foldingStopMarker": "^\\s*(\\}|// \\}\\}\\}$)", 1119 | "name": "Kotlin", 1120 | "patterns": [ 1121 | { 1122 | "include": "#comments" 1123 | }, 1124 | { 1125 | "include": "#package" 1126 | }, 1127 | { 1128 | "include": "#imports" 1129 | }, 1130 | { 1131 | "include": "#code" 1132 | } 1133 | ], 1134 | "scopeName": "source.kotlin", 1135 | "uuid": "d9380650-5edc-447d-8dbd-98838c7d0adf" 1136 | } -------------------------------------------------------------------------------- /dist/Kotlin.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | annotations: 3 | patterns: 4 | - 5 | comment: 'Use-site annotation' 6 | match: '@(?:file|property|field|get|set|receiver|param|setparam|delegate)\s*:\s*?[a-zA-Z_]\w*' 7 | name: meta.annotation.kotlin 8 | - 9 | begin: '@[a-zA-Z_]\w*\s*(\()' 10 | beginCaptures: 11 | '1': {name: punctuation.definition.arguments.begin.kotlin} 12 | end: \) 13 | endCaptures: 14 | '0': {name: punctuation.definition.arguments.end.kotlin} 15 | name: meta.annotation.kotlin 16 | patterns: 17 | - {include: '#code'} 18 | - {match: ',', name: punctuation.seperator.property.kotlin} 19 | - 20 | match: '@[a-zA-Z_]\w*' 21 | name: meta.annotation.kotlin 22 | class-literal: 23 | patterns: 24 | - 25 | begin: '(?=\b(?:(?:(?:data|value)\s+)?class|(?:data\s+)?object|(?:(?:fun|value)\s+)?interface)\s+\w+)\b' 26 | end: '(?=\}|$)' 27 | name: meta.class.kotlin 28 | patterns: 29 | - {include: '#keywords'} 30 | - {begin: '\b((?:(?:data|value)\s+)?class|(?:data\s+)?object|(?:(?:fun|value)\s+)?interface)\b\s+(\w+)', beginCaptures: {'1': {name: storage.modifier.kotlin}, '2': {name: entity.name.class.kotlin}}, end: '(?=\(|\{|$)', patterns: [{include: '#comments'}, {include: '#annotations'}, {include: '#types'}]} 31 | - {begin: (\(), beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}, '1': {name: punctuation.definition.parameters.begin.kotlin}}, end: (\)), endCaptures: {'0': {name: punctuation.section.group.end.kotlin}, '1': {name: punctuation.definition.parameters.end.kotlin}}, name: meta.parameters.kotlin, patterns: [{include: '#class-parameter-list'}, {include: '#comments'}]} 32 | - {begin: '\{', beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}}, end: '\}', endCaptures: {'0': {name: punctuation.section.group.end.kotlin}}, name: meta.block.kotlin, patterns: [{include: '#code'}]} 33 | repository: 34 | class-parameter-list: 35 | patterns: 36 | - {include: '#generic'} 37 | - {include: '#annotations'} 38 | - {include: '#keywords'} 39 | - {match: '(\w+)\s*(:)', captures: {'1': {name: variable.parameter.function.kotlin}, '2': {name: keyword.operator.declaration.kotlin}}} 40 | - {match: ',', name: punctuation.seperator.kotlin} 41 | - {include: '#types'} 42 | - {include: '#literals'} 43 | comments: 44 | patterns: 45 | - 46 | include: '#inline' 47 | - 48 | begin: '/\*' 49 | beginCaptures: 50 | '0': {name: punctuation.definition.comment.begin.kotlin} 51 | end: '\*/' 52 | endCaptures: 53 | '0': {name: punctuation.definition.comment.end.kotlin} 54 | name: comment.block.kotlin 55 | patterns: 56 | - {include: '#nested'} 57 | repository: 58 | inline: 59 | patterns: 60 | - {match: '(//).*$\n?', captures: {'0': {name: punctuation.definition.comment.kotlin}, '1': {name: comment.line.double-slash.kotlin}}} 61 | nested: 62 | patterns: 63 | - {begin: '/\*', end: '\*/', patterns: [{include: '#nested'}]} 64 | builtin-functions: 65 | patterns: 66 | - 67 | match: '\b(apply|also|let|run|takeIf|takeWhile|takeUnless|with|print|println)\b\s*(?={|\()' 68 | captures: 69 | '1': {name: support.function.kotlin} 70 | - 71 | match: '\b(arrayListOf|mutableListOf|listOf|mutableMapOf|mapOf|mutableSetOf|setOf)\b\s*(?={|\()' 72 | captures: 73 | '1': {name: support.function.kotlin} 74 | literal-functions: 75 | patterns: 76 | - 77 | begin: '(?=\b(?:fun)\b)' 78 | end: '(?<=$|=|\})' 79 | name: meta.function.kotlin 80 | patterns: 81 | - {include: '#keywords'} 82 | - {begin: \bfun\b, beginCaptures: {'0': {name: keyword.other.kotlin}}, end: '(?=\()', patterns: [{include: '#generic'}, {match: '(`[^`]*`)', comment: 'Backtick quoted function names', captures: {'0': {name: entity.name.function.kotlin}, '1': {name: string.quoted.backtick.kotlin}}}, {match: '([\.<\?>\w]+\.)?(\w+)', captures: {'2': {name: entity.name.function.kotlin}}}, {include: '#types'}]} 83 | - {begin: (\(), beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}, '1': {name: punctuation.definition.parameters.begin.kotlin}}, end: (\)), endCaptures: {'0': {name: punctuation.section.group.end.kotlin}, '1': {name: punctuation.definition.parameters.end.kotlin}}, name: meta.parameters.kotlin, patterns: [{include: '#function-parameter-list'}]} 84 | - {match: '=', name: keyword.operator.single-expression.kotlin} 85 | - {begin: '\{', beginCaptures: {'0': {name: punctuation.section.group.begin.kotlin}}, end: '\}', endCaptures: {'0': {name: punctuation.section.group.end.kotlin}}, name: meta.block.kotlin, patterns: [{include: '#code'}]} 86 | - {include: '#return-type'} 87 | repository: 88 | function-parameter-list: 89 | patterns: 90 | - {include: '#comments'} 91 | - {include: '#annotations'} 92 | - {include: '#keywords'} 93 | - {match: '(\w+)\s*(:)', captures: {'1': {name: variable.parameter.function.kotlin}, '2': {name: keyword.operator.declaration.kotlin}}} 94 | - {match: ',', name: punctuation.seperator.kotlin} 95 | - {include: '#types'} 96 | return-type: 97 | patterns: 98 | - {name: meta.return.type.kotlin, begin: '(?<=\))\s*(:)(?=\s*\S)', end: '(?)(?!\>)' 104 | patterns: 105 | - {match: '<', name: punctuation.bracket.angle.begin.kotlin} 106 | - {match: '>', name: punctuation.bracket.angle.end.kotlin} 107 | - {match: '\*', name: entity.name.type.generic.wildcard.kotlin} 108 | - {include: '#generic-parameter-list'} 109 | - {match: ',', name: punctuation.seperator.kotlin} 110 | repository: 111 | generic-parameter-list: 112 | patterns: 113 | - {include: '#annotations'} 114 | - {match: \b(in|out)\b, name: storage.modifier.generic.variance.kotlin} 115 | - {include: '#built-in-types'} 116 | - {include: '#class-ident'} 117 | - {include: '#generic'} 118 | - {include: '#operators'} 119 | class-ident: 120 | patterns: 121 | - 122 | match: '\b[A-Z_]\w*\b' 123 | name: entity.name.type.class.kotlin 124 | comment: 'Classes generally start with an Uppercase Char' 125 | imports: 126 | patterns: 127 | - 128 | match: '^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?' 129 | captures: 130 | '1': {name: keyword.other.import.kotlin} 131 | '2': {name: storage.modifier.import.kotlin} 132 | '3': {name: keyword.other.kotlin} 133 | '4': {name: entity.name.type} 134 | name: meta.import.kotlin 135 | parens: 136 | patterns: 137 | - 138 | begin: \( 139 | beginCaptures: 140 | '0': {name: punctuation.section.group.begin.kotlin} 141 | end: \) 142 | endCaptures: 143 | '0': {name: punctuation.section.group.end.kotlin} 144 | name: meta.group.kotlin 145 | patterns: 146 | - {include: '#code'} 147 | braces: 148 | patterns: 149 | - 150 | begin: '\{' 151 | beginCaptures: 152 | '0': {name: punctuation.section.group.begin.kotlin} 153 | end: '\}' 154 | endCaptures: 155 | '0': {name: punctuation.section.group.end.kotlin} 156 | name: meta.block.kotlin 157 | patterns: 158 | - {include: '#code'} 159 | brackets: 160 | patterns: 161 | - 162 | begin: '\[' 163 | beginCaptures: 164 | '0': {name: punctuation.section.brackets.begin.kotlin} 165 | end: '\]' 166 | endCaptures: 167 | '0': {name: punctuation.section.brackets.end.kotlin} 168 | name: meta.brackets.kotlin 169 | patterns: 170 | - {include: '#code'} 171 | code: 172 | patterns: 173 | - 174 | include: '#comments' 175 | - 176 | include: '#annotations' 177 | - 178 | include: '#parens' 179 | - 180 | include: '#braces' 181 | - 182 | include: '#brackets' 183 | - 184 | include: '#class-literal' 185 | - 186 | include: '#literal-functions' 187 | - 188 | include: '#literals' 189 | - 190 | include: '#keywords' 191 | - 192 | include: '#types' 193 | - 194 | include: '#operators' 195 | - 196 | include: '#constants' 197 | - 198 | include: '#punctuations' 199 | - 200 | include: '#builtin-functions' 201 | keywords: 202 | patterns: 203 | - 204 | match: '(\!in|\!is|as\?)\b' 205 | name: keyword.operator.kotlin 206 | - 207 | match: \b(in|is|as|assert)\b 208 | name: keyword.operator.kotlin 209 | - 210 | match: \b(val|var)\b 211 | name: storage.type.kotlin 212 | - 213 | match: \b(\_)\b 214 | name: punctuation.definition.variable.kotlin 215 | - 216 | match: '\b(tailrec|operator|infix|typealias|reified|copy(?=\s+fun|\s+var))\b' 217 | name: storage.type.kotlin 218 | - 219 | match: \b(out|in|yield|typealias|override)\b 220 | name: storage.modifier.kotlin 221 | - 222 | match: '\b(?=|<|>) 255 | name: keyword.operator.comparison.kotlin 256 | - 257 | match: (=) 258 | name: keyword.operator.assignment.kotlin 259 | - 260 | match: '(:(?!:))' 261 | name: keyword.operator.declaration.kotlin 262 | - 263 | match: '(\?:)' 264 | name: keyword.operator.elvis.kotlin 265 | - 266 | match: (\-\-|\+\+) 267 | name: keyword.operator.increment-decrement.kotlin 268 | - 269 | match: '(\-|\+|\*|\/|%)' 270 | name: keyword.operator.arithmetic.kotlin 271 | - 272 | match: '(\+\=|\-\=|\*\=|\/\=)' 273 | name: keyword.operator.arithmetic.assign.kotlin 274 | - 275 | match: '(\!|\&\&|\|\|)' 276 | name: keyword.operator.logical.kotlin 277 | - 278 | match: (\.\.) 279 | name: keyword.operator.range.kotlin 280 | constants: 281 | patterns: 282 | - 283 | match: \b(class)\b 284 | name: constant.language.kotlin 285 | - 286 | match: \b(this|super)\b 287 | name: variable.language.kotlin 288 | punctuations: 289 | patterns: 290 | - 291 | match: '::' 292 | name: punctuation.accessor.reference.kotlin 293 | - 294 | match: '\?\.' 295 | name: punctuation.accessor.dot.safe.kotlin 296 | - 297 | match: '(?&|\^~.])(->)(?![/=\-+!*%<>&|\^~.])' 372 | captures: 373 | '1': {name: keyword.operator.type.function.kotlin} 374 | - 375 | match: '\?(?!\.)' 376 | name: keyword.operator.type.nullable.kotlin 377 | - 378 | begin: \( 379 | beginCaptures: 380 | '0': {name: punctuation.section.group.begin.kotlin} 381 | end: \) 382 | endCaptures: 383 | '0': {name: punctuation.section.group.end.kotlin} 384 | patterns: 385 | - {include: '#types'} 386 | repository: 387 | built-in-types: 388 | patterns: 389 | - {match: '\b(Nothing|Any|Unit|String|CharSequence|Int|Boolean|Char|Long|Double|Float|Short|Byte|UByte|UShort|UInt|ULong|Array|List|Map|Set|dynamic)\b(\?)?', name: support.class.kotlin} 390 | - {match: '\b(IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray|UByteArray|UShortArray|UIntArray|ULongArray)\b(\?)?', name: support.class.kotlin} 391 | fileTypes: 392 | - kt 393 | - kts 394 | foldingStartMarker: '(\{\s*(//.*)?$|^\s*// \{\{\{)' 395 | foldingStopMarker: '^\s*(\}|// \}\}\}$)' 396 | name: Kotlin 397 | patterns: 398 | - 399 | include: '#comments' 400 | - 401 | include: '#package' 402 | - 403 | include: '#imports' 404 | - 405 | include: '#code' 406 | scopeName: source.kotlin 407 | uuid: d9380650-5edc-447d-8dbd-98838c7d0adf 408 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "language-kotlin", 3 | "version": "1.0.0", 4 | "description": "Textmate grammar for the Kotlin programming language", 5 | "author": "Nish Tahir", 6 | "license": "Apache-2.0", 7 | "homepage": "https://github.com/nishtahir/language-kotlin#readme", 8 | "type": "module", 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/nishtahir/language-kotlin.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/nishtahir/language-kotlin/issues" 15 | }, 16 | "scripts": { 17 | "build:snapshot": "npx vscode-tmgrammar-snap -u -g dist/Kotlin.tmLanguage -s source.kotlin \"snapshots/**/*.kt\"", 18 | "build:grammar": "node scripts/build.js", 19 | "build": "npm run build:grammar && npm run build:snapshot", 20 | "format": "node scripts/format.js", 21 | "coverage": "node scripts/coverage.js && npx codecov", 22 | "prettier": "prettier --write .", 23 | "test:snapshot": "npx vscode-tmgrammar-snap -g dist/Kotlin.tmLanguage -s source.kotlin \"snapshots/**/*.kt\"", 24 | "test:grammar": "npx vscode-tmgrammar-test -g dist/Kotlin.tmLanguage \"test/**/*.test.kt\"", 25 | "test": "npm run test:grammar && npm run test:snapshot" 26 | }, 27 | "devDependencies": { 28 | "codecov": "^3.8.3", 29 | "deepmerge": "^4.3.1", 30 | "format-json": "^1.0.3", 31 | "lcov-write": "^1.0.0", 32 | "plist": "^3.1.0", 33 | "prettier": "^3.3.3", 34 | "vscode-tmgrammar-test": "^0.1.3", 35 | "yaml": "^1.10.0", 36 | "yaml-source-map": "^2.1.1", 37 | "yamljs": "^0.3.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This script is used to generate the final syntax files from the source files. 3 | * It merges all source files into a single file and generates the final syntax files. 4 | * - Kotlin.JSON-tmLanguage 5 | * - Kotlin.YAML-tmLanguage 6 | * - Kotlin.tmLanguage 7 | */ 8 | 9 | import fs from "fs"; 10 | import path from "path"; 11 | import plist from "plist"; 12 | import json from "format-json"; 13 | import yaml from "yamljs"; 14 | import deepmerge from "deepmerge"; 15 | import { __dirname, safeWriteFileSync } from "./util.js"; 16 | 17 | const SOURCE_PATH = path.resolve(__dirname, "../", "src/"); 18 | const OUTPUT_PATH = path.resolve(__dirname, "../dist/"); 19 | 20 | const data = fs.readdirSync(SOURCE_PATH).reduce((acc, file) => { 21 | const filePath = path.resolve(SOURCE_PATH, file); 22 | try { 23 | const source = fs.readFileSync(filePath, "utf8"); 24 | // skip empty files 25 | if (source.trim().length === 0) { 26 | return acc; 27 | } 28 | 29 | const parsedFile = yaml.parse(source); 30 | return deepmerge(acc, parsedFile); 31 | } catch (err) { 32 | console.log("An error occured while parsing file..."); 33 | console.log(filePath, "\n", err); 34 | process.exit(1); 35 | } 36 | }, {}); 37 | 38 | console.log("Generating Json file..."); 39 | safeWriteFileSync( 40 | path.resolve(OUTPUT_PATH, "Kotlin.JSON-tmLanguage"), 41 | json.plain(data), 42 | ); 43 | 44 | console.log("Generating Yaml file..."); 45 | safeWriteFileSync( 46 | path.resolve(OUTPUT_PATH, "Kotlin.YAML-tmLanguage"), 47 | yaml.stringify(data, 6), 48 | ); 49 | 50 | console.log("Generating Xml file..."); 51 | const xmlData = plist.build(data); 52 | safeWriteFileSync(path.resolve(OUTPUT_PATH, "Kotlin.tmLanguage"), xmlData); 53 | -------------------------------------------------------------------------------- /scripts/coverage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This script generates a naive coverage report for the Kotlin.tmlanguage file. 3 | * It is used to ensure that all scopes are tested. 4 | * 5 | * The script works by instrumenting the compiled Kotlin.tmlanguage file with 6 | * coverage tracking scopes. It then runs all tests against the instrumented file 7 | * and generates a coverage report. 8 | * 9 | * It does not consider the inner structure of the scopes, only that they are hit. 10 | */ 11 | 12 | import path from "path"; 13 | import plist from "plist"; 14 | import { 15 | __dirname, 16 | safeWriteFileSync, 17 | getAllFilesInDir, 18 | readFileSync, 19 | } from "./util.js"; 20 | 21 | import { 22 | parseGrammarTestCase, 23 | runGrammarTestCase, 24 | } from "vscode-tmgrammar-test/dist/unit/index.js"; 25 | import { createRegistry } from "vscode-tmgrammar-test/dist/common/index.js"; 26 | 27 | import lcovWrite from "lcov-write"; 28 | import Yaml from "yaml"; 29 | import YamlSourceMap from "yaml-source-map"; 30 | 31 | const distDir = path.resolve(__dirname, "../", "dist/"); 32 | const buildDir = path.resolve(__dirname, "../", "build/"); 33 | const testDir = path.resolve(__dirname, "../", "test/"); 34 | const srcDir = path.resolve(__dirname, "../", "src/"); 35 | 36 | const compiledSourcePath = path.resolve(distDir, "Kotlin.JSON-tmLanguage"); 37 | const compiledSource = JSON.parse(readFileSync(compiledSourcePath)); 38 | const instrumentedTree = instrumentScopesTree(compiledSource); 39 | console.log(`${instrumentedTree.probesInserted} probes inserted...`); 40 | 41 | const xml = plist.build(instrumentedTree.scopesTree); 42 | const instrumentedSourcePath = path.resolve(buildDir, "Kotlin.tmLanguage"); 43 | 44 | // vscode-tmgrammar-test requires this to be a file on disk. 45 | // This is not ideal but we have to work with it for now... 46 | safeWriteFileSync(instrumentedSourcePath, xml); 47 | 48 | const testSources = getAllFilesInDir(testDir); 49 | const appSources = getAllFilesInDir(srcDir); 50 | generateCoverageReports(appSources, testSources, instrumentedSourcePath); 51 | 52 | /** 53 | * Generate an LCOV compatible coverage report for the given inputs 54 | * @param {Array} appSources application sources to map coverage data to 55 | * @param {Array} testSources test sources to test coverage 56 | * @param {string} instrumentedSourcePath instrumented compiled source 57 | */ 58 | async function generateCoverageReports( 59 | appSources, 60 | testSources, 61 | instrumentedSourcePath, 62 | ) { 63 | const registry = createRegistry([ 64 | { path: instrumentedSourcePath, language: "kotlin" }, 65 | ]); 66 | const scopesHit = await runTestCases(registry, testSources); 67 | 68 | const allHits = Object.values(scopesHit) 69 | .flat() 70 | .filter((hit) => hit !== "source.kotlin") 71 | .map((hit) => (hit.endsWith(".name") ? hit.slice(0, -5) : hit)); 72 | 73 | const sourceMap = new YamlSourceMap(); 74 | 75 | // Index application sources 76 | const indexedSources = appSources.map((sourceFile) => { 77 | const sourceContent = readFileSync(sourceFile); 78 | const document = Yaml.parseDocument(sourceContent, { keepCstNodes: true }); 79 | return { 80 | source: document.toJSON(), 81 | index: sourceMap.index(document, { filename: sourceFile }), 82 | filename: sourceFile, 83 | }; 84 | }); 85 | 86 | const coverageData = []; 87 | 88 | // Find match all hits in sources 89 | indexedSources.forEach((indexedSource) => { 90 | const { source, index, filename } = indexedSource; 91 | const coverage = createCoverageData(filename); 92 | 93 | const lineData = {}; 94 | 95 | // Seed lineData with testable lines. 96 | // this includes anything that has a scope 97 | findScopes(source) 98 | .map((path) => path.slice(0, -1)) 99 | .map((path) => sourceMap.lookup(path, index)) 100 | .forEach((line) => { 101 | const start = line.start.line; 102 | const end = line.end.line; 103 | // End is not inclusive 104 | for (let i = start; i < end; i++) { 105 | if (!lineData[i]) { 106 | lineData[i] = 0; 107 | } 108 | } 109 | }); 110 | 111 | // We now know how many lines we can test 112 | coverage.lines.found = Object.keys(lineData).length; 113 | 114 | allHits.forEach((hit) => { 115 | const mapping = sourceMap.lookup(hit.split("."), index); 116 | if (mapping) { 117 | const start = mapping.start.line; 118 | const end = mapping.end.line; 119 | // End is not inclusive 120 | for (let i = start; i < end; i++) { 121 | lineData[i]++; 122 | } 123 | } 124 | }); 125 | 126 | // Count lines that have at least 1 hit 127 | coverage.lines.hit = Object.values(lineData).filter( 128 | (value) => value > 0, 129 | ).length; 130 | 131 | // Associate hit count and line numbers 132 | // for coverage report 133 | for (const lineNum in lineData) { 134 | if (lineData.hasOwnProperty(lineNum)) { 135 | const hits = lineData[lineNum]; 136 | coverage.lines.details.push({ 137 | line: lineNum, 138 | hit: hits, 139 | }); 140 | } 141 | } 142 | 143 | coverageData.push(coverage); 144 | }); 145 | 146 | printCoverageSummary(coverageData); 147 | writeCoverageReportToLcov(coverageData); 148 | } 149 | 150 | /** 151 | * @param {*} coverageData 152 | */ 153 | function printCoverageSummary(coverageData) { 154 | coverageData.forEach(({ title, lines }) => { 155 | const lineCoveragePercent = ((lines.hit / lines.found) * 100).toFixed(2); 156 | console.log(`${title}\nLine coverage: ${lineCoveragePercent}%\n`); 157 | }); 158 | } 159 | 160 | /** 161 | * 162 | * @param coverageData - coverage report to serialize to LCOV 163 | */ 164 | function writeCoverageReportToLcov(coverageData, outputFile = "coverage.lcov") { 165 | // Write coverage data to file 166 | const coverageSource = lcovWrite.stringify(coverageData); 167 | safeWriteFileSync(path.resolve(buildDir, outputFile), coverageSource); 168 | } 169 | 170 | /** 171 | * Generate an LCOV coverage data template 172 | * @param {string} filename filename of the file undertest 173 | */ 174 | function createCoverageData(filename) { 175 | return { 176 | title: filename, 177 | file: filename, 178 | functions: { 179 | hit: 0, 180 | found: 0, 181 | details: [], 182 | }, 183 | branches: { 184 | hit: 0, 185 | found: 0, 186 | details: [], 187 | }, 188 | lines: { 189 | hit: 0, 190 | found: 0, 191 | details: [], 192 | }, 193 | }; 194 | } 195 | 196 | /** 197 | * Run test cases against a test sources. 198 | * @param {object} registry - registry containing scopes to test against. 199 | * @param {Array} testSources sources to test. 200 | * @returns {object} map of file to scopes that were hit. 201 | */ 202 | async function runTestCases(registry, testSources) { 203 | let scopesHit = {}; 204 | for (let i = 0; i < testSources.length; i++) { 205 | const file = testSources[i]; 206 | const results = await runSingleTestCase(registry, file); 207 | const actualScopesFound = results.map((result) => result.actual).flat(); 208 | scopesHit[file] = actualScopesFound; 209 | } 210 | return scopesHit; 211 | } 212 | 213 | /** 214 | * Run a single test case 215 | * @param {object} registry - scopes to test against 216 | * @param {string} file - path to file to test 217 | */ 218 | async function runSingleTestCase(registry, file) { 219 | const testCase = parseGrammarTestCase(readFileSync(file)); 220 | return await runGrammarTestCase(registry, testCase); 221 | } 222 | 223 | /** 224 | * Find all testable scopes for the given object 225 | * These are scopes that contain a 'name' element 226 | * @param {object} obj - object to search 227 | * @param {Array} qualifiedPath - current path to the object 228 | */ 229 | function findScopes(obj, qualifiedPath = []) { 230 | let scopes = []; 231 | for (let key in obj) { 232 | const value = obj[key]; 233 | const scopedQualifiedPath = [...qualifiedPath, key]; 234 | if (typeof value === "object") { 235 | scopes = scopes.concat(findScopes(value, scopedQualifiedPath)); 236 | } else { 237 | if (key === "name") { 238 | scopes.push(scopedQualifiedPath); 239 | } 240 | } 241 | } 242 | return scopes; 243 | } 244 | 245 | /** 246 | * Instruments a given scope tree by replacing its named scopes 247 | * with debug scope names for coverage tracking. Names are uniquely determined 248 | * by generating a fully qualified path to the scope. 249 | * 250 | * @param {object} scopesTree - tree to instrument 251 | */ 252 | function instrumentScopesTree(scopesTree) { 253 | let probeCount = 0; 254 | 255 | /** 256 | * Recursively inserts coverage tracking probes into a given 257 | * tmlanguage scope tree. 258 | * Nested to keep the outer function pure. 259 | * @param {object} obj - tree to instrument 260 | * @param {arr} qualifiedPath qualified path of the current scopes if this is nested 261 | */ 262 | function insertProbes(obj, qualifiedPath = []) { 263 | for (let key in obj) { 264 | const value = obj[key]; 265 | const scopedQualifiedPath = [...qualifiedPath, key]; 266 | if (typeof value === "object") { 267 | insertProbes(obj[key], scopedQualifiedPath); 268 | } else { 269 | if (key === "name") { 270 | const qualifiedPathStr = scopedQualifiedPath.join("."); 271 | obj[key] = qualifiedPathStr; 272 | probeCount++; 273 | } 274 | } 275 | } 276 | } 277 | 278 | // Mutate the tree inserting coverage scopes 279 | insertProbes(scopesTree); 280 | 281 | return { 282 | probesInserted: probeCount, 283 | scopesTree, 284 | }; 285 | } 286 | -------------------------------------------------------------------------------- /scripts/format.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This script formats all YAML files in the src/ directory. 3 | * It is used to ensure a consistent code style. 4 | */ 5 | 6 | import path from "path"; 7 | import yaml from "yamljs"; 8 | import { readdirSync, readFileSync, writeFileSync } from "fs"; 9 | import { __dirname } from "./util.js"; 10 | 11 | const sourceDirPath = path.resolve(__dirname, "../", "src/"); 12 | const sourceFiles = readdirSync(sourceDirPath); 13 | 14 | sourceFiles.forEach((file) => { 15 | const filePath = path.resolve(sourceDirPath, file); 16 | console.log("Formatting " + filePath); 17 | 18 | const source = readFileSync(filePath, "utf8"); 19 | if (source.trim().length === 0) { 20 | return; // skip empty files 21 | } 22 | 23 | const parsedFile = yaml.parse(source); 24 | const yamlData = yaml.stringify(parsedFile, { 25 | indent: 2, 26 | indentSeq: true, 27 | }); 28 | writeFileSync(filePath, yamlData); 29 | }); 30 | -------------------------------------------------------------------------------- /scripts/util.js: -------------------------------------------------------------------------------- 1 | import fs from "fs"; 2 | import path from "path"; 3 | import { fileURLToPath } from "url"; 4 | 5 | export const __filename = fileURLToPath(import.meta.url); 6 | export const __dirname = path.dirname(__filename); 7 | 8 | /** 9 | * Read a file from a given path 10 | * @param {string} path file to read 11 | */ 12 | export function readFileSync(path) { 13 | return fs.readFileSync(path, "utf8"); 14 | } 15 | 16 | /** 17 | * Wrapper around [writeFileSync] that creates 18 | * the directory to write in before performing the write. 19 | * @param {string} dest 20 | * @param {string} content 21 | */ 22 | export function safeWriteFileSync(dest, content) { 23 | const dir = dest.substring(0, dest.lastIndexOf("/") + 1); 24 | if (!fs.existsSync(dir)) { 25 | fs.mkdirSync(dir); 26 | } 27 | fs.writeFileSync(dest, content); 28 | } 29 | 30 | /** 31 | * Returns a list of files in the given directory 32 | * @param {string} dirPath - path to directory 33 | * @param {Array} files - files in parent directory 34 | */ 35 | export function getAllFilesInDir(dirPath, files = []) { 36 | fs.readdirSync(dirPath).forEach((file) => { 37 | if (fs.statSync(dirPath + "/" + file).isDirectory()) { 38 | files = getAllFilesInDir(dirPath + "/" + file, files); 39 | } else { 40 | files.push(path.join(dirPath, "/", file)); 41 | } 42 | }); 43 | return files; 44 | } 45 | -------------------------------------------------------------------------------- /snapshots/corpus.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlin 2 | 3 | // #region imports 4 | import java.util.Random as Rand 5 | import android.support.v7.app.AppCompatActivity 6 | import org.amshove.kluent.`should equal` as Type 7 | // #endregion 8 | 9 | // #region main 10 | fun main(@NonNull args: Array) { 11 | println("Hello Kotlin! ${/*test*/}") 12 | 13 | val map = mutableMapOf("A" to "B") 14 | 15 | thing.apply("random string here \n\t\r") 16 | thing.let { test: -> } 17 | 18 | val string = "${getThing()}" 19 | } 20 | // #endregion 21 | 22 | // #region variables 23 | val items = listOf("apple", "banana", "kiwifruit") 24 | var x = 9 25 | const val CONSTANT = 99 26 | 27 | @get:Rule 28 | val activityRule = ActivityTestRule(SplashActivity::class.java) 29 | // #endregion 30 | 31 | // #region numeric 32 | val oneMillion = 1_000_000 33 | val creditCardNumber = 1234_5678_9012_3456L 34 | val socialSecurityNumber = 999_99_9999L 35 | val hexBytes = 0xFF_EC_DE_5E 36 | val float = 0.043_331F 37 | val bytes = 0b11010010_01101001_10010100_10010010 38 | // #endregion 39 | 40 | // #region conditionals 41 | if(test == "") { 42 | 1 and 2 not 3 43 | } else { 44 | 45 | } 46 | // #endregion 47 | 48 | // #region functions 49 | fun foo() { 50 | val x = Bar::class 51 | val y = hello?.test 52 | } 53 | 54 | suspend fun SequenceBuilder.yieldIfOdd(x: Int) { 55 | if (x % 2 != 0) yield(x) 56 | } 57 | 58 | val function = fun(@Inject x: Int, y: Int, lamda: (A, B) -> Unit): Int { 59 | test.test() 60 | return x + y; 61 | } 62 | 63 | abstract fun onCreate(savedInstanceState: Bundle?) 64 | 65 | fun isOdd(x: Int) = x % 2 != 0 66 | fun isOdd(s: String) = s == "brillig" || s == "slithy" || s == "tove" 67 | 68 | val numbers = listOf(1, 2, 3) 69 | println(numbers.filter(::isOdd)) 70 | // #endregion 71 | 72 | // #region control 73 | fun foo(node: Node?): String? { 74 | val parent = node.getParent() ?: return null 75 | } 76 | // #endregion 77 | 78 | // #region classes 79 | interface Greetable { 80 | fun greet() 81 | } 82 | 83 | open class Greeter: Greetable { 84 | companion object { 85 | private const val GREETING = "Hello, World!" 86 | } 87 | 88 | override fun greet() { 89 | println(GREETING) 90 | } 91 | } 92 | // #endregion 93 | 94 | // #region expect/actual 95 | expect class Foo(bar: String) { 96 | fun frob() 97 | } 98 | 99 | actual class Foo actual constructor(val bar: String) { 100 | actual fun frob() { 101 | println("Frobbing the $bar") 102 | } 103 | } 104 | 105 | expect fun formatString(source: String, vararg args: Any): String 106 | expect annotation class Test 107 | 108 | actual fun formatString(source: String, vararg args: Any) = String.format(source, args) 109 | actual typealias Test = org.junit.Test 110 | // #endregion 111 | 112 | // #region sealed-class 113 | sealed class Expr 114 | data class Const(val number: Double) : Expr() 115 | data class Sum(val e1: Expr, val e2: Expr) : Expr() 116 | object NotANumber : Expr() 117 | // #endregion 118 | 119 | // #region annotation 120 | @file:JvmName("Foo") 121 | private sealed class InjectedClass @Inject constructor(val test: Int = 50, var anotherVar: String = "hello world") : SomeSuperClass(test, anotherVar) { 122 | 123 | init { 124 | // 125 | } 126 | 127 | constructor(param1: String, param2: Int): this(param1, param2) { 128 | // 129 | } 130 | 131 | companion object { 132 | // 133 | } 134 | } 135 | annotation class Suspendable 136 | val f = @Suspendable { Fiber.sleep(10) } 137 | // #endregion 138 | 139 | 140 | private data class Foo( 141 | /** 142 | * ``` 143 | * ($) 144 | * ``` 145 | */ 146 | val variables: Map 147 | ) 148 | 149 | data class Response(@SerializedName("param1") val param1: String, 150 | @SerializedName("param2") val param2: String, 151 | @SerializedName("param3") val param3: String) { 152 | } 153 | 154 | object DefaultListener : MouseAdapter() { 155 | override fun mouseClicked(e: MouseEvent) { } 156 | 157 | override fun mouseEntered(e: MouseEvent) { } 158 | } 159 | 160 | class Feature : Node("Title", "Content", "Description") { 161 | 162 | } 163 | 164 | class Outer { 165 | inner class Inner {} 166 | } 167 | 168 | sealed interface ProfileScreenState { 169 | data class Success(val username: String) : ProfileScreenState 170 | data object Error : ProfileScreenState 171 | data object Loading : ProfileScreenState 172 | } 173 | -------------------------------------------------------------------------------- /src/annotations.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | annotations: 3 | patterns: 4 | - 5 | comment: 'Use-site annotation' 6 | match: '@(?:file|property|field|get|set|receiver|param|setparam|delegate)\s*:\s*?[a-zA-Z_]\w*' 7 | name: meta.annotation.kotlin 8 | - 9 | begin: '@[a-zA-Z_]\w*\s*(\()' 10 | beginCaptures: 11 | '1': 12 | name: punctuation.definition.arguments.begin.kotlin 13 | end: \) 14 | endCaptures: 15 | '0': 16 | name: punctuation.definition.arguments.end.kotlin 17 | name: meta.annotation.kotlin 18 | patterns: 19 | - 20 | include: '#code' 21 | - 22 | match: ',' 23 | name: punctuation.seperator.property.kotlin 24 | - 25 | match: '@[a-zA-Z_]\w*' 26 | name: meta.annotation.kotlin 27 | -------------------------------------------------------------------------------- /src/classes.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | class-literal: 3 | patterns: 4 | - 5 | begin: '(?=\b(?:(?:(?:data|value)\s+)?class|(?:data\s+)?object|(?:(?:fun|value)\s+)?interface)\s+\w+)\b' 6 | end: '(?=\}|$)' 7 | name: meta.class.kotlin 8 | patterns: 9 | - 10 | include: '#keywords' 11 | - 12 | begin: '\b((?:(?:data|value)\s+)?class|(?:data\s+)?object|(?:(?:fun|value)\s+)?interface)\b\s+(\w+)' 13 | beginCaptures: 14 | '1': 15 | name: storage.modifier.kotlin 16 | '2': 17 | name: entity.name.class.kotlin 18 | end: '(?=\(|\{|$)' 19 | patterns: 20 | - 21 | include: '#comments' 22 | - 23 | include: '#annotations' 24 | - 25 | include: '#types' 26 | - 27 | begin: (\() 28 | beginCaptures: 29 | '0': 30 | name: punctuation.section.group.begin.kotlin 31 | '1': 32 | name: punctuation.definition.parameters.begin.kotlin 33 | end: (\)) 34 | endCaptures: 35 | '0': 36 | name: punctuation.section.group.end.kotlin 37 | '1': 38 | name: punctuation.definition.parameters.end.kotlin 39 | name: meta.parameters.kotlin 40 | patterns: 41 | - 42 | include: '#class-parameter-list' 43 | - 44 | include: '#comments' 45 | - 46 | begin: '\{' 47 | beginCaptures: 48 | '0': 49 | name: punctuation.section.group.begin.kotlin 50 | end: '\}' 51 | endCaptures: 52 | '0': 53 | name: punctuation.section.group.end.kotlin 54 | name: meta.block.kotlin 55 | patterns: 56 | - 57 | include: '#code' 58 | repository: 59 | class-parameter-list: 60 | patterns: 61 | - 62 | include: '#generic' 63 | - 64 | include: '#annotations' 65 | - 66 | include: '#keywords' 67 | - 68 | match: '(\w+)\s*(:)' 69 | captures: 70 | '1': 71 | name: variable.parameter.function.kotlin 72 | '2': 73 | name: keyword.operator.declaration.kotlin 74 | - 75 | match: ',' 76 | name: punctuation.seperator.kotlin 77 | - 78 | include: '#types' 79 | - 80 | include: '#literals' 81 | -------------------------------------------------------------------------------- /src/comments.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | comments: 3 | patterns: 4 | - 5 | include: '#inline' 6 | - 7 | begin: '/\*' 8 | beginCaptures: 9 | '0': 10 | name: punctuation.definition.comment.begin.kotlin 11 | end: '\*/' 12 | endCaptures: 13 | '0': 14 | name: punctuation.definition.comment.end.kotlin 15 | name: comment.block.kotlin 16 | patterns: 17 | - 18 | include: '#nested' 19 | repository: 20 | inline: 21 | patterns: 22 | - 23 | match: '(//).*$\n?' 24 | captures: 25 | '0': 26 | name: punctuation.definition.comment.kotlin 27 | '1': 28 | name: comment.line.double-slash.kotlin 29 | nested: 30 | patterns: 31 | - 32 | begin: '/\*' 33 | end: '\*/' 34 | patterns: 35 | - 36 | include: '#nested' 37 | -------------------------------------------------------------------------------- /src/functions.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | builtin-functions: 3 | patterns: 4 | - 5 | match: '\b(apply|also|let|run|takeIf|takeWhile|takeUnless|with|print|println)\b\s*(?={|\()' 6 | captures: 7 | '1': 8 | name: support.function.kotlin 9 | - 10 | match: '\b(arrayListOf|mutableListOf|listOf|mutableMapOf|mapOf|mutableSetOf|setOf)\b\s*(?={|\()' 11 | captures: 12 | '1': 13 | name: support.function.kotlin 14 | literal-functions: 15 | patterns: 16 | - 17 | begin: '(?=\b(?:fun)\b)' 18 | end: '(?<=$|=|\})' 19 | name: meta.function.kotlin 20 | patterns: 21 | - 22 | include: '#keywords' 23 | - 24 | begin: \bfun\b 25 | beginCaptures: 26 | '0': 27 | name: keyword.other.kotlin 28 | end: '(?=\()' 29 | patterns: 30 | - 31 | include: '#generic' 32 | - 33 | match: '(`[^`]*`)' 34 | comment: 'Backtick quoted function names' 35 | captures: 36 | '0': 37 | name: entity.name.function.kotlin 38 | '1': 39 | name: string.quoted.backtick.kotlin 40 | - 41 | match: '([\.<\?>\w]+\.)?(\w+)' 42 | captures: 43 | '2': 44 | name: entity.name.function.kotlin 45 | - 46 | include: '#types' 47 | - 48 | begin: (\() 49 | beginCaptures: 50 | '0': 51 | name: punctuation.section.group.begin.kotlin 52 | '1': 53 | name: punctuation.definition.parameters.begin.kotlin 54 | end: (\)) 55 | endCaptures: 56 | '0': 57 | name: punctuation.section.group.end.kotlin 58 | '1': 59 | name: punctuation.definition.parameters.end.kotlin 60 | name: meta.parameters.kotlin 61 | patterns: 62 | - 63 | include: '#function-parameter-list' 64 | - 65 | match: '=' 66 | name: keyword.operator.single-expression.kotlin 67 | - 68 | begin: '\{' 69 | beginCaptures: 70 | '0': 71 | name: punctuation.section.group.begin.kotlin 72 | end: '\}' 73 | endCaptures: 74 | '0': 75 | name: punctuation.section.group.end.kotlin 76 | name: meta.block.kotlin 77 | patterns: 78 | - 79 | include: '#code' 80 | - 81 | include: '#return-type' 82 | repository: 83 | function-parameter-list: 84 | patterns: 85 | - 86 | include: '#comments' 87 | - 88 | include: '#annotations' 89 | - 90 | include: '#keywords' 91 | - 92 | match: '(\w+)\s*(:)' 93 | captures: 94 | '1': 95 | name: variable.parameter.function.kotlin 96 | '2': 97 | name: keyword.operator.declaration.kotlin 98 | - 99 | match: ',' 100 | name: punctuation.seperator.kotlin 101 | - 102 | include: '#types' 103 | return-type: 104 | patterns: 105 | - 106 | name: meta.return.type.kotlin 107 | begin: '(?<=\))\s*(:)(?=\s*\S)' 108 | end: '(?)(?!\>)' 7 | patterns: 8 | - 9 | match: '<' 10 | name: punctuation.bracket.angle.begin.kotlin 11 | - 12 | match: '>' 13 | name: punctuation.bracket.angle.end.kotlin 14 | - 15 | match: '\*' 16 | name: entity.name.type.generic.wildcard.kotlin 17 | - 18 | include: '#generic-parameter-list' 19 | - 20 | match: ',' 21 | name: punctuation.seperator.kotlin 22 | repository: 23 | generic-parameter-list: 24 | patterns: 25 | - 26 | include: '#annotations' 27 | - 28 | match: \b(in|out)\b 29 | name: storage.modifier.generic.variance.kotlin 30 | - 31 | include: '#built-in-types' 32 | - 33 | include: '#class-ident' 34 | - 35 | include: '#generic' 36 | - 37 | include: '#operators' 38 | -------------------------------------------------------------------------------- /src/ident.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | class-ident: 3 | patterns: 4 | - 5 | match: '\b[A-Z_]\w*\b' 6 | name: entity.name.type.class.kotlin 7 | comment: 'Classes generally start with an Uppercase Char' 8 | -------------------------------------------------------------------------------- /src/imports.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | imports: 3 | patterns: 4 | - 5 | match: '^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?' 6 | captures: 7 | '1': 8 | name: keyword.other.import.kotlin 9 | '2': 10 | name: storage.modifier.import.kotlin 11 | '3': 12 | name: keyword.other.kotlin 13 | '4': 14 | name: entity.name.type 15 | name: meta.import.kotlin 16 | -------------------------------------------------------------------------------- /src/index.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | fileTypes: 2 | - kt 3 | - kts 4 | foldingStartMarker: '(\{\s*(//.*)?$|^\s*// \{\{\{)' 5 | foldingStopMarker: '^\s*(\}|// \}\}\}$)' 6 | name: Kotlin 7 | patterns: 8 | - 9 | include: '#comments' 10 | - 11 | include: '#package' 12 | - 13 | include: '#imports' 14 | - 15 | include: '#code' 16 | repository: 17 | parens: 18 | patterns: 19 | - 20 | begin: \( 21 | beginCaptures: 22 | '0': 23 | name: punctuation.section.group.begin.kotlin 24 | end: \) 25 | endCaptures: 26 | '0': 27 | name: punctuation.section.group.end.kotlin 28 | name: meta.group.kotlin 29 | patterns: 30 | - 31 | include: '#code' 32 | braces: 33 | patterns: 34 | - 35 | begin: '\{' 36 | beginCaptures: 37 | '0': 38 | name: punctuation.section.group.begin.kotlin 39 | end: '\}' 40 | endCaptures: 41 | '0': 42 | name: punctuation.section.group.end.kotlin 43 | name: meta.block.kotlin 44 | patterns: 45 | - 46 | include: '#code' 47 | brackets: 48 | patterns: 49 | - 50 | begin: '\[' 51 | beginCaptures: 52 | '0': 53 | name: punctuation.section.brackets.begin.kotlin 54 | end: '\]' 55 | endCaptures: 56 | '0': 57 | name: punctuation.section.brackets.end.kotlin 58 | name: meta.brackets.kotlin 59 | patterns: 60 | - 61 | include: '#code' 62 | code: 63 | patterns: 64 | - 65 | include: '#comments' 66 | - 67 | include: '#annotations' 68 | - 69 | include: '#parens' 70 | - 71 | include: '#braces' 72 | - 73 | include: '#brackets' 74 | - 75 | include: '#class-literal' 76 | - 77 | include: '#literal-functions' 78 | - 79 | include: '#literals' 80 | - 81 | include: '#keywords' 82 | - 83 | include: '#types' 84 | - 85 | include: '#operators' 86 | - 87 | include: '#constants' 88 | - 89 | include: '#punctuations' 90 | - 91 | include: '#builtin-functions' 92 | scopeName: source.kotlin 93 | uuid: d9380650-5edc-447d-8dbd-98838c7d0adf 94 | -------------------------------------------------------------------------------- /src/keywords.YAML-tmLanguage: -------------------------------------------------------------------------------- 1 | repository: 2 | keywords: 3 | patterns: 4 | - 5 | match: '(\!in|\!is|as\?)\b' 6 | name: keyword.operator.kotlin 7 | - 8 | match: \b(in|is|as|assert)\b 9 | name: keyword.operator.kotlin 10 | - 11 | match: \b(val|var)\b 12 | name: storage.type.kotlin 13 | - 14 | match: \b(\_)\b 15 | name: punctuation.definition.variable.kotlin 16 | - 17 | match: '\b(tailrec|operator|infix|typealias|reified|copy(?=\s+fun|\s+var))\b' 18 | name: storage.type.kotlin 19 | - 20 | match: \b(out|in|yield|typealias|override)\b 21 | name: storage.modifier.kotlin 22 | - 23 | match: '\b(?=|<|>) 56 | name: keyword.operator.comparison.kotlin 57 | - 58 | match: (=) 59 | name: keyword.operator.assignment.kotlin 60 | - 61 | match: '(:(?!:))' 62 | name: keyword.operator.declaration.kotlin 63 | - 64 | match: '(\?:)' 65 | name: keyword.operator.elvis.kotlin 66 | - 67 | match: (\-\-|\+\+) 68 | name: keyword.operator.increment-decrement.kotlin 69 | - 70 | match: '(\-|\+|\*|\/|%)' 71 | name: keyword.operator.arithmetic.kotlin 72 | - 73 | match: '(\+\=|\-\=|\*\=|\/\=)' 74 | name: keyword.operator.arithmetic.assign.kotlin 75 | - 76 | match: '(\!|\&\&|\|\|)' 77 | name: keyword.operator.logical.kotlin 78 | - 79 | match: (\.\.) 80 | name: keyword.operator.range.kotlin 81 | constants: 82 | patterns: 83 | - 84 | match: \b(class)\b 85 | name: constant.language.kotlin 86 | - 87 | match: \b(this|super)\b 88 | name: variable.language.kotlin 89 | punctuations: 90 | patterns: 91 | - 92 | match: '::' 93 | name: punctuation.accessor.reference.kotlin 94 | - 95 | match: '\?\.' 96 | name: punctuation.accessor.dot.safe.kotlin 97 | - 98 | match: '(?&|\^~.])(->)(?![/=\-+!*%<>&|\^~.])' 12 | captures: 13 | '1': 14 | name: keyword.operator.type.function.kotlin 15 | - 16 | match: '\?(?!\.)' 17 | name: keyword.operator.type.nullable.kotlin 18 | - 19 | begin: \( 20 | beginCaptures: 21 | '0': 22 | name: punctuation.section.group.begin.kotlin 23 | end: \) 24 | endCaptures: 25 | '0': 26 | name: punctuation.section.group.end.kotlin 27 | patterns: 28 | - 29 | include: '#types' 30 | repository: 31 | built-in-types: 32 | patterns: 33 | - 34 | match: '\b(Nothing|Any|Unit|String|CharSequence|Int|Boolean|Char|Long|Double|Float|Short|Byte|UByte|UShort|UInt|ULong|Array|List|Map|Set|dynamic)\b(\?)?' 35 | name: support.class.kotlin 36 | - 37 | match: '\b(IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray|UByteArray|UShortArray|UIntArray|ULongArray)\b(\?)?' 38 | name: support.class.kotlin 39 | -------------------------------------------------------------------------------- /test/ClassDeclaration.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Class Declaration" 2 | class Test() { 3 | // <--- meta.class.kotlin storage.modifier.kotlin 4 | // ^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 5 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 6 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 7 | // ^ meta.block.kotlin punctuation.section.group.begin.kotlin 8 | } 9 | // <--- source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 10 | 11 | expect class Foo(bar: String) 12 | // <-- storage.modifier.kotlin 13 | // ^^^^^ meta.class.kotlin storage.modifier.kotlin 14 | // ^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 15 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 16 | // ^^^ variable.parameter.function.kotlin 17 | // ^^^^^^ support.class.kotlin 18 | // ^ punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 19 | 20 | expect class Foo(bar: String, baz: String) 21 | // ^ punctuation.seperator.kotlin 22 | // ^^^ variable.parameter.function.kotlin 23 | // ^^^^^^ support.class.kotlin 24 | 25 | actual class Foo(bar: String) { 26 | // ^ punctuation.section.group.begin.kotlin 27 | actual fun frob() { 28 | // ^^^^^^ storage.modifier.kotlin 29 | // ^^^ keyword.other.kotlin 30 | // ^^^^ entity.name.function.kotlin 31 | // ^ meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 32 | // ^ meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 33 | // ^ meta.block.kotlin punctuation.section.group.begin.kotlin 34 | } 35 | // ^ meta.block.kotlin punctuation.section.group.end.kotlin 36 | } 37 | // <--- ^ punctuation.section.group.begin.kotlin 38 | 39 | fun interface ITestInterface { 40 | // <------------- meta.class.kotlin storage.modifier.kotlin 41 | // ^^^^^^^^^^^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 42 | // ^ meta.block.kotlin punctuation.section.group.begin.kotlin 43 | fun sam() 44 | // ^^^ keyword.other.kotlin 45 | // ^^^ entity.name.function.kotlin 46 | // ^ meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 47 | // ^ meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 48 | } 49 | // <- source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 50 | 51 | value class UInt(private val value: Int) {} 52 | // <----------- meta.class.kotlin storage.modifier.kotlin 53 | // ^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 54 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 55 | // ^^^ variable.parameter.function.kotlin 56 | // ^^^ support.class.kotlin 57 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 58 | -------------------------------------------------------------------------------- /test/Comments.test.kt: -------------------------------------------------------------------------------- 1 | ## SYNTAX TEST "source.kotlin" "Comments" 2 | ## Note comments are represented by ## in this file 3 | 4 | // hey taco 5 | ##^^ source.kotlin punctuation.definition.comment.kotlin comment.line.double-slash.kotlin 6 | ## ^^^^^^^^^^ source.kotlin punctuation.definition.comment.kotlin 7 | 8 | 9 | /** 10 | ##^^ source.kotlin comment.block.kotlin punctuation.definition.comment.begin.kotlin 11 | Multi line comment content 12 | ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin comment.block.kotlin 13 | */ 14 | ##^^ source.kotlin comment.block.kotlin punctuation.definition.comment.end.kotlin -------------------------------------------------------------------------------- /test/Functions.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Function Declaration" 2 | 3 | fun main(@NonNull args: Array) { 4 | //^^^ keyword.other.kotlin 5 | // ^^^^ entity.name.function.kotlin 6 | // ^ meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 7 | // ^^^^^^^^ meta.parameters.kotlin meta.annotation.kotlin 8 | // ^ meta.parameters.kotlin 9 | // ^^^^ meta.parameters.kotlin variable.parameter.function.kotlin 10 | // ^ meta.parameters.kotlin keyword.operator.declaration.kotlin 11 | // ^^^^^ meta.parameters.kotlin support.class.kotlin 12 | // ^ punctuation.bracket.angle.begin.kotlin 13 | // ^^^^^^ meta.parameters.kotlin support.class.kotlin 14 | // ^ punctuation.bracket.angle.end.kotlin 15 | // ^ meta.parameters.kotlin punctuation.section.group.end.kotlin 16 | // ^ meta.block.kotlin punctuation.section.group.begin.kotlin 17 | println("Hello Kotlin!") 18 | //^^^^ meta.block.kotlin 19 | // ^^^^^^^ meta.block.kotlin support.function.kotlin 20 | // ^ meta.block.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 21 | // ^ meta.block.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 22 | // ^^^^^^^^^^^^^ meta.block.kotlin meta.group.kotlin string.quoted.double.kotlin 23 | // ^ meta.block.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 24 | // ^ meta.block.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 25 | } 26 | //^ meta.block.kotlin punctuation.section.group.end.kotlin 27 | 28 | 29 | fun `🌯`() { 30 | //^^^ keyword.other.kotlin 31 | // ^ source.kotlin 32 | // ^^^^ entity.name.function.kotlin 33 | // ^ meta.parameters.kotlin punctuation.section.group.begin.kotlin 34 | // ^ meta.parameters.kotlin punctuation.section.group.end.kotlin 35 | // ^ meta.block.kotlin punctuation.section.group.begin.kotlin 36 | println("Hello Kotlin!") 37 | //^^^^ meta.block.kotlin 38 | // ^^^^^^^ meta.block.kotlin support.function.kotlin 39 | // ^ meta.block.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 40 | // ^ meta.block.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 41 | // ^^^^^^^^^^^^^ meta.block.kotlin meta.group.kotlin string.quoted.double.kotlin 42 | // ^ meta.block.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 43 | // ^ meta.block.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 44 | } 45 | //^ meta.block.kotlin punctuation.section.group.end.kotlin 46 | 47 | fun foo(): String? { 48 | //^^^ source.kotlin meta.function.kotlin keyword.other.kotlin 49 | // ^ source.kotlin meta.function.kotlin 50 | // ^^^ source.kotlin meta.function.kotlin entity.name.function.kotlin 51 | // ^ source.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 52 | // ^ source.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 53 | // ^^^^^^^ source.kotlin meta.function.kotlin support.class.kotlin 54 | // ^ source.kotlin meta.function.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 55 | } 56 | //^ source.kotlin meta.function.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 57 | 58 | val numbers = arrayListOf(1, 2, 3) 59 | //^^^ source.kotlin storage.type.kotlin 60 | // ^^^^^^^^^ source.kotlin 61 | // ^ source.kotlin keyword.operator.assignment.kotlin 62 | // ^ source.kotlin 63 | // ^^^^^^^^^^^ source.kotlin support.function.kotlin 64 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 65 | // ^ source.kotlin meta.group.kotlin constant.numeric.integer.kotlin 66 | // ^ source.kotlin meta.group.kotlin punctuation.seperator.kotlin 67 | // ^ source.kotlin meta.group.kotlin 68 | // ^ source.kotlin meta.group.kotlin constant.numeric.integer.kotlin 69 | // ^ source.kotlin meta.group.kotlin punctuation.seperator.kotlin 70 | // ^ source.kotlin meta.group.kotlin 71 | // ^ source.kotlin meta.group.kotlin constant.numeric.integer.kotlin 72 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 73 | 74 | fun singleExpression(): String = "Hello World!" 75 | //^^^ source.kotlin meta.function.kotlin keyword.other.kotlin 76 | // ^ source.kotlin meta.function.kotlin 77 | // ^^^^^^^^^^^^^^^^ source.kotlin meta.function.kotlin entity.name.function.kotlin 78 | // ^ source.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 79 | // ^ source.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 80 | // ^^^^^^ source.kotlin meta.function.kotlin support.class.kotlin 81 | // ^ source.kotlin meta.function.kotlin keyword.operator.single-expression.kotlin 82 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 83 | // ^^^^^^^^^^^^ source.kotlin string.quoted.double.kotlin 84 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 85 | 86 | fun singleExpression(input: String = "Default") = input 87 | // ^ - keyword.operator.single-expression.kotlin 88 | // ^ keyword.operator.single-expression.kotlin -------------------------------------------------------------------------------- /test/Generic.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Generic" 2 | class Test { 3 | // ^ punctuation.bracket.angle.begin.kotlin 4 | // ^^ storage.modifier.generic.variance.kotlin 5 | // ^ meta.class.kotlin entity.name.type.class.kotlin 6 | // ^^^^^^^^^^^^ meta.class.kotlin support.class.kotlin 7 | // ^ punctuation.bracket.angle.end.kotlin 8 | fun do(input: T) { 9 | // ^ punctuation.bracket.angle.begin.kotlin 10 | // ^ meta.class.kotlin entity.name.type.class.kotlin 11 | // ^ keyword.operator.declaration.kotlin 12 | // ^^^^^^ meta.class.kotlin entity.name.type.class.kotlin 13 | // ^ punctuation.bracket.angle.end.kotlin 14 | } 15 | } 16 | 17 | val list: MutableList<*> 18 | // ^ punctuation.bracket.angle.begin.kotlin 19 | // ^ entity.name.type.generic.wildcard.kotlin 20 | // ^ punctuation.bracket.angle.end.kotlin 21 | 22 | fun test() { 23 | // ^ punctuation.bracket.angle.begin.kotlin 24 | // ^ meta.function.kotlin entity.name.type.class.kotlin 25 | // ^ punctuation.seperator.kotlin 26 | // ^ meta.function.kotlin entity.name.type.class.kotlin 27 | // ^ punctuation.bracket.angle.end.kotlin 28 | } -------------------------------------------------------------------------------- /test/Imports.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Imports" 2 | 3 | import com.google.test.ClassName as Test 4 | //^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin 5 | // ^ source.kotlin meta.import.kotlin 6 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin 7 | // ^ source.kotlin meta.import.kotlin 8 | // ^^ source.kotlin meta.import.kotlin keyword.other.kotlin 9 | // ^ source.kotlin meta.import.kotlin 10 | // ^^^^^ source.kotlin meta.import.kotlin entity.name.type 11 | 12 | import Interpreter 13 | //^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin 14 | // ^ source.kotlin meta.import.kotlin 15 | // ^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin 16 | 17 | import `Testing Module`.StringTester as STester 18 | //^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin 19 | // ^ source.kotlin meta.import.kotlin 20 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin 21 | // ^ source.kotlin meta.import.kotlin 22 | // ^^ source.kotlin meta.import.kotlin keyword.other.kotlin 23 | // ^ source.kotlin meta.import.kotlin 24 | // ^^^^^^^ source.kotlin meta.import.kotlin entity.name.type 25 | 26 | import Test.`take String as CharSequence` as take 27 | //^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin 28 | // ^ source.kotlin meta.import.kotlin 29 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin 30 | // ^^ - keyword.other.kotlin 31 | // ^ source.kotlin meta.import.kotlin 32 | // ^^ source.kotlin meta.import.kotlin keyword.other.kotlin 33 | // ^ source.kotlin meta.import.kotlin 34 | // ^^^^ source.kotlin meta.import.kotlin entity.name.type 35 | 36 | import com.google.test.CommentedClass // comment 37 | //^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin 38 | // ^ source.kotlin meta.import.kotlin 39 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin 40 | // ^^ source.kotlin punctuation.definition.comment.kotlin comment.line.double-slash.kotlin 41 | 42 | import com.google.test.CommentedClass /*comment*/ as Another 43 | //^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin 44 | // ^ source.kotlin meta.import.kotlin 45 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin 46 | // ^^ source.kotlin comment.block.kotlin punctuation.definition.comment.begin.kotlin 47 | // ^^ source.kotlin comment.block.kotlin punctuation.definition.comment.end.kotlin 48 | // ^ source.kotlin 49 | // ^^ source.kotlin keyword.operator.kotlin 50 | // ^ source.kotlin 51 | // ^^^^^^^ source.kotlin entity.name.type.class.kotlin -------------------------------------------------------------------------------- /test/Keywords.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Keywords" 2 | 3 | if (x !is String) return 4 | //^^ source.kotlin keyword.control.conditional.kotlin 5 | // ^ source.kotlin 6 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 7 | // ^^ source.kotlin meta.group.kotlin 8 | // ^^^ source.kotlin meta.group.kotlin keyword.operator.kotlin 9 | // ^ source.kotlin meta.group.kotlin 10 | // ^^^^^^ source.kotlin meta.group.kotlin support.class.kotlin 11 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 12 | // ^ source.kotlin 13 | // ^^^^^^ source.kotlin keyword.control.kotlin 14 | 15 | if (x is String && x.length > 0) { 16 | //^^ source.kotlin keyword.control.conditional.kotlin 17 | // ^ source.kotlin 18 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 19 | // ^^ source.kotlin meta.group.kotlin 20 | // ^^ source.kotlin meta.group.kotlin keyword.operator.kotlin 21 | // ^ source.kotlin meta.group.kotlin 22 | // ^^^^^^ source.kotlin meta.group.kotlin support.class.kotlin 23 | // ^ source.kotlin meta.group.kotlin 24 | // ^^ source.kotlin meta.group.kotlin keyword.operator.logical.kotlin 25 | // ^^ source.kotlin meta.group.kotlin 26 | // ^ source.kotlin meta.group.kotlin punctuation.accessor.dot.kotlin 27 | // ^^^^^^^ source.kotlin meta.group.kotlin 28 | // ^ source.kotlin meta.group.kotlin keyword.operator.comparison.kotlin 29 | // ^ source.kotlin meta.group.kotlin 30 | // ^ source.kotlin meta.group.kotlin constant.numeric.integer.kotlin 31 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 32 | // ^ source.kotlin 33 | // ^ source.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 34 | print(x.length) // x is automatically cast to String 35 | //^^^^ source.kotlin meta.block.kotlin 36 | // ^^^^^ source.kotlin meta.block.kotlin support.function.kotlin 37 | // ^ source.kotlin meta.block.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 38 | // ^ source.kotlin meta.block.kotlin meta.group.kotlin 39 | // ^ source.kotlin meta.block.kotlin meta.group.kotlin punctuation.accessor.dot.kotlin 40 | // ^^^^^^ source.kotlin meta.block.kotlin meta.group.kotlin 41 | // ^ source.kotlin meta.block.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 42 | // ^ source.kotlin meta.block.kotlin 43 | // ^^ source.kotlin meta.block.kotlin punctuation.definition.comment.kotlin comment.line.double-slash.kotlin 44 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.block.kotlin punctuation.definition.comment.kotlin 45 | } 46 | //^ source.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 47 | 48 | try { 49 | //^^^ source.kotlin keyword.control.catch-exception.kotlin 50 | // ^ source.kotlin 51 | // ^ source.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 52 | } 53 | //^ source.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 54 | catch (e: SomeException) { 55 | //^^^^^ source.kotlin keyword.control.catch-exception.kotlin 56 | // ^ source.kotlin 57 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 58 | // ^ source.kotlin meta.group.kotlin 59 | // ^ source.kotlin meta.group.kotlin keyword.operator.declaration.kotlin 60 | // ^ source.kotlin meta.group.kotlin 61 | // ^^^^^^^^^^^^^ source.kotlin meta.group.kotlin entity.name.type.class.kotlin 62 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 63 | // ^ source.kotlin 64 | // ^ source.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 65 | } 66 | //^ source.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 67 | finally { 68 | //^^^^^^^ source.kotlin keyword.control.catch-exception.kotlin 69 | // ^ source.kotlin 70 | // ^ source.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 71 | } 72 | //^ source.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 73 | 74 | // Taken from: https://github.com/Kotlin/KEEP/blob/master/notes/value-classes.md#value-interfaces 75 | value interface ImmutableList { 76 | // <--------------- source.kotlin meta.class.kotlin storage.modifier.kotlin 77 | // ^^^^^^^^^^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 78 | // ^ source.kotlin meta.class.kotlin punctuation.bracket.angle.begin.kotlin 79 | // ^ source.kotlin meta.class.kotlin entity.name.type.class.kotlin 80 | // ^ source.kotlin meta.class.kotlin punctuation.bracket.angle.end.kotlin 81 | // ^ source.kotlin meta.class.kotlin punctuation.section.group.begin.kotlin 82 | copy fun add(element: T) 83 | // ^^^^ source.kotlin meta.class.kotlin storage.type.kotlin 84 | // ^^^ source.kotlin meta.class.kotlin meta.function.kotlin keyword.other.kotlin 85 | // ^^^ source.kotlin meta.class.kotlin meta.function.kotlin entity.name.function.kotlin 86 | // ^ source.kotlin meta.class.kotlin meta.function.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 87 | // ^^^^^^^ source.kotlin meta.class.kotlin meta.function.kotlin variable.parameter.function.kotlin 88 | // ^ source.kotlin meta.class.kotlin meta.function.kotlin keyword.operator.declaration.kotlin 89 | // ^ source.kotlin meta.class.kotlin meta.function.kotlin 90 | // ^ source.kotlin meta.class.kotlin meta.function.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 91 | } 92 | // <- source.kotlin meta.class.kotlin punctuation.section.group.end.kotlin 93 | 94 | value class State( 95 | // <----------- source.kotlin meta.class.kotlin storage.modifier.kotlin 96 | // ^^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 97 | // ^ source.kotlin meta.class.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 98 | copy var lastUpdate: Instant, 99 | // ^^^^ source.kotlin meta.class.kotlin meta.parameters.kotlin storage.type.kotlin 100 | // ^^^ source.kotlin meta.class.kotlin meta.parameters.kotlin storage.type.kotlin 101 | // ^^^^^^^^^^ source.kotlin meta.class.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 102 | // ^ source.kotlin meta.class.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 103 | // ^^^^^^^ source.kotlin meta.class.kotlin meta.parameters.kotlin entity.name.type.class.kotlin 104 | // ^ source.kotlin meta.class.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 105 | ) 106 | // <- source.kotlin meta.class.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin -------------------------------------------------------------------------------- /test/Objects.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Object" 2 | 3 | addListener(object : AnimatorListenerAdapter() { 4 | // ^ meta.group.kotlin punctuation.section.group.begin.kotlin 5 | // ^^^^^^ meta.group.kotlin storage.type.kotlin 6 | // ^ meta.group.kotlin 7 | // ^ meta.group.kotlin keyword.operator.declaration.kotlin 8 | // ^ meta.group.kotlin 9 | // ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.kotlin entity.name.type.class.kotlin 10 | // ^ meta.group.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 11 | // ^ meta.group.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 12 | // ^ meta.group.kotlin 13 | // ^ meta.group.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 14 | override fun onAnimationEnd(animation: Animator) { 15 | //^^^^ meta.group.kotlin meta.block.kotlin 16 | // ^^^^^^^^ meta.group.kotlin meta.block.kotlin storage.modifier.kotlin 17 | // ^ meta.group.kotlin meta.block.kotlin 18 | // ^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin keyword.other.kotlin 19 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin 20 | // ^^^^^^^^^^^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin entity.name.function.kotlin 21 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 22 | // ^^^^^^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 23 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 24 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin 25 | // ^^^^^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin entity.name.type.class.kotlin 26 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 27 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin 28 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 29 | 30 | } 31 | //^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.block.kotlin 32 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 33 | }) 34 | //^ meta.group.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 35 | // ^ meta.group.kotlin punctuation.section.group.end.kotlin 36 | 37 | data object Foo 38 | // <------- source.kotlin meta.class.kotlin storage.modifier.kotlin 39 | // ^^^ source.kotlin meta.class.kotlin 40 | -------------------------------------------------------------------------------- /test/Package.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Package" 2 | 3 | package com.nishtahir.kotlin 4 | //^^^^^^^ source.kotlin keyword.other.kotlin 5 | // ^ source.kotlin 6 | // ^^^^^^^^^^^^^^^^^^^^^ source.kotlin entity.name.package.kotlin -------------------------------------------------------------------------------- /test/Types.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Types" 2 | 3 | val test: () -> Unit = {} 4 | //^^^ source.kotlin storage.type.kotlin 5 | // ^^^^^ source.kotlin 6 | // ^ source.kotlin keyword.operator.declaration.kotlin 7 | // ^ source.kotlin 8 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 9 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 10 | // ^ source.kotlin 11 | // ^^ keyword.operator.type.function.kotlin 12 | // ^ source.kotlin 13 | // ^^^^ source.kotlin support.class.kotlin 14 | // ^ source.kotlin 15 | // ^ source.kotlin keyword.operator.assignment.kotlin 16 | // ^ source.kotlin 17 | // ^ source.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 18 | // ^ source.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 19 | 20 | val type: Type? = Type() 21 | //^^^ source.kotlin storage.type.kotlin 22 | // ^^^^^ source.kotlin 23 | // ^ source.kotlin keyword.operator.declaration.kotlin 24 | // ^ source.kotlin 25 | // ^^^^ source.kotlin entity.name.type.class.kotlin 26 | // ^^ source.kotlin 27 | // ^ source.kotlin keyword.operator.assignment.kotlin 28 | // ^ source.kotlin 29 | // ^^^^ source.kotlin entity.name.type.class.kotlin 30 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 31 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/VariableDeclaration.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Variable Declaration" 2 | var x = 9 3 | // <--- storage.type.kotlin 4 | // ^ keyword.operator.assignment.kotlin 5 | // ^ constant.numeric.integer.kotlin 6 | 7 | const val CONSTANT = 99 8 | // <---- storage.modifier.kotlin 9 | // ^^^ storage.type.kotlin 10 | 11 | val items = listOf("apple", "banana") 12 | // ^^^^^^ support.function.kotlin 13 | // ^ punctuation.section.group.begin.kotlin 14 | // ^ string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 15 | // ^^^^^ string.quoted.double.kotlin 16 | // ^ string.quoted.double.kotlin punctuation.definition.string.end.kotlin 17 | // ^ punctuation.seperator.kotlin 18 | // ^ string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 19 | // ^^^^^^ string.quoted.double.kotlin 20 | // ^ string.quoted.double.kotlin punctuation.definition.string.end.kotlin 21 | // ^ punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/annotations.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Annotations" 2 | 3 | @file:JvmName("Foo") 4 | //<------------- meta.annotation.kotlin 5 | // ^ punctuation.section.group.begin.kotlin 6 | // ^ meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 7 | // ^^^ meta.group.kotlin string.quoted.double.kotlin 8 | // ^ meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 9 | // ^ meta.group.kotlin punctuation.section.group.end.kotlin 10 | 11 | data class Response(@SerializedName("param1") val param1: String, 12 | // ^^^^^^^^^^^^^^^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin 13 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.begin.kotlin 14 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 15 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin 16 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 17 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.end.kotlin 18 | // ^^^ meta.class.kotlin meta.parameters.kotlin storage.type.kotlin 19 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 20 | // ^ meta.class.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 21 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin support.class.kotlin 22 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 23 | 24 | @SerializedName("param2") val param2: String, 25 | // ^^^^^^^^^^^^^^^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin 26 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.begin.kotlin 27 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 28 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin 29 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 30 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.end.kotlin 31 | // ^^^ meta.class.kotlin meta.parameters.kotlin storage.type.kotlin 32 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 33 | // ^ meta.class.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 34 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin support.class.kotlin 35 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 36 | @SerializedName("param3") val param3: String) { 37 | // ^^^^^^^^^^^^^^^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin 38 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.begin.kotlin 39 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 40 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin 41 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 42 | // ^ meta.class.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.end.kotlin 43 | // ^^^ meta.class.kotlin meta.parameters.kotlin storage.type.kotlin 44 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 45 | // ^ meta.class.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 46 | // ^^^^^^ meta.class.kotlin meta.parameters.kotlin support.class.kotlin 47 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 48 | // ^ meta.class.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 49 | } 50 | 51 | class Example { 52 | @set:Inject 53 | // ^^^^^^^^^^^ meta.annotation.kotlin 54 | var collaborator: Collaborator 55 | } 56 | 57 | 58 | @MultiLineAnnotation( 59 | //^^^^^^^^^^^^^^^^^^^^ meta.annotation.kotlin 60 | // ^ meta.annotation.kotlin punctuation.definition.arguments.begin.kotlin 61 | "One", 62 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 63 | // ^^^ meta.annotation.kotlin string.quoted.double.kotlin 64 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 65 | // ^ meta.annotation.kotlin punctuation.seperator.kotlin 66 | "Two", 67 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 68 | // ^^^ meta.annotation.kotlin string.quoted.double.kotlin 69 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 70 | // ^ meta.annotation.kotlin punctuation.seperator.kotlin 71 | "Three", 72 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 73 | // ^^^^^ meta.annotation.kotlin string.quoted.double.kotlin 74 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 75 | // ^ meta.annotation.kotlin punctuation.seperator.kotlin 76 | "Four", 77 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 78 | // ^^^^ meta.annotation.kotlin string.quoted.double.kotlin 79 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 80 | // ^ meta.annotation.kotlin punctuation.seperator.kotlin 81 | "Five", 82 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 83 | // ^^^^ meta.annotation.kotlin string.quoted.double.kotlin 84 | // ^ meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 85 | // ^ meta.annotation.kotlin punctuation.seperator.kotlin 86 | ) 87 | //^ meta.annotation.kotlin punctuation.definition.arguments.end.kotlin -------------------------------------------------------------------------------- /test/literals.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Literals" 2 | 3 | val test = true 4 | // ^^^ storage.type.kotlin 5 | // ^ keyword.operator.assignment.kotlin 6 | // ^^^^ constant.language.boolean.kotlin 7 | val test = false 8 | // ^^^ storage.type.kotlin 9 | // ^ keyword.operator.assignment.kotlin 10 | // ^^^^ constant.language.boolean.kotlin 11 | 12 | val oneMillion = 1_000_000 13 | //^^^ storage.type.kotlin 14 | // ^^^^^^^^^^^^ source.kotlin 15 | // ^ keyword.operator.assignment.kotlin 16 | // ^ source.kotlin 17 | // ^^^^^^^^^ constant.numeric.integer.kotlin 18 | val creditCardNumber = 1234_5678_9012_3456L 19 | //^^^ storage.type.kotlin 20 | // ^^^^^^^^^^^^^^^^^^ source.kotlin 21 | // ^ keyword.operator.assignment.kotlin 22 | // ^ source.kotlin 23 | // ^^^^^^^^^^^^^^^^^^^^ constant.numeric.integer.kotlin 24 | val socialSecurityNumber = 999_99_9999L 25 | //^^^ storage.type.kotlin 26 | // ^^^^^^^^^^^^^^^^^^^^^^ source.kotlin 27 | // ^ keyword.operator.assignment.kotlin 28 | // ^ source.kotlin 29 | // ^^^^^^^^^^^^ constant.numeric.integer.kotlin 30 | val hexBytes = 0xFF_EC_DE_5E 31 | //^^^ storage.type.kotlin 32 | // ^^^^^^^^^^ source.kotlin 33 | // ^ keyword.operator.assignment.kotlin 34 | // ^ source.kotlin 35 | // ^^^^^^^^^^^^^ constant.numeric.hex.kotlin 36 | val float = 0.043_331F 37 | //^^^ storage.type.kotlin 38 | // ^^^^^^^ source.kotlin 39 | // ^ keyword.operator.assignment.kotlin 40 | // ^ source.kotlin 41 | // ^^^^^^^^^^ constant.numeric.float.kotlin 42 | val bytes = 0b11010010_01101001_10010100_10010010 43 | //^^^ storage.type.kotlin 44 | // ^^^^^^^ source.kotlin 45 | // ^ keyword.operator.assignment.kotlin 46 | // ^ source.kotlin 47 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.binary.kotlin 48 | 49 | 50 | val myString = "Hey there!" 51 | //^^^ source.kotlin storage.type.kotlin 52 | // ^^^^^^^^^^ source.kotlin 53 | // ^ source.kotlin keyword.operator.assignment.kotlin 54 | // ^ source.kotlin 55 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 56 | // ^^^^^^^^^^ source.kotlin string.quoted.double.kotlin 57 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 58 | println("myString = $myString") 59 | //^^^^^^^ source.kotlin support.function.kotlin 60 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 61 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 62 | // ^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.group.kotlin string.quoted.double.kotlin 63 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 64 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 65 | 66 | val myString = "Hey there!\n" 67 | //^^^ source.kotlin storage.type.kotlin 68 | // ^^^^^^^^^^ source.kotlin 69 | // ^ source.kotlin keyword.operator.assignment.kotlin 70 | // ^ source.kotlin 71 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 72 | // ^^^^^^^^^^ source.kotlin string.quoted.double.kotlin 73 | // ^^ source.kotlin string.quoted.double.kotlin constant.character.escape.kotlin 74 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 75 | 76 | val myString = """ 77 | //^^^ source.kotlin storage.type.kotlin 78 | // ^^^^^^^^^^ source.kotlin 79 | // ^ source.kotlin keyword.operator.assignment.kotlin 80 | // ^ source.kotlin 81 | // ^^^ source.kotlin string.quoted.triple.kotlin punctuation.definition.string.begin.kotlin 82 | for (character in "Hey!") 83 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin string.quoted.triple.kotlin 84 | println(character) 85 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin string.quoted.triple.kotlin 86 | """ 87 | //^^^ source.kotlin string.quoted.triple.kotlin punctuation.definition.string.end.kotlin 88 | 89 | println("Length of s1 string is ${s1.length}.") 90 | //^^^^^^^ source.kotlin support.function.kotlin 91 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 92 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 93 | // ^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.group.kotlin string.quoted.double.kotlin 94 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin entity.string.template.element.kotlin 95 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin entity.string.template.element.kotlin punctuation.section.block.begin.kotlin 96 | // ^^ source.kotlin meta.group.kotlin string.quoted.double.kotlin entity.string.template.element.kotlin 97 | // ^^^^^^ source.kotlin meta.group.kotlin string.quoted.double.kotlin entity.string.template.element.kotlin 98 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin entity.string.template.element.kotlin punctuation.section.block.end.kotlin 99 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin 100 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 101 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 102 | 103 | val test = null 104 | //^^^ source.kotlin storage.type.kotlin 105 | // ^^^^^^ source.kotlin 106 | // ^ source.kotlin keyword.operator.assignment.kotlin 107 | // ^ source.kotlin 108 | // ^^^^ source.kotlin constant.language.null.kotlin 109 | 110 | val ubyte: UByte = 1u 111 | //^^^ source.kotlin storage.type.kotlin 112 | // ^^^^^^ source.kotlin 113 | // ^ source.kotlin keyword.operator.declaration.kotlin 114 | // ^^^^^ source.kotlin support.class.kotlin 115 | // ^ source.kotlin keyword.operator.assignment.kotlin 116 | // ^^ constant.numeric.integer.kotlin 117 | 118 | val ushort: UShort = 1u 119 | //^^^ source.kotlin storage.type.kotlin 120 | // ^^^^^^^ source.kotlin 121 | // ^ source.kotlin keyword.operator.declaration.kotlin 122 | // ^^^^^^ source.kotlin support.class.kotlin 123 | // ^ source.kotlin keyword.operator.assignment.kotlin 124 | // ^^ constant.numeric.integer.kotlin 125 | 126 | val uint: UInt = 1u 127 | //^^^ source.kotlin storage.type.kotlin 128 | // ^^^^^ source.kotlin 129 | // ^ source.kotlin keyword.operator.declaration.kotlin 130 | // ^^^^ source.kotlin support.class.kotlin 131 | // ^ source.kotlin keyword.operator.assignment.kotlin 132 | // ^^ constant.numeric.integer.kotlin 133 | 134 | val ulong: ULong = 42u 135 | //^^^ source.kotlin storage.type.kotlin 136 | // ^^^^^^ source.kotlin 137 | // ^ source.kotlin keyword.operator.declaration.kotlin 138 | // ^^^^^ source.kotlin support.class.kotlin 139 | // ^ source.kotlin keyword.operator.assignment.kotlin 140 | // ^^ constant.numeric.integer.kotlin 141 | 142 | val hexUlong = 0xFFFF_FFFF_FFFFu 143 | //^^^ source.kotlin storage.type.kotlin 144 | // ^^^^^^^^^ source.kotlin 145 | // ^ source.kotlin keyword.operator.assignment.kotlin 146 | // ^^^^^^^^^^^^^^^^^ constant.numeric.hex.kotlin 147 | 148 | listOf(0b0u, 0b1U, 0b10uL, 0b11UL, 4u, 5U, 6uL, 7UL, 0x8u, 0x9U, 0xauL, 0xbUL) 149 | //^^^^^^ source.kotlin support.function.kotlin 150 | // ^^^^ constant.numeric.binary.kotlin 151 | // ^^^^ constant.numeric.binary.kotlin 152 | // ^^^^^ constant.numeric.binary.kotlin 153 | // ^^^^^ constant.numeric.binary.kotlin 154 | // ^^ constant.numeric.integer.kotlin 155 | // ^^ constant.numeric.integer.kotlin 156 | // ^^^ constant.numeric.integer.kotlin 157 | // ^^^ constant.numeric.integer.kotlin 158 | // ^^^^ constant.numeric.hex.kotlin 159 | // ^^^^ constant.numeric.hex.kotlin 160 | // ^^^^^ constant.numeric.hex.kotlin 161 | // ^^^^^ constant.numeric.hex.kotlin 162 | 163 | val unicodeEscape = "\u3400" 164 | //^^^ source.kotlin storage.type.kotlin 165 | // ^^^^^^^^^^^^^^^ source.kotlin 166 | // ^ source.kotlin keyword.operator.assignment.kotlin 167 | // ^ source.kotlin 168 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 169 | // ^^^^^^ source.kotlin string.quoted.double.kotlin constant.character.escape.unicode.kotlin 170 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 171 | 172 | foo('"') 173 | //^^^ source.kotlin 174 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 175 | // ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.begin.kotlin 176 | // ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin 177 | // ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.end.kotlin 178 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 179 | 180 | foo('\'') 181 | //^^^ source.kotlin 182 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 183 | // ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.begin.kotlin 184 | // ^^ source.kotlin meta.group.kotlin string.quoted.single.kotlin constant.character.escape.kotlin 185 | // ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.end.kotlin 186 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 187 | 188 | foo(""""."""") 189 | //^^^ source.kotlin 190 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 191 | // ^^^ source.kotlin meta.group.kotlin string.quoted.triple.kotlin punctuation.definition.string.begin.kotlin 192 | // ^^^ source.kotlin meta.group.kotlin string.quoted.triple.kotlin 193 | // ^^^ source.kotlin meta.group.kotlin string.quoted.triple.kotlin punctuation.definition.string.end.kotlin 194 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 195 | 196 | foo("'Hello ' World'") 197 | //^^^ source.kotlin 198 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 199 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 200 | // ^^^^^^^^^^^^^^^ source.kotlin meta.group.kotlin string.quoted.double.kotlin 201 | // ^ source.kotlin meta.group.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 202 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/regression/12.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "@ in string templates" 2 | val name = "More specific name: `${this@SomeClass.id}`" 3 | //<--- source.kotlin storage.type.kotlin 4 | // ^ source.kotlin keyword.operator.assignment.kotlin 5 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 6 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin string.quoted.double.kotlin 7 | // ^^^^^^^^^^^^^^^^ -meta.declaration.annotation.kotlin 8 | // ^ source.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 9 | -------------------------------------------------------------------------------- /test/regression/15.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Greater than or equal should not be treated as generic" 2 | 3 | if (num <= 10) { 4 | //<-- source.kotlin keyword.control.conditional.kotlin 5 | // ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 6 | // ^^ keyword.operator.comparison.kotlin 7 | // ^ meta.group.kotlin punctuation.section.group.end.kotlin 8 | // ^ punctuation.section.group.begin.kotlin 9 | errors["num"] = "Something is wrong" 10 | // ^ punctuation.section.brackets.begin.kotlin 11 | // ^ punctuation.definition.string.begin.kotlin 12 | // ^^^ string.quoted.double.kotlin 13 | // ^ punctuation.definition.string.end.kotlin 14 | // ^ punctuation.section.brackets.end.kotlin 15 | // ^ keyword.operator.assignment.kotlin 16 | // ^ punctuation.definition.string.begin.kotlin 17 | // ^^^^^^^^^^^^^^^^^ string.quoted.double.kotlin 18 | // ^ punctuation.definition.string.end.kotlin 19 | } 20 | //<- punctuation.section.group.end.kotlin 21 | -------------------------------------------------------------------------------- /test/regression/19.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" " < and > in generics are incorrectly scoped as comparison operators #19 " 2 | 3 | // TODO fill out appropriate scope for generics params 4 | 5 | fun main(@NonNull args: Array) { 6 | // ^ -keyword.operator.comparison.kotlin 7 | // ^ -keyword.operator.comparison.kotlin 8 | } -------------------------------------------------------------------------------- /test/regression/20.test.kt: -------------------------------------------------------------------------------- 1 | # SYNTAX TEST "source.kotlin" "Kotlin nested multi-line comments syntax-highlighting" 2 | 3 | /* 4 | #^^ source.kotlin comment.block.kotlin punctuation.definition.comment.begin.kotlin 5 | This is inside the comment 6 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin comment.block.kotlin 7 | /* 8 | #^^^^ source.kotlin comment.block.kotlin 9 | # ^^ source.kotlin comment.block.kotlin 10 | You can insert something here. 11 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin comment.block.kotlin 12 | */ 13 | #^^^^ source.kotlin comment.block.kotlin 14 | # ^^ source.kotlin comment.block.kotlin 15 | This is a comment since the nested comment is parsed correctly. 16 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin comment.block.kotlin 17 | */ 18 | #^^ source.kotlin comment.block.kotlin punctuation.definition.comment.end.kotlin -------------------------------------------------------------------------------- /test/regression/21.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Object expressions fail to highlight code blocks" 2 | 3 | addListener(object : AnimatorListenerAdapter() { 4 | // ^ meta.group.kotlin punctuation.section.group.begin.kotlin 5 | // ^^^^^^ meta.group.kotlin storage.type.kotlin 6 | // ^ meta.group.kotlin 7 | // ^ meta.group.kotlin keyword.operator.declaration.kotlin 8 | // ^ meta.group.kotlin 9 | // ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.kotlin entity.name.type.class.kotlin 10 | // ^ meta.group.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 11 | // ^ meta.group.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 12 | // ^ meta.group.kotlin 13 | // ^ meta.group.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 14 | override fun onAnimationEnd(animation: Animator) { 15 | //^^^^ meta.group.kotlin meta.block.kotlin 16 | // ^^^^^^^^ meta.group.kotlin meta.block.kotlin storage.modifier.kotlin 17 | // ^ meta.group.kotlin meta.block.kotlin 18 | // ^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin keyword.other.kotlin 19 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin 20 | // ^^^^^^^^^^^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin entity.name.function.kotlin 21 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 22 | // ^^^^^^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 23 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 24 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin 25 | // ^^^^^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin entity.name.type.class.kotlin 26 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 27 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin 28 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 29 | 30 | } 31 | //^^^^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.block.kotlin 32 | // ^ meta.group.kotlin meta.block.kotlin meta.function.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 33 | }) 34 | //^ meta.group.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 35 | // ^ meta.group.kotlin punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/regression/23.test.kt: -------------------------------------------------------------------------------- 1 | ## SYNTAX TEST "source.kotlin" "Comments in function parameters are not scoped correctly" 2 | 3 | fun setNodeIpAddress( 4 | ##^^^ meta.function.kotlin keyword.other.kotlin 5 | ## ^ meta.function.kotlin 6 | ## ^^^^^^^^^^^^^^^^ meta.function.kotlin entity.name.function.kotlin 7 | ## ^ meta.function.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 8 | @Param("str") value: String, 9 | ##^^ meta.function.kotlin meta.parameters.kotlin 10 | ## ^^^^^^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin 11 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.begin.kotlin 12 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 13 | ## ^^^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin 14 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 15 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.end.kotlin 16 | ## ^ meta.function.kotlin meta.parameters.kotlin 17 | ## ^^^^^ meta.function.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 18 | ## ^ meta.function.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 19 | ## ^ meta.function.kotlin meta.parameters.kotlin 20 | ## ^^^^^^ meta.function.kotlin meta.parameters.kotlin support.class.kotlin 21 | ## ^ meta.function.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 22 | // @Param("str) value: String, 23 | ##^^ meta.function.kotlin meta.parameters.kotlin 24 | ## ^^ meta.function.kotlin meta.parameters.kotlin punctuation.definition.comment.kotlin comment.line.double-slash.kotlin 25 | ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.kotlin meta.parameters.kotlin punctuation.definition.comment.kotlin 26 | @Param("str") value: String, 27 | ##^^ meta.function.kotlin meta.parameters.kotlin 28 | ## ^^^^^^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin 29 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.begin.kotlin 30 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 31 | ## ^^^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin 32 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 33 | ## ^ meta.function.kotlin meta.parameters.kotlin meta.annotation.kotlin punctuation.definition.arguments.end.kotlin 34 | ## ^ meta.function.kotlin meta.parameters.kotlin 35 | ## ^^^^^ meta.function.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 36 | ## ^ meta.function.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 37 | ## ^ meta.function.kotlin meta.parameters.kotlin 38 | ## ^^^^^^ meta.function.kotlin meta.parameters.kotlin support.class.kotlin 39 | ## ^ meta.function.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 40 | ) 41 | ##^ meta.function.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin -------------------------------------------------------------------------------- /test/regression/26.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Double quotes in character value and quadrupel double quotes" 2 | 3 | foo('"') 4 | // ^ -string.quoted.double.kotlin 5 | 6 | val same = '"' == '"' 7 | // ^ -string.quoted.double.kotlin 8 | // ^ -string.quoted.double.kotlin 9 | 10 | foo(""""."""") 11 | //^^^^ source.kotlin 12 | // ^ -punctuation.definition.string.end.kotlin 13 | // ^ -punctuation.definition.string.begin.kotlin 14 | // ^^ -string.quoted.double.kotlin -------------------------------------------------------------------------------- /test/regression/4.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Comments after field" 2 | 3 | data class A( 4 | // <---------- meta.class.kotlin storage.modifier.kotlin 5 | // ^ meta.class.kotlin entity.name.class.kotlin 6 | // ^ meta.class.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 7 | val field: Int // This is a comment, when is not a keyword 8 | //^^^ meta.class.kotlin meta.parameters.kotlin storage.type.kotlin 9 | // ^^^^^ meta.class.kotlin meta.parameters.kotlin variable.parameter.function.kotlin 10 | // ^ meta.class.kotlin meta.parameters.kotlin keyword.operator.declaration.kotlin 11 | // ^^^ meta.class.kotlin meta.parameters.kotlin support.class.kotlin 12 | // ^^ punctuation.definition.comment.kotlin comment.line.double-slash.kotlin 13 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ punctuation.definition.comment.kotlin 14 | // ^ -keyword.operator.arithmetic.kotlin 15 | // ^ -keyword.operator.arithmetic.kotlin 16 | ) 17 | //<- meta.class.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 18 | 19 | // This is a comment, when is not a keyword -------------------------------------------------------------------------------- /test/regression/42.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Camel cased variable declaration should not have class" 2 | 3 | camelCased?.let { print(it) } 4 | // ^^^^^ -entity.name.type.class.kotlin 5 | // ^^ punctuation.accessor.dot.safe.kotlin 6 | // ^^^ support.function.kotlin 7 | // ^ meta.block.kotlin punctuation.section.group.begin.kotlin 8 | // ^ meta.block.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 9 | // ^ meta.block.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 10 | // ^ meta.block.kotlin punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/regression/44.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Keywords" 2 | 3 | val test = !isC 4 | //^^^ source.kotlin storage.type.kotlin 5 | // ^^^^^^ source.kotlin 6 | // ^ source.kotlin keyword.operator.assignment.kotlin 7 | // ^ keyword.operator.logical.kotlin 8 | // ^^^ source.kotlin - keyword.operator.kotlin 9 | 10 | val test2 =!isC 11 | // ^ keyword.operator.assignment.kotlin 12 | // ^^^ - keyword.operator.kotlin 13 | 14 | if (test3!is String) return 15 | // ^^^ source.kotlin meta.group.kotlin keyword.operator.kotlin 16 | -------------------------------------------------------------------------------- /test/regression/47.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Keywords" 2 | 3 | suspend fun suspendFunction() { 4 | // <------- source.kotlin storage.modifier.kotlin 5 | // ^^^ source.kotlin meta.function.kotlin 6 | // ^^^^^^^^^^^^^^^ source.kotlin meta.function.kotlin entity.name.function.kotlin - storage.modifier.kotlin 7 | } 8 | 9 | explicitSuspendCall(suspend { delay(10) }) 10 | // ^^^^^^^ - storage.modifier.kotlin -------------------------------------------------------------------------------- /test/regression/50.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Soft keywords should not be parsed as modifiers" 2 | 3 | fun foo(expect: String) {} 4 | // ^^^^^^ - storage.modifier.kotlin 5 | 6 | val expect = "42" 7 | // ^^^^^^ - storage.modifier.kotlin 8 | 9 | foo(expect = expect) 10 | // ^^^^^^ - storage.modifier.kotlin 11 | // ^^^^^^ - storage.modifier.kotlin 12 | 13 | expect class Klass(val expect : Int) 14 | // ^^^^^^ - storage.modifier.kotlin 15 | 16 | expect class A 17 | // <------ storage.modifier.kotlin 18 | 19 | Klass(expect = 42) 20 | // ^^^^^^ - storage.modifier.kotlin 21 | 22 | expect 23 | // <------ - storage.modifier.kotlin 24 | 25 | expect + anotherVar 26 | // <------ - storage.modifier.kotlin 27 | 28 | expect 29 | // ^^^^^^ - storage.modifier.kotlin 30 | 31 | stes += expect 32 | // ^^^^^^ - storage.modifier.kotlin 33 | 34 | expect += 1 35 | // <------ - storage.modifier.kotlin 36 | 37 | fun formatString(source: String, vararg args: Any): String 38 | // ^^^^^^ storage.modifier.kotlin 39 | 40 | val vararg : String = "" 41 | // ^^^^^^ - storage.modifier.kotlin -------------------------------------------------------------------------------- /test/regression/57.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Keywords" 2 | 3 | "outside string ${ /*Comment*/ "inside string ${ "string in code block" } " + someFunction() }" 4 | # <- string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 5 | # ^^ string.quoted.double.kotlin entity.string.template.element.kotlin punctuation.section.block.start.kotlin 6 | # ^^ string.quoted.double.kotlin entity.string.template.element.kotlin comment.block.kotlin punctuation.definition.comment.begin.kotlin 7 | # ^^^^^^^ string.quoted.double.kotlin entity.string.template.element.kotlin comment.block.kotlin 8 | # ^^ string.quoted.double.kotlin entity.string.template.element.kotlin comment.block.kotlin punctuation.definition.comment.end.kotlin 9 | # ^ string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 10 | # ^^ string.quoted.double.kotlin entity.string.template.element.kotlin punctuation.section.block.start.kotlin 11 | # ^ string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 12 | # ^ string.quoted.double.kotlin punctuation.definition.string.end.kotlin 13 | # ^ string.quoted.double.kotlin entity.string.template.element.kotlin punctuation.section.block.end.kotlin 14 | # ^ string.quoted.double.kotlin punctuation.definition.string.end.kotlin 15 | # ^ keyword.operator.increment-decrement.kotlin kotlin 16 | # ^ punctuation.section.group.begin.kotlin 17 | # ^ punctuation.section.group.end.kotlin 18 | # ^ string.quoted.double.kotlin entity.string.template.element.kotlin punctuation.section.block.end.kotlin 19 | # ^ string.quoted.double.kotlin punctuation.definition.string.end.kotlin 20 | 21 | """${someFunction()}""" 22 | # <--- string.quoted.triple.kotlin punctuation.definition.string.begin.kotlin 23 | # ^^string.quoted.triple.kotlin entity.string.template.element.kotlin punctuation.section.block.start.kotlin 24 | # ^ string.quoted.triple.kotlin entity.string.template.element.kotlin punctuation.section.block.end.kotlin 25 | # ^^^ string.quoted.triple.kotlin punctuation.definition.string.end.kotlin -------------------------------------------------------------------------------- /test/regression/59.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Double slash in strings is sometimes detected as a comment" 2 | 3 | >class Rawkuma : WPMangaStream("Rawkuma", "https://rawkuma.com/", "ja") { 4 | #^^^^^ source.kotlin meta.class.kotlin storage.modifier.kotlin 5 | # ^ source.kotlin meta.class.kotlin 6 | # ^^^^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 7 | # ^^^ source.kotlin meta.class.kotlin 8 | # ^^^^^^^^^^^^^ source.kotlin meta.class.kotlin entity.name.type.class.kotlin 9 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin punctuation.section.group.begin.kotlin punctuation.definition.parameters.begin.kotlin 10 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 11 | # ^^^^^^^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin 12 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 13 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 14 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin 15 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 16 | # ^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin 17 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 18 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin punctuation.seperator.kotlin 19 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin 20 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin punctuation.definition.string.begin.kotlin 21 | # ^^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin 22 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin string.quoted.double.kotlin punctuation.definition.string.end.kotlin 23 | # ^ source.kotlin meta.class.kotlin meta.parameters.kotlin punctuation.section.group.end.kotlin punctuation.definition.parameters.end.kotlin 24 | # ^ source.kotlin meta.class.kotlin 25 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 26 | > private val rateLimitInterceptor = RateLimitInterceptor(4) 27 | #^^^^ source.kotlin meta.class.kotlin meta.block.kotlin 28 | # ^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin storage.modifier.kotlin 29 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin 30 | # ^^^ source.kotlin meta.class.kotlin meta.block.kotlin storage.type.kotlin 31 | # ^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin 32 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin keyword.operator.assignment.kotlin 33 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin 34 | # ^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin entity.name.type.class.kotlin 35 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin 36 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.group.kotlin constant.numeric.integer.kotlin 37 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.group.kotlin punctuation.section.group.end.kotlin 38 | >} 39 | #^ source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/regression/63.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Recognize inner modifier" 2 | 3 | >class Outer { 4 | #^^^^^ source.kotlin meta.class.kotlin storage.modifier.kotlin 5 | # ^ source.kotlin meta.class.kotlin 6 | # ^^^^^ source.kotlin meta.class.kotlin entity.name.class.kotlin 7 | # ^ source.kotlin meta.class.kotlin 8 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 9 | > inner class Inner {} 10 | #^^^^ source.kotlin meta.class.kotlin meta.block.kotlin 11 | # ^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin storage.modifier.kotlin 12 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin 13 | # ^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin storage.modifier.kotlin 14 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin 15 | # ^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin entity.name.class.kotlin 16 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin 17 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.begin.kotlin 18 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 19 | >} 20 | #^ source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.end.kotlin -------------------------------------------------------------------------------- /test/regression/67.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Triple-quoted strings do not ignore backslash before closing sequence" 2 | 3 | >val cmd = """bash -c "sudo -u test bash --noprofile --norc -euo pipefail "\""" 4 | #^^^ source.kotlin storage.type.kotlin 5 | # ^^^^^ source.kotlin 6 | # ^ source.kotlin keyword.operator.assignment.kotlin 7 | # ^ source.kotlin 8 | # ^^^ source.kotlin string.quoted.triple.kotlin punctuation.definition.string.begin.kotlin 9 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin string.quoted.triple.kotlin 10 | # ^^^ source.kotlin string.quoted.triple.kotlin punctuation.definition.string.end.kotlin 11 | >val num = 1 12 | #^^^ source.kotlin storage.type.kotlin 13 | # ^^^^^ source.kotlin 14 | # ^ source.kotlin keyword.operator.assignment.kotlin 15 | # ^ source.kotlin 16 | # ^ source.kotlin constant.numeric.integer.kotlin 17 | > -------------------------------------------------------------------------------- /test/regression/71.test.kt: -------------------------------------------------------------------------------- 1 | // SYNTAX TEST "source.kotlin" "Add Data Object" 2 | 3 | > data object Error : ProfileScreenState 4 | #^^^^ source.kotlin meta.class.kotlin meta.block.kotlin 5 | # ^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin storage.modifier.kotlin 6 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin 7 | # ^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin entity.name.class.kotlin 8 | # ^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin 9 | # ^^^^^^^^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin entity.name.type.class.kotlin 10 | > data object Loading : ProfileScreenState 11 | #^^^^ source.kotlin meta.class.kotlin meta.block.kotlin 12 | # ^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin storage.modifier.kotlin 13 | # ^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin 14 | # ^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin entity.name.class.kotlin 15 | # ^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin 16 | # ^^^^^^^^^^^^^^^^^^ source.kotlin meta.class.kotlin meta.block.kotlin meta.class.kotlin entity.name.type.class.kotlin 17 | >} 18 | #^ source.kotlin meta.class.kotlin meta.block.kotlin punctuation.section.group.end.kotlin 19 | > --------------------------------------------------------------------------------