Skip to content

Commit b5753ad

Browse files
committed
Merge remote-tracking branch 'origin_apple/main' into detect-missing-comma-in-tupel
# Conflicts: # Tests/SwiftParserTest/Types.swift # Tests/SwiftParserTest/translated/InvalidTests.swift
2 parents 3701a15 + 7e3dc35 commit b5753ad

File tree

117 files changed

+3421
-2359
lines changed

Some content is hidden

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

117 files changed

+3421
-2359
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Alternatively you can also build it from the command line using `build-script.py
2323
2424
Because of SwiftSyntax’s integration with the Swift compiler project, testing certain parts of the project is a little bit more involved than others.
2525
26-
The `SwiftParser` tests have no depdendencies, other `XCTests` require you to use a matching Swift Development Snapshot, `lit`-based test require a compiler build.
26+
The `SwiftParser` tests have no dependencies, other `XCTests` require you to use a matching Swift Development Snapshot, `lit`-based test require a compiler build.
2727
28-
Run the tests that you belive are necessary locally. CI will always run all test before allowing the PR to be merged.
28+
Run the tests that you believe are necessary locally. CI will always run all test before allowing the PR to be merged.
2929
3030
### SwiftParser
3131
@@ -39,7 +39,7 @@ The `SwiftSyntaxParser` module (the legacy parser) of this repository depends on
3939
The syntax node definitions of that parser library need to match those used by your SwiftSyntax checkout.
4040
Most of the time, the parser library included in the latest Swift Development Snapshot will fulfill this requirement.
4141
42-
To run the tests in Xcode, select the latest Swift Development Snapshot in Xcode -> Toolchains, select the SwiftSyntax-Package scheme and hit Prodcut -> Test.
42+
To run the tests in Xcode, select the latest Swift Development Snapshot in Xcode -> Toolchains, select the SwiftSyntax-Package scheme and hit Product -> Test.
4343
4444
You can also run the tests from the command line using
4545
```bash
@@ -51,7 +51,7 @@ If you are seeing issues regarding a mismatched parser library, try the followin
5151
2. Revert your swift-syntax checkout to the date of your Swift Development Snapshot
5252
3. Wait for a new Swift Development Snapshot
5353
4. If the above options are not possible, build your own Swift toolchain locally and use that toolchain as the `--toolchain` parameter for SwiftSyntax’s `build-script.py` invocations
54-
- Note: Building your own toolchain will take more than 1 hour and even longer if you are running into any issues. We do not recomment building your own Swift toolchain unless you are familiar with Swift compiler development.
54+
- Note: Building your own toolchain will take more than 1 hour and even longer if you are running into any issues. We do not recommend building your own Swift toolchain unless you are familiar with Swift compiler development.
5555

5656
Tip: Running SwiftSyntax’s self-parse tests takes the majority of testing time. If you want to iterate quickly, you can skip these tests using the following steps:
5757
1. Product -> Scheme -> Edit Scheme…

CodeGeneration/Sources/SyntaxSupport/gyb_generated/CommonNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public let COMMON_NODES: [Node] = [
127127
elementsSeparatedByNewline: true),
128128

129129
Node(name: "CodeBlock",
130-
nameForDiagnostics: nil,
130+
nameForDiagnostics: "code block",
131131
kind: "Syntax",
132132
traits: [
133133
"Braced",

CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public let DECL_NODES: [Node] = [
637637
]),
638638

639639
Node(name: "MemberDeclBlock",
640-
nameForDiagnostics: nil,
640+
nameForDiagnostics: "member block",
641641
kind: "Syntax",
642642
traits: [
643643
"Braced"
@@ -1258,7 +1258,7 @@ public let DECL_NODES: [Node] = [
12581258
]),
12591259

12601260
Node(name: "OperatorDecl",
1261-
nameForDiagnostics: "operator",
1261+
nameForDiagnostics: "operator declaration",
12621262
description: "A Swift `operator` declaration.",
12631263
kind: "Decl",
12641264
traits: [

CodeGeneration/Sources/SyntaxSupport/gyb_generated/GenericNodes.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ public let GENERIC_NODES: [Node] = [
145145
tokenChoices: [
146146
"Identifier"
147147
]),
148+
Child(name: "Ellipsis",
149+
kind: "EllipsisToken",
150+
isOptional: true,
151+
tokenChoices: [
152+
"Ellipsis"
153+
]),
148154
Child(name: "Colon",
149155
kind: "ColonToken",
150156
isOptional: true,

CodeGeneration/Sources/generate-swiftsyntaxbuilder/BuildableCollectionNodesFile.swift

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,11 @@ let buildableCollectionNodesFile = SourceFile {
9898
}
9999
}
100100

101-
/// Generate an initializer taking an array of elements.
102-
private func createArrayInitializer(node: Node) -> InitializerDecl {
103-
let type = node.type
104-
let elementType = node.collectionElementType
105-
var elementsInit: ExprBuildable = IdentifierExpr("elements")
106-
if !elementType.isToken {
107-
elementsInit = FunctionCallExpr(
108-
calledExpression: MemberAccessExpr(base: elementsInit, name: "map"),
109-
trailingClosure: ClosureExpr(" { $0.create\(elementType.buildableBaseName)() }")
110-
)
111-
}
101+
/// Helper for generating an initializer taking an array of elements.
102+
private func createArrayInitializer<ElementsInit: ExprBuildable>(
103+
type: SyntaxBuildableType, elementType: SyntaxBuildableType,
104+
elementsInit: ElementsInit
105+
) -> InitializerDecl {
112106
return InitializerDecl(
113107
"""
114108
/// Creates a `\(type.buildableBaseName)` with the provided list of elements.
@@ -121,6 +115,26 @@ private func createArrayInitializer(node: Node) -> InitializerDecl {
121115
)
122116
}
123117

118+
/// Generate an initializer taking an array of elements.
119+
private func createArrayInitializer(node: Node) -> InitializerDecl {
120+
let type = node.type
121+
let elementType = node.collectionElementType
122+
let elementsInit = IdentifierExpr("elements")
123+
if elementType.isToken {
124+
return createArrayInitializer(
125+
type: type, elementType: elementType, elementsInit: elementsInit
126+
)
127+
}
128+
129+
let elementsInitCall = FunctionCallExpr(
130+
calledExpression: MemberAccessExpr(base: elementsInit, name: "map"),
131+
trailingClosure: ClosureExpr(" { $0.create\(elementType.buildableBaseName)() }")
132+
)
133+
return createArrayInitializer(
134+
type: type, elementType: elementType, elementsInit: elementsInitCall
135+
)
136+
}
137+
124138
/// Generate a flattening initializer taking an array of collections.
125139
private func createCombiningInitializer(node: Node) -> InitializerDecl {
126140
let type = node.type

Documentation/SwiftParser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Documentation on the Swift parser can be found in [Sources/SwiftParser/SwiftParser.docc](../Sources/SwiftParser/SwiftParser.docc).
44

5-
You can either directly view this documentation on GitHub or build a documenation bundle by opening the project in Xcode and clicking Product -> Build Documentation
5+
You can either directly view this documentation on GitHub or build a documentation bundle by opening the project in Xcode and clicking Product -> Build Documentation

Package.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ let package = Package(
9797
dependencies: ["SwiftBasicFormat", "SwiftSyntax", "SwiftParser"],
9898
exclude: [
9999
"gyb_helpers",
100+
"SyntaxExpressibleByStringInterpolationConformances.swift.gyb",
100101
]
101102
),
102103
.target(
@@ -125,7 +126,10 @@ let package = Package(
125126
),
126127
.target(
127128
name: "SwiftOperators",
128-
dependencies: ["SwiftSyntax", "SwiftParser", "SwiftDiagnostics"]
129+
dependencies: ["SwiftSyntax", "SwiftParser", "SwiftDiagnostics"],
130+
exclude: [
131+
"CMakeLists.txt",
132+
]
129133
),
130134
.target(
131135
name: "SwiftCompilerSupport",
@@ -142,13 +146,12 @@ let package = Package(
142146
),
143147
.executableTarget(
144148
name: "swift-parser-cli",
145-
dependencies: ["_SwiftSyntaxTestSupport", "SwiftDiagnostics",
146-
"SwiftSyntax", "SwiftParser", "SwiftOperators",
149+
dependencies: ["SwiftDiagnostics", "SwiftSyntax", "SwiftParser", "SwiftOperators",
147150
.product(name: "ArgumentParser", package: "swift-argument-parser")]
148151
),
149152
.testTarget(
150153
name: "SwiftDiagnosticsTest",
151-
dependencies: ["SwiftDiagnostics", "SwiftParser"]
154+
dependencies: ["_SwiftSyntaxTestSupport", "SwiftDiagnostics", "SwiftParser"]
152155
),
153156
.testTarget(
154157
name: "SwiftSyntaxTest",

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
11
# SwiftSyntax
22

3-
SwiftSyntax is a set of Swift bindings for the
4-
[libSyntax](https://github.com/apple/swift/tree/main/lib/Syntax) library. It
5-
allows Swift tools to parse, inspect, generate, and transform Swift source
6-
code.
3+
SwiftSyntax is a set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
74

8-
Its API is designed for performance-critical applications. It uses value types almost exclusively and aims to avoid existential conversions where possible.
5+
> Note: SwiftSyntax is still in development, and its API is not guaranteed to
6+
> be stable. It is subject to change without warning.
97
10-
> Note: SwiftSyntax is still in development, and the API is not guaranteed to
11-
> be stable. It's subject to change without warning.
8+
## Adding SwiftSyntax as a Dependency
129

13-
## Declare SwiftPM dependency with release tag
10+
### Trunk Development (main)
1411

15-
Add this repository to the `Package.swift` manifest of your project:
12+
The mainline branch of SwiftSyntax tracks the latest developments. It is not
13+
an official release, and is subject to rapid changes in APIs and behaviors. To
14+
use it, add this repository to the `Package.swift` manifest of your project:
1615

1716
```swift
18-
// swift-tools-version:5.6
17+
// swift-tools-version:5.7
18+
import PackageDescription
19+
20+
let package = Package(
21+
name: "MyTool",
22+
dependencies: [
23+
.package(url: "https://github.com/apple/swift-syntax.git", branch: "main"),
24+
],
25+
targets: [
26+
.target(name: "MyTool", dependencies: [
27+
.product(name: "SwiftSyntax", package: "swift-syntax"),
28+
]),
29+
]
30+
)
31+
```
32+
33+
Mainline SwiftSyntax also includes
34+
35+
- `SwiftParser` for natively parsing source code
36+
- `SwiftOperators` for folding SwiftSyntax trees containing operators
37+
- `SwiftSyntaxBuilder` for generating Swift code with a result builder-style interface
38+
39+
### Releases
40+
41+
Releases of SwiftSyntax are aligned with corresponding language
42+
and tooling releases and are stable. To use them,
43+
add this repository to the `Package.swift` manifest of your project:
44+
45+
```swift
46+
// swift-tools-version:5.7
1947
import PackageDescription
2048

2149
let package = Package(
@@ -42,13 +70,11 @@ Replace `<#Specify Release tag#>` by the version of SwiftSyntax that you want to
4270
| Xcode 12.0 | swift-5.3-RELEASE | 0.50300.0 |
4371
| Xcode 11.4 | swift-5.2-RELEASE | 0.50200.0 |
4472

45-
Then, import `SwiftSyntax` in your Swift code.
46-
4773
## Documentation
4874

4975
Documentation can be found in the following places:
5076
- For the parser: [Sources/SwiftParser/SwiftParser.docc](Sources/SwiftParser/SwiftParser.docc)
51-
- You can either directly view this documentation on GitHub or build a documenation bundle by opening the project in Xcode and clicking Product -> Build Documentation
77+
- You can either directly view this documentation on GitHub or build a documentation bundle by opening the project in Xcode and clicking Product -> Build Documentation
5278
- General documentation: [Documentation](Documentation)
5379
- Examples of using SwiftSyntax: [Examples](Examples).
5480

@@ -62,4 +88,4 @@ If you should hit any issues while using SwiftSyntax, we appreciate bug reports
6288

6389
## License
6490

65-
Please see [LICENSE](LICENSE.txt) for more information.
91+
Please see [LICENSE](LICENSE.txt) for more information.

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,13 +2304,15 @@ open class BasicFormat: SyntaxRewriter {
23042304
let attributes = node.attributes.map(self.visit)?.cast(AttributeListSyntax.self)
23052305
let unexpectedBetweenAttributesAndName = node.unexpectedBetweenAttributesAndName.map(self.visit)?.cast(UnexpectedNodesSyntax.self)
23062306
let name = self.visit(node.name).cast(TokenSyntax.self)
2307-
let unexpectedBetweenNameAndColon = node.unexpectedBetweenNameAndColon.map(self.visit)?.cast(UnexpectedNodesSyntax.self)
2307+
let unexpectedBetweenNameAndEllipsis = node.unexpectedBetweenNameAndEllipsis.map(self.visit)?.cast(UnexpectedNodesSyntax.self)
2308+
let ellipsis = node.ellipsis.map(self.visit)?.cast(TokenSyntax.self)
2309+
let unexpectedBetweenEllipsisAndColon = node.unexpectedBetweenEllipsisAndColon.map(self.visit)?.cast(UnexpectedNodesSyntax.self)
23082310
let colon = node.colon.map(self.visit)?.cast(TokenSyntax.self)
23092311
let unexpectedBetweenColonAndInheritedType = node.unexpectedBetweenColonAndInheritedType.map(self.visit)?.cast(UnexpectedNodesSyntax.self)
23102312
let inheritedType = node.inheritedType.map(self.visit)?.cast(TypeSyntax.self)
23112313
let unexpectedBetweenInheritedTypeAndTrailingComma = node.unexpectedBetweenInheritedTypeAndTrailingComma.map(self.visit)?.cast(UnexpectedNodesSyntax.self)
23122314
let trailingComma = node.trailingComma.map(self.visit)?.cast(TokenSyntax.self)
2313-
return Syntax(GenericParameterSyntax(unexpectedBeforeAttributes, attributes: attributes, unexpectedBetweenAttributesAndName, name: name, unexpectedBetweenNameAndColon, colon: colon, unexpectedBetweenColonAndInheritedType, inheritedType: inheritedType, unexpectedBetweenInheritedTypeAndTrailingComma, trailingComma: trailingComma))
2315+
return Syntax(GenericParameterSyntax(unexpectedBeforeAttributes, attributes: attributes, unexpectedBetweenAttributesAndName, name: name, unexpectedBetweenNameAndEllipsis, ellipsis: ellipsis, unexpectedBetweenEllipsisAndColon, colon: colon, unexpectedBetweenColonAndInheritedType, inheritedType: inheritedType, unexpectedBetweenInheritedTypeAndTrailingComma, trailingComma: trailingComma))
23142316
}
23152317

23162318
open override func visit(_ node: PrimaryAssociatedTypeListSyntax) -> Syntax {

Sources/SwiftOperators/SwiftOperators.docc/SwiftOperators.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import SwiftParser
4545
import SwiftOperators
4646

4747
var opPrecedence = OperatorTable.standardOperators // Use the Swift standard library operators
48-
let parsed = try Parser.parse(source: "x + y * z")
48+
let parsed = Parser.parse(source: "x + y * z")
4949
dump(parsed) // contains SequenceExprSyntax(x, +, y, *, z)
5050
let folded = try opPrecedence.foldAll(parsed)
5151
dump(folded) // contains InfixOperatorExpr(x, +, InfixOperatorExpr(y, *, z))
@@ -65,12 +65,12 @@ let moreOperators =
6565
6666
infix operator **: ExponentiationPrecedence
6767
"""
68-
let parsedOperators = try Parser.parse(source: moreOperators)
68+
let parsedOperators = Parser.parse(source: moreOperators)
6969

7070
// Adds **, ExponentiationPrecedence to the set of known operators and precedence groups.
7171
try opPrecedence.addSourceFile(parsedOperators)
7272

73-
let parsed2 = try Parser.parse(source: "b ** c ** d")
73+
let parsed2 = Parser.parse(source: "b ** c ** d")
7474
dump(parsed2) // contains SequenceExprSyntax(b, **, c, **, d)
7575
let folded2 = try opPrecedence.foldAll(parsed2)
7676
dump(folded2) // contains InfixOperatorExpr(b, **, InfixOperatorExpr(c, **, d))

0 commit comments

Comments
 (0)