File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Sources/SwiftOperatorPrecedence
Tests/SwiftOperatorPrecedenceTest Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,15 @@ extension OperatorPrecedence {
60
60
}
61
61
62
62
// The ternary operator has a fixed precedence group name.
63
- if let ternaryExpr = expr. as ( UnresolvedTernaryExprSyntax . self) {
63
+ if expr. is ( UnresolvedTernaryExprSyntax . self) {
64
64
return " TernaryPrecedence "
65
65
}
66
66
67
+ // An assignment operator has fixed precedence.
68
+ if expr. is ( AssignmentExprSyntax . self) {
69
+ return " AssignmentPrecedence "
70
+ }
71
+
67
72
// FIXME: Handle all of the language-defined precedence relationships.
68
73
return nil
69
74
}
@@ -81,8 +86,7 @@ extension OperatorPrecedence {
81
86
return ExprSyntax (
82
87
InfixOperatorExprSyntax (
83
88
leftOperand: lhs,
84
- binaryOperatorExpr. unexpectedBeforeOperatorToken,
85
- operatorOperand: op,
89
+ operatorOperand: ExprSyntax ( binaryOperatorExpr) ,
86
90
rightOperand: rhs)
87
91
)
88
92
}
@@ -102,6 +106,16 @@ extension OperatorPrecedence {
102
106
)
103
107
}
104
108
109
+ // An assignment operator x = y.
110
+ if let assignExpr = op. as ( AssignmentExprSyntax . self) {
111
+ return ExprSyntax (
112
+ InfixOperatorExprSyntax (
113
+ leftOperand: lhs,
114
+ operatorOperand: ExprSyntax ( assignExpr) ,
115
+ rightOperand: rhs)
116
+ )
117
+ }
118
+
105
119
// FIXME: Fallback that we should never need
106
120
fatalError ( " Unknown binary operator " )
107
121
}
Original file line number Diff line number Diff line change @@ -118,6 +118,12 @@ public class OperatorPrecedenceTests: XCTestCase {
118
118
XCTAssertFalse ( foldedAll. containsExprSequence)
119
119
}
120
120
121
+ func testAssignExprs( ) throws {
122
+ let opPrecedence = OperatorPrecedence . standardOperators
123
+ try opPrecedence. assertExpectedFold ( " a = b + c " , " (a = (b + c)) " )
124
+ try opPrecedence. assertExpectedFold ( " a = b = c " , " (a = (b = c)) " )
125
+ }
126
+
121
127
func testParsedLogicalExprs( ) throws {
122
128
let logicalOperatorSources =
123
129
"""
You can’t perform that action at this time.
0 commit comments