# swiftlang/swift-syntax

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/swiftlang-swift-syntax).**

_How this analysis was created: the description and tags below were written by an AI model that read this project's README and public documentation pages; stars, license and language come straight from the GitHub API. The model does not read the source code._

3,720 stars · 565 forks · Swift · Apache-2.0

## Links

- GitHub: https://github.com/swiftlang/swift-syntax
- awesome-repositories: https://awesome-repositories.com/repository/swiftlang-swift-syntax.md

## Description

SwiftSyntax is a set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code. It parses source text into lossless syntax trees that keep every token, piece of trivia, and source position, so the original text can be rebuilt exactly. Those trees are the basis for the rest of the package: structural analysis, name lookup, diagnostics, and code rewriting.

The package also covers Swift macro development. It provides protocols and an expansion engine for writing macros that inspect annotated code and generate new code at compile time. Macros can be bundled into standalone compiler plugin executables, which the compiler launches and communicates with separately from its own process. A collection of sample macros and a utility for testing macro expansions against expected output are included. On the generation side, a builder interface constructs syntax trees programmatically and prints them as well-formed source, instead of relying on string concatenation.

Beyond parsing and macros, the libraries offer formatting, refactoring actions that can surface as editor commands in Xcode, and diagnostics with suggested fixes. Supporting capabilities include operator precedence folding, conditional compilation evaluation, lexical scope name resolution, and syntax classification for editor tooling. Syntax nodes are immutable, so each transformation produces a new tree that shares unchanged parts with the old one. Transformations are written with visitor and rewriter classes.

API reference documentation is published for each library target, and an interactive browser-based explorer lets you view the syntax tree of any source file.

## Tags

### Programming Languages & Runtimes

- [Source File Parsing](https://awesome-repositories.com/f/programming-languages-runtimes/source-file-parsing.md) — Parses Swift source text into lossless syntax trees that keep every token, piece of trivia, and source position. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Sources))
- [Swift Source Parsers](https://awesome-repositories.com/f/programming-languages-runtimes/swift-source-parsers.md) — Parses Swift source into lossless syntax trees preserving every token, trivia, and position so the original text can be rebuilt exactly.
- [Compiler Plugin Executables](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-plugin-executables.md) — Builds standalone plugin executables that the compiler launches and talks to in order to run custom macro logic while compiling. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Examples))
- [Compiler Plugin SDKs](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-plugin-sdks.md) — Lets macro logic be bundled into standalone executables that the compiler launches and communicates with outside its own process.
- [Attribute-Macro Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/metaprogramming/procedural-macros/attribute-macro-code-generators.md) — Lets macros produce syntax nodes that the expansion inserts into source files, forming the basis of the macro system. ([source](https://github.com/swiftlang/swift-syntax/blob/main/README.md))
- [Procedural Macro Engines](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/metaprogramming-macros/hygienic-macro-systems/macro-expansion-engines/procedural-macro-engines.md) — Provides protocols and an expansion engine for writing macros that inspect annotated code and generate new code at compile time. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Sources))
- [Macro Expansion Frameworks](https://awesome-repositories.com/f/programming-languages-runtimes/macro-expansion-frameworks.md) — Provides role-specific protocols and an expansion engine that splice macro-generated nodes into source files at compile time.
- [Source Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-generators.md) — Builds syntax trees programmatically through builder interfaces and prints them as well-formed source text instead of concatenating strings. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Sources))
- [Swift Source Analysis](https://awesome-repositories.com/f/programming-languages-runtimes/swift-code-formatters/swift-source-analysis.md) — Parses Swift into accurate syntax trees for structural inspection, name resolution, token classification, and diagnostics with suggested fixes.
- [Custom Macro Definitions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/metaprogramming-macros/custom-macro-definitions.md) — Supports defining reusable macros that expand into generated code at compile time, with ready-to-run samples to learn from. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Examples))
- [Swift Source Code Transformers](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/source-code-templates/source-code-transformation-engines/swift-source-code-transformers.md) — Transforms Swift source by walking its syntax tree with rewriters, including a command-line example that increments every integer literal. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Examples))
- [Swift Development Tooling](https://awesome-repositories.com/f/programming-languages-runtimes/swift-development-tooling.md) — Supplies syntax classification, diagnostics with fix-its, name lookup, and operator precedence folding that editors and IDEs build on.
- [Swift Refactoring Tools](https://awesome-repositories.com/f/programming-languages-runtimes/swift-refactoring-tools.md) — Offers reusable refactoring actions and syntax tree rewriting that transform Swift code structure, including commands that surface in Xcode.

### Development Tools & Productivity

- [Compile-Time Macros](https://awesome-repositories.com/f/development-tools-productivity/compile-time-parameter-bindings/compile-time-macros.md) — Supports writing compile-time macros that inspect annotated code and expand into generated code, packaged as plugins the compiler loads. ([source](https://github.com/swiftlang/swift-syntax/blob/main/Examples))
- [Code Refactoring Tools](https://awesome-repositories.com/f/development-tools-productivity/code-refactoring-tools.md) — Provides reusable refactoring actions that rewrite code structure on syntax trees while keeping surrounding source intact. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Sources))
- [Swift Code Generators](https://awesome-repositories.com/f/development-tools-productivity/swift-code-generators.md) — Provides a builder interface that constructs valid Swift source instead of string concatenation, with generated files rebuilt from definitions.
- [Swift Refactoring Tools](https://awesome-repositories.com/f/development-tools-productivity/swift-refactoring-tools.md) — Offers a framework of reusable refactoring actions that rewrite and format syntax trees and can appear as Xcode editor commands.

### Software Engineering & Architecture

- [Lossless Semantic Trees](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-tools/internal-tree-representations/lossless-semantic-trees.md) — Models source as a tree that keeps every token, whitespace, comment and position so the original text can be rebuilt exactly.
- [Out-of-Process Plugin Architectures](https://awesome-repositories.com/f/software-engineering-architecture/out-of-process-plugin-architectures.md) — Runs macros in standalone executables that the compiler launches and communicates with via serialized messages, isolating custom logic.
- [Syntax Tree Construction](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction.md) — Models source code as an immutable tree of nodes preserving program structure, tokens, and trivia for inspection and manipulation. ([source](https://github.com/swiftlang/swift-syntax#readme))
- [Immutable Nodes](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing/abstract-syntax-tree-generators/immutable-nodes.md) — Syntax nodes are immutable, so each transformation yields a new tree that shares unchanged parts with the previous one.
- [Builder-Based Source Generation](https://awesome-repositories.com/f/software-engineering-architecture/builder-based-source-generation.md) — Constructs source files from structured builder calls that produce syntax nodes, guaranteeing well-formed output without string concatenation.
- [Syntax Tree Transformers](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-tree-transformers.md) — Offers visitor and rewriter classes that override specific node types and return replacements while leaving untouched code intact.

### DevOps & Infrastructure

- [Build Plugin Compilation](https://awesome-repositories.com/f/devops-infrastructure/cicd-pipeline-automation/core-build-engines/build-tooling/build-pipeline-extensions/build-plugins/plugin-compilation-automation/build-plugin-compilation.md) — Bundles macro implementations into a standalone plugin program that the compiler loads and runs during compilation. ([source](https://github.com/swiftlang/swift-syntax/blob/main/Examples))

### System Administration & Monitoring

- [Parser Diagnostics Reporting](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/diagnostic-error-reporting/parser-diagnostics-reporting.md) — Creates errors, warnings and suggested fixes tied to source locations and detects problems in parsed code with correction hints. ([source](https://github.com/swiftlang/swift-syntax/tree/main/Sources))
