Skip to content

Commit cf6ff40

Browse files
committed
Make CodeGeneration a lot less string-based
Because of its Python legacy the CodeGeneration tool has been heavily string-based. This PR fixes that at least to some degree. The main motivating factors here were: - Instead of using strings to specify the node type of a child node, define a `SyntaxNodeKind` enum that contains a case for each syntax node. This way you can be sure that you’re not referring to a non-existent syntax node (like we did for e.g. `InOutToken`, which we forgot to change to `.token("inout")`) - Refactor `Node` so that it contains two initializers: One for collections and one for layout nodes instead of having one initializer that has a bunch of optional and defaulted arguments. - Change a bunch of properties from returning a `String` to returning a `TypeSyntax` or `TokenSyntax` so we don‘t need to use the `raw:` interpolation style for them. In general, the API of `Node` and `SyntaxNodeKind` is what I’m happy with now. The other files can still do with some cleanup. All the changes resulted in nearly no functionaly changes of the generated code.
1 parent 967e487 commit cf6ff40

File tree

53 files changed

+2257
-1783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2257
-1783
lines changed

CodeGeneration/Package.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let package = Package(
2020
dependencies: [
2121
.product(name: "SwiftSyntax", package: "swift-syntax"),
2222
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
23+
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
2324
.product(name: "ArgumentParser", package: "swift-argument-parser"),
2425
"SyntaxSupport",
2526
"Utils",
@@ -29,11 +30,16 @@ let package = Package(
2930
]
3031
),
3132
.target(
32-
name: "SyntaxSupport"
33+
name: "SyntaxSupport",
34+
dependencies: [
35+
.product(name: "SwiftSyntax", package: "swift-syntax"),
36+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
37+
]
3338
),
3439
.target(
3540
name: "Utils",
3641
dependencies: [
42+
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
3743
.product(name: "SwiftSyntax", package: "swift-syntax"),
3844
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
3945
"SyntaxSupport",

0 commit comments

Comments
 (0)