Avatar
Kishikawa Katsumi 12/26/2022 3:32 PM
## Syntax Nodes A syntax tree is made up of elements called syntax nodes. To help categorize and organize syntax nodes, SwiftSyntax defines a hierarchy of protocols for syntax nodes. At the top of this hierarchy is the ``SyntaxProtocol`` protocol. To represent related categories of syntax, ``SyntaxProtocol`` is further refined: - ``DeclSyntaxProtocol`` for declarations like `struct`s, `class`es, `enum`s and `protocol`s. - ``StmtSyntaxProtocol`` for statements like `if`, `switch`, and `do`. - ``ExprSyntaxProtocol`` for expressions like function calls, literals, and closures - ``TypeSyntaxProtocol`` for types like `Array<String>`, `[String: String]`, and `some Protocol` - ``PatternSyntaxProtocol`` for patterns like `case (_, let x)` Syntax nodes form the "branches" of the syntax tree, as they are generally high-level collections of one or more syntax nodes. Taken together, these branches form the syntactic structure of the source code. This structure is used by compilers and static analyzers to process source code at a high level. A special kind of syntax node is a ``SyntaxCollection``, which represents syntax with a variable number of children. For example, a code block value can contain zero or more statements in between a pair of braces. To represent these children, a ``CodeBlockSyntax`` value has a ``CodeBlockSyntax/statements`` accessor that returns a ``CodeBlockItemListSyntax`` value. The elements of this syntax collection are ``CodeBlockItemSyntax`` values. これいいな。こういう体系的な情報はドキュメントに書いてくれないとわからんから。できれば網羅して書いてほしいけど。