Swift.tmLanguage is a TextMate language grammar for the Swift programming language. It defines regex-based parsing rules so that code renderers can highlight Swift code using a semantic color scheme.
func foo<T>(x: T) async throws -> Int where T: Equatable {}
let int = /(?x)\\N\{(?:U\+[0-9a-fA-F]{1,8} | [\s\w-]+)\}/This grammar is used for syntax highlighting by several popular projects, including:
- GitHub — via Linguist
- Visual Studio Code — as part of the built-in extension for basic language support, not in the full-featured
vscode-swiftextension
The language grammar is available in three formats:
- Swift.tmLanguage.yaml — the canonical copy intended for human editing
- Swift.tmLanguage.json — generated from the YAML
- Swift.tmLanguage — generated from the JSON
-
Run
yarn installto install dependencies. -
After making changes to the YAML grammar, run
yarn buildto regenerate the.tmLanguage.jsonand.tmLanguagefiles. -
To test the grammar in VS Code, press F5 to load the current version of the
.tmLanguagein a new window. After eachyarn build, reload the window to load the updated.tmLanguage. (If you have thevscode-swiftextension installed, you'll need to disable it so it doesn't override the scopes provided by the.tmLanguagegrammar.)
The Swift grammar was developed for years at textmate/swift.tmbundle, which is no longer actively maintained. Development of the grammar continues here.
This grammar is maintained by @jtbandes as a passion project. If you'd like to support past and future development, please consider making a donation. 💖
This project is licensed under the terms of the MIT license.