Skip to content

Commit d895d3b

Browse files
committed
Rename SwiftOperatorPrecedence -> SwiftOperators
This module has been generalized (slightly) to handle everything involving Swift's user-defined operators and precedence groups, so rename it accordingly.
1 parent 2f46100 commit d895d3b

13 files changed

+19
-17
lines changed

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ let package = Package(
4545
.macCatalyst(.v13),
4646
],
4747
products: [
48-
.library(name: "SwiftOperatorPrecedence", type: .static,
49-
targets: ["SwiftOperatorPrecedence"]),
48+
.library(name: "SwiftOperators", type: .static,
49+
targets: ["SwiftOperators"]),
5050
.library(name: "SwiftParser", type: .static, targets: ["SwiftParser"]),
5151
.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]),
5252
.library(name: "SwiftSyntaxParser", type: .static, targets: ["SwiftSyntaxParser"]),
@@ -117,7 +117,7 @@ let package = Package(
117117
]
118118
),
119119
.target(
120-
name: "SwiftOperatorPrecedence",
120+
name: "SwiftOperators",
121121
dependencies: ["SwiftSyntax", "SwiftParser", "SwiftDiagnostics"]
122122
),
123123
.executableTarget(
@@ -176,8 +176,8 @@ let package = Package(
176176
dependencies: ["SwiftDiagnostics", "SwiftParser", "_SwiftSyntaxTestSupport"]
177177
),
178178
.testTarget(
179-
name: "SwiftOperatorPrecedenceTest",
180-
dependencies: ["SwiftOperatorPrecedence", "_SwiftSyntaxTestSupport",
179+
name: "SwiftOperatorsTest",
180+
dependencies: ["SwiftOperators", "_SwiftSyntaxTestSupport",
181181
"SwiftParser"]
182182
),
183183
]

Sources/SwiftOperatorPrecedence/OperatorPrecedenceError+Diagnostics.swift renamed to Sources/SwiftOperators/OperatorPrecedenceError+Diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension OperatorPrecedenceError : DiagnosticMessage {
4343
}
4444

4545
public var diagnosticID: MessageID {
46-
MessageID(domain: "SwiftOperatorPrecedence", id: "\(self)")
46+
MessageID(domain: "SwiftOperators", id: "\(self)")
4747
}
4848
}
4949

Sources/SwiftOperatorPrecedence/SwiftOperatorPrecedence.docc/Info.plist renamed to Sources/SwiftOperators/SwiftOperators.docc/Info.plist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleName</key>
6-
<string>SwiftOperatorPrecedence</string>
6+
<string>SwiftOperators</string>
77
<key>CFBundleDisplayName</key>
8-
<string>SwiftOperatorPrecedence</string>
8+
<string>SwiftOperators</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.apple.swift-operator-precedence</string>
10+
<string>com.apple.swift-operators</string>
1111
<key>CFBundleDevelopmentRegion</key>
1212
<string>en</string>
1313
<key>CFBundleIconFile</key>
@@ -24,7 +24,7 @@
2424
<string>0.1.0</string>
2525
<key>CDAppleDefaultAvailability</key>
2626
<dict>
27-
<key>SwiftOperatorPrecedence</key>
27+
<key>SwiftOperators</key>
2828
<array>
2929
<dict>
3030
<key>name</key>
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# ``SwiftOperatorPrecedence``
1+
# ``SwiftOperators``
22

33

44

5-
An implementation of Swift's operator precedence semantics for Swift syntax trees.
5+
An implementation of Swift's user-defined operator declarations and precedence
6+
groups, allowing a program to reason about the relative precedence of
7+
infix operations and transform syntax trees to describe the order of operations.
68

79

810

@@ -15,7 +17,7 @@ infix operator +: AdditionPrecedence
1517
infix operator *: MultiplicationPrecedence
1618
```
1719

18-
The define the associativity and relative precedence of these operators is defined via a [precedence group declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_precedence-group-declaration). For example, the precedence groups used for `+` and `*` are defined as follows:
20+
The associativity and relative precedence of these operators is defined via a [precedence group declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_precedence-group-declaration). For example, the precedence groups used for `+` and `*` are defined as follows:
1921

2022
```swift
2123
precedencegroup AdditionPrecedence {
@@ -29,18 +31,18 @@ precedencegroup MultiplicationPrecedence {
2931

3032
The Swift parser itself does not reason about the semantics of operators or precedence groups. Instead, an expression such as `x + y * z` will be parsed into a `SequenceExprSyntax` node whose children are `x`, a `BinaryOperatorExprSyntax` node for `+`, `y`, a `BinaryOperatorExprSyntax` node for `*`, and `z`. This is all the structure that is possible to parse for a Swift program without semantic information about operators and precedence groups.
3133

32-
The `SwiftOperatorPrecedence` module interprets operator and precedence group declarations to provide those semantics. Its primary operation is to "fold" a `SequenceExprSyntax` node into an equivalent syntax tree that fully expresses the order of operations: in our example case, this means that the resulting syntax node will be an `InfixOperatorExprSyntax` whose left-hand side is `x` and operator is `+`, and whose right-hand side is another `InfixOperatorExprSyntax` node representing `y * z`. The resulting syntax tree will still accurately represent the original source input, but will be completely describe the order of evaluation and be suitable for structured editing or later semantic passes, such as type checking.
34+
The `SwiftOperators` module interprets operator and precedence group declarations to provide those semantics. Its primary operation is to "fold" a `SequenceExprSyntax` node into an equivalent syntax tree that fully expresses the order of operations: in our example case, this means that the resulting syntax node will be an `InfixOperatorExprSyntax` whose left-hand side is `x` and operator is `+`, and whose right-hand side is another `InfixOperatorExprSyntax` node representing `y * z`. The resulting syntax tree will still accurately represent the original source input, but will be completely describe the order of evaluation and be suitable for structured editing or later semantic passes, such as type checking.
3335

3436

3537

3638
## Quickstart
3739

38-
The `SwiftOperatorPrecedence` library is typically used to take a raw parse of Swift code and apply the operator-precedence transformation to it to replace all `SequenceExprSyntax` nodes with more structured syntax nodes. For example, we can use this library's representation of the Swift standard library operators to provide a structured syntax tree for the expression `x + y * z`:
40+
The `SwiftOperators` library is typically used to take a raw parse of Swift code and apply the operator-precedence transformation to it to replace all `SequenceExprSyntax` nodes with more structured syntax nodes. For example, we can use this library's representation of the Swift standard library operators to provide a structured syntax tree for the expression `x + y * z`:
3941

4042
```swift
4143
import SwiftSyntax
4244
import SwiftParser
43-
import SwiftOperatorPrecedence
45+
import SwiftOperators
4446

4547
var opPrecedence = OperatorTable.standardOperators // Use the Swift standard library operators
4648
let parsed = try Parser.parse(source: "x + y * z")

Tests/SwiftOperatorPrecedenceTest/OperatorTable.swift renamed to Tests/SwiftOperatorsTest/OperatorTable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import XCTest
22
import SwiftSyntax
33
import SwiftParser
4-
@_spi(Testing) import SwiftOperatorPrecedence
4+
@_spi(Testing) import SwiftOperators
55
import _SwiftSyntaxTestSupport
66

77
/// Visitor that looks for ExprSequenceSyntax nodes.

0 commit comments

Comments
 (0)