Exploring SwiftSyntax
SwiftSyntax
is not a new library, and it’s part of Swift’s code base from its early beginnings. In fact, Swift Macros is part of SwiftSyntax
, and it uses its capabilities.
Before we dive into SwiftSyntax
(and there’s enough to dive into it), let’s learn about how the Swift compiler works (Figure 10.1):
Figure 10.1: The Swift compiler process
Don’t fear the different expressions you see in Figure 10.1. This figure is a high-level overview of how the compiler takes our source code and generates machine code our device can run (the *.o
files). We don’t have to understand every step in that flow, but knowing how it works is essential, especially where SwiftSyntax
fits in the process.
Let’s go over the steps together:
- Parse and abstract syntax tree (AST): The compiler takes our source code and builds an AST. The AST represents our code hierarchical structure, including classes...