Repolode
swiftlang

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. 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. 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