An incremental parser generator and parsing library that builds concrete syntax trees and updates them as source files are edited.
swiftlang/swift-syntax
A Swift library set for parsing, inspecting, generating and transforming Swift source code as a source-accurate syntax tree.
- Stars
- 3,712
- Forks
- 562
- Open issues
- 180
- Last commit
- 6 hours ago
What is it?
swift-syntax is a set of Swift libraries that work on a source-accurate tree representation of Swift source code, called the SwiftSyntax tree. Tools that need to read or rewrite Swift code can build on this tree instead of handling raw text.
The SwiftSyntax tree is the foundation of Swift's macro system: macro expansion nodes are represented as SwiftSyntax nodes, and a macro generates a SwiftSyntax tree that is inserted into the source file. The package is distributed through Swift Package Manager and Xcode, and also offers an experimental Bazel build configuration.
Releases are aligned with Swift language and tooling versions, so a major version such as 509 corresponds to Swift 5.9. Example usages are provided in the repository, and the tree can be explored interactively with a community AST explorer website.
Key features
- 01Parses Swift source into a source-accurate syntax tree.
- 02Provides libraries for inspecting and traversing the tree.
- 03Supports building and modifying syntax nodes to generate Swift code.
- 04Serves as the basis for Swift macro expansion.
- 05Installable via Swift Package Manager, Xcode, or Bazel.
Use cases
- Writing Swift macros that generate code at compile time.
- Building linters, formatters or refactoring tools for Swift code.
- Automatically rewriting or code-generating Swift source files.
Quick start
- 1
Add the swift-syntax package to your Package.swift dependencies
dependencies: [ .package(url: "https://github.com/swiftlang/swift-syntax.git", from: "<#latest swift-syntax tag#>"), ] - 2
Or add it as a dependency of an Xcode project via the Package Dependencies tab
Things to know
- Releases are tied to Swift language and toolchain versions, so you must pick a version matching your Swift release.
- The Bazel build configuration is experimental.
Topics
FAQ
- What is swift-syntax?
- A Swift library set for parsing, inspecting, generating and transforming Swift source code as a source-accurate syntax tree. swift-syntax is a set of Swift libraries that work on a source-accurate tree representation of Swift source code, called the SwiftSyntax tree. Tools that need to read or rewrite Swift code can build on this tree instead of handling raw text.
- Is swift-syntax free to use? What license does it have?
- swift-syntax is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is swift-syntax still maintained?
- Actively maintained. The last commit to swift-syntax was on Oct 21, 2026.
- What can I use swift-syntax for?
- Writing Swift macros that generate code at compile time. Building linters, formatters or refactoring tools for Swift code. Automatically rewriting or code-generating Swift source files.
- How do I install swift-syntax?
- Add the swift-syntax package to your Package.swift dependencies: dependencies: [ .package(url: "https://github.com/swiftlang/swift-syntax.git", from: "<#latest swift-syntax tag#>"), ] Or add it as a dependency of an Xcode project via the Package Dependencies tab
- Where can I get swift-syntax?
- The source code and installation instructions are on GitHub: https://github.com/swiftlang/swift-syntax
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A complete C99/C11 parser written in pure Python, producing an AST from C source code with no external dependencies.
A JavaScript compiler that transforms next-generation JS syntax into code that runs in your target environments.
A modular collection of compiler and toolchain technologies, including the LLVM core, the Clang C/C++ frontend, libc++ and the LLD linker.
A fast, low-level markdown parser and compiler for JavaScript that runs in browsers, Node.js, and the command line.
A super-fast TypeScript/JavaScript compiler and parser written in Rust, usable from Rust and from JavaScript.