Skip to content

Commit 4ea6531

Browse files
committed
Merge spacedBinaryOperator and unspacedBinaryOperator
rdar://103774663
1 parent f5f6ae2 commit 4ea6531

39 files changed

+111
-224
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ public let ATTRIBUTE_NODES: [Node] = [
514514
description: "The base name of the referenced function.",
515515
tokenChoices: [
516516
"Identifier",
517-
"UnspacedBinaryOperator",
518-
"SpacedBinaryOperator",
517+
"BinaryOperator",
519518
"PrefixOperator",
520519
"PostfixOperator"
521520
]),

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AvailabilityNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public let AVAILABILITY_NODES: [Node] = [
3030
Child(name: "Token",
3131
kind: "Token",
3232
tokenChoices: [
33-
"SpacedBinaryOperator",
33+
"BinaryOperator",
3434
"Identifier"
3535
]),
3636
Child(name: "AvailabilityVersionRestriction",

CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,7 @@ public let DECL_NODES: [Node] = [
812812
kind: "Token",
813813
tokenChoices: [
814814
"Identifier",
815-
"UnspacedBinaryOperator",
816-
"SpacedBinaryOperator",
815+
"BinaryOperator",
817816
"PrefixOperator",
818817
"PostfixOperator"
819818
]),
@@ -1312,8 +1311,7 @@ public let DECL_NODES: [Node] = [
13121311
Child(name: "Identifier",
13131312
kind: "Token",
13141313
tokenChoices: [
1315-
"UnspacedBinaryOperator",
1316-
"SpacedBinaryOperator",
1314+
"BinaryOperator",
13171315
"PrefixOperator",
13181316
"PostfixOperator"
13191317
],

CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public let EXPR_NODES: [Node] = [
167167
"Self",
168168
"CapitalSelf",
169169
"DollarIdentifier",
170-
"SpacedBinaryOperator"
170+
"BinaryOperator"
171171
]),
172172
Child(name: "DeclNameArguments",
173173
kind: "DeclNameArguments",
@@ -282,7 +282,10 @@ public let EXPR_NODES: [Node] = [
282282
kind: "Expr",
283283
children: [
284284
Child(name: "OperatorToken",
285-
kind: "BinaryOperatorToken")
285+
kind: "BinaryOperatorToken",
286+
tokenChoices: [
287+
"BinaryOperator"
288+
])
286289
]),
287290

288291
Node(name: "ArrowExpr",
@@ -1080,7 +1083,7 @@ public let EXPR_NODES: [Node] = [
10801083
"Self",
10811084
"CapitalSelf",
10821085
"DollarIdentifier",
1083-
"SpacedBinaryOperator",
1086+
"BinaryOperator",
10841087
"IntegerLiteral"
10851088
]),
10861089
Child(name: "DeclNameArguments",

CodeGeneration/Sources/SyntaxSupport/gyb_generated/GenericNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public let GENERIC_NODES: [Node] = [
6767
Child(name: "EqualityToken",
6868
kind: "Token",
6969
tokenChoices: [
70-
"SpacedBinaryOperator",
71-
"UnspacedBinaryOperator",
70+
"BinaryOperator",
7271
"PrefixOperator",
7372
"PostfixOperator"
7473
]),

CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
310310
LiteralSpec(name: "RegexLiteral", kind: "regex_literal", nameForDiagnostics: "regex literal"),
311311
MiscSpec(name: "Unknown", kind: "unknown", nameForDiagnostics: "token"),
312312
MiscSpec(name: "Identifier", kind: "identifier", nameForDiagnostics: "identifier", classification: "Identifier"),
313-
MiscSpec(name: "UnspacedBinaryOperator", kind: "oper_binary_unspaced", nameForDiagnostics: "binary operator", classification: "OperatorIdentifier"),
314-
MiscSpec(name: "SpacedBinaryOperator", kind: "oper_binary_spaced", nameForDiagnostics: "binary operator", classification: "OperatorIdentifier", requiresLeadingSpace: true, requiresTrailingSpace: true),
313+
MiscSpec(name: "BinaryOperator", kind: "oper_binary", nameForDiagnostics: "binary operator", classification: "OperatorIdentifier", requiresLeadingSpace: true, requiresTrailingSpace: true),
315314
MiscSpec(name: "PostfixOperator", kind: "oper_postfix", nameForDiagnostics: "postfix operator", classification: "OperatorIdentifier"),
316315
MiscSpec(name: "PrefixOperator", kind: "oper_prefix", nameForDiagnostics: "prefix operator", classification: "OperatorIdentifier"),
317316
MiscSpec(name: "DollarIdentifier", kind: "dollarident", nameForDiagnostics: "dollar identifier", classification: "DollarIdentifier"),

CodeGeneration/Sources/generate-swiftsyntax/templates/basicformat/BasicFormatFile.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let basicFormatFile = SourceFile {
124124
FunctionDecl("open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool") {
125125
SwitchStmt("""
126126
switch (token.previousToken(viewMode: .sourceAccurate)?.tokenKind, token.tokenKind) {
127-
case (.leftParen, .spacedBinaryOperator):
127+
case (.leftParen, .binaryOperator): // Ensures there is no space in @available(*, deprecated)
128128
return false
129129
default:
130130
break
@@ -165,9 +165,8 @@ let basicFormatFile = SourceFile {
165165
(.postfixQuestionMark, .rightAngle), // Ensures there is not space in `ContiguousArray<RawSyntax?>`
166166
(.postfixQuestionMark, .rightParen), // Ensures there is not space in `myOptionalClosure?()`
167167
(.tryKeyword, .exclamationMark), // Ensures there is not space in `try!`
168-
(.tryKeyword, .postfixQuestionMark): // Ensures there is not space in `try?`
169-
return false
170-
case (.spacedBinaryOperator, .comma):
168+
(.tryKeyword, .postfixQuestionMark), // Ensures there is not space in `try?`
169+
(.binaryOperator, .comma): // Ensures there is no space in @available(*, deprecated)
171170
return false
172171
default:
173172
break

Sources/IDEUtils/generated/SyntaxClassification.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ extension RawTokenKind {
358358
return .none
359359
case .identifier:
360360
return .identifier
361-
case .unspacedBinaryOperator:
362-
return .operatorIdentifier
363-
case .spacedBinaryOperator:
361+
case .binaryOperator:
364362
return .operatorIdentifier
365363
case .postfixOperator:
366364
return .operatorIdentifier

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ open class BasicFormat: SyntaxRewriter {
137137

138138
open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool {
139139
switch (token.previousToken(viewMode: .sourceAccurate)?.tokenKind, token.tokenKind) {
140-
case (.leftParen, .spacedBinaryOperator):
140+
case (.leftParen, .binaryOperator): // Ensures there is no space in @available(*, deprecated)
141141
return false
142142
default:
143143
break
@@ -155,7 +155,7 @@ open class BasicFormat: SyntaxRewriter {
155155
return true
156156
case .arrow:
157157
return true
158-
case .spacedBinaryOperator:
158+
case .binaryOperator:
159159
return true
160160
default:
161161
return false
@@ -178,9 +178,8 @@ open class BasicFormat: SyntaxRewriter {
178178
(.postfixQuestionMark, .rightAngle), // Ensures there is not space in `ContiguousArray<RawSyntax?>`
179179
(.postfixQuestionMark, .rightParen), // Ensures there is not space in `myOptionalClosure?()`
180180
(.tryKeyword, .exclamationMark), // Ensures there is not space in `try!`
181-
(.tryKeyword, .postfixQuestionMark): // Ensures there is not space in `try?`
182-
return false
183-
case (.spacedBinaryOperator, .comma):
181+
(.tryKeyword, .postfixQuestionMark), // Ensures there is not space in `try?`
182+
(.binaryOperator, .comma): // Ensures there is no space in @available(*, deprecated)
184183
return false
185184
default:
186185
break
@@ -334,7 +333,7 @@ open class BasicFormat: SyntaxRewriter {
334333
return true
335334
case .poundHasSymbolKeyword:
336335
return true
337-
case .spacedBinaryOperator:
336+
case .binaryOperator:
338337
return true
339338
case .contextualKeyword("async"):
340339
return true

Sources/SwiftParser/Declarations.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,14 @@ extension Parser {
547547

548548
enum ExpectedTokenKind: RawTokenKindSubset {
549549
case colon
550-
case spacedBinaryOperator
551-
case unspacedBinaryOperator
550+
case binaryOperator
552551
case postfixOperator
553552
case prefixOperator
554553

555554
init?(lexeme: Lexer.Lexeme) {
556555
switch (lexeme.tokenKind, lexeme.tokenText) {
557556
case (.colon, _): self = .colon
558-
case (.spacedBinaryOperator, "=="): self = .spacedBinaryOperator
559-
case (.unspacedBinaryOperator, "=="): self = .unspacedBinaryOperator
557+
case (.binaryOperator, "=="): self = .binaryOperator
560558
case (.postfixOperator, "=="): self = .postfixOperator
561559
case (.prefixOperator, "=="): self = .prefixOperator
562560
default: return nil
@@ -566,8 +564,7 @@ extension Parser {
566564
var rawTokenKind: RawTokenKind {
567565
switch self {
568566
case .colon: return .colon
569-
case .spacedBinaryOperator: return .spacedBinaryOperator
570-
case .unspacedBinaryOperator: return .unspacedBinaryOperator
567+
case .binaryOperator: return .binaryOperator
571568
case .postfixOperator: return .postfixOperator
572569
case .prefixOperator: return .prefixOperator
573570
}
@@ -639,8 +636,7 @@ extension Parser {
639636
)
640637
)
641638
}
642-
case (.spacedBinaryOperator, let handle)?,
643-
(.unspacedBinaryOperator, let handle)?,
639+
case (.binaryOperator, let handle)?,
644640
(.postfixOperator, let handle)?,
645641
(.prefixOperator, let handle)?:
646642
let equal = self.eat(handle)
@@ -1246,7 +1242,7 @@ extension Parser {
12461242
name = SyntaxText(rebasing: name.dropLast())
12471243
}
12481244
unexpectedBeforeIdentifier = nil
1249-
identifier = self.consumePrefix(name, as: .spacedBinaryOperator)
1245+
identifier = self.consumePrefix(name, as: .binaryOperator)
12501246
} else {
12511247
(unexpectedBeforeIdentifier, identifier) = self.expectIdentifier(keywordRecovery: true)
12521248
}
@@ -1821,7 +1817,7 @@ extension Parser {
18211817
} else {
18221818
unexpectedBeforeName = nil
18231819
}
1824-
name = missingToken(.spacedBinaryOperator, text: nil)
1820+
name = missingToken(.binaryOperator, text: nil)
18251821
}
18261822

18271823
// Eat any subsequent tokens that are not separated to the operator by trivia.

Sources/SwiftParser/Expressions.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ extension Parser {
227227
pattern: PatternContext
228228
) -> (operator: RawExprSyntax, rhs: RawExprSyntax?)? {
229229
enum ExpectedTokenKind: RawTokenKindSubset {
230-
case spacedBinaryOperator
231-
case unspacedBinaryOperator
230+
case binaryOperator
232231
case infixQuestionMark
233232
case equal
234233
case isKeyword
@@ -239,8 +238,7 @@ extension Parser {
239238

240239
init?(lexeme: Lexer.Lexeme) {
241240
switch lexeme.tokenKind {
242-
case .spacedBinaryOperator: self = .spacedBinaryOperator
243-
case .unspacedBinaryOperator: self = .unspacedBinaryOperator
241+
case .binaryOperator: self = .binaryOperator
244242
case .infixQuestionMark: self = .infixQuestionMark
245243
case .equal: self = .equal
246244
case .isKeyword: self = .isKeyword
@@ -254,8 +252,7 @@ extension Parser {
254252

255253
var rawTokenKind: RawTokenKind {
256254
switch self {
257-
case .spacedBinaryOperator: return .spacedBinaryOperator
258-
case .unspacedBinaryOperator: return .unspacedBinaryOperator
255+
case .binaryOperator: return .binaryOperator
259256
case .infixQuestionMark: return .infixQuestionMark
260257
case .equal: return .equal
261258
case .isKeyword: return .isKeyword
@@ -275,7 +272,7 @@ extension Parser {
275272
}
276273

277274
switch self.at(anyIn: ExpectedTokenKind.self) {
278-
case (.spacedBinaryOperator, let handle)?, (.unspacedBinaryOperator, let handle)?:
275+
case (.binaryOperator, let handle)?:
279276
// Parse the operator.
280277
let operatorToken = self.eat(handle)
281278
let op = RawBinaryOperatorExprSyntax(operatorToken: operatorToken, arena: arena)
@@ -1054,7 +1051,7 @@ extension Parser {
10541051
if self.at(any: [
10551052
.postfixOperator, .postfixQuestionMark,
10561053
.exclamationMark, .prefixOperator,
1057-
.unspacedBinaryOperator,
1054+
.binaryOperator,
10581055
]),
10591056
let numComponents = getNumOptionalKeyPathPostfixComponents(
10601057
self.currentToken.tokenText
@@ -2420,7 +2417,7 @@ extension Parser {
24202417
// this case lexes as a binary operator because it neither leads nor
24212418
// follows a proper subexpression.
24222419
let expr: RawExprSyntax
2423-
if self.at(anyIn: BinaryOperator.self) != nil
2420+
if self.at(.binaryOperator)
24242421
&& (self.peek().tokenKind == .comma || self.peek().tokenKind == .rightParen || self.peek().tokenKind == .rightSquareBracket)
24252422
{
24262423
let (ident, args) = self.parseDeclNameRef(.operators)
@@ -2581,8 +2578,7 @@ extension Parser.Lookahead {
25812578
.colon,
25822579
.equal,
25832580
.postfixOperator,
2584-
.spacedBinaryOperator,
2585-
.unspacedBinaryOperator:
2581+
.binaryOperator:
25862582
return !backtrack.currentToken.isAtStartOfLine
25872583
default:
25882584
return false

Sources/SwiftParser/Lexer.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,11 +1791,7 @@ extension Lexer.Cursor {
17911791
}
17921792

17931793
if leftBound == rightBound {
1794-
if leftBound {
1795-
return Lexer.Result(.unspacedBinaryOperator)
1796-
} else {
1797-
return Lexer.Result(.spacedBinaryOperator)
1798-
}
1794+
return Lexer.Result(.binaryOperator)
17991795
} else if leftBound {
18001796
return Lexer.Result(.postfixOperator)
18011797
} else {

Sources/SwiftParser/Names.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension Parser {
6767
if self.at(.identifier) || self.at(any: [.selfKeyword, .capitalSelfKeyword, .initKeyword]) {
6868
ident = self.expectIdentifierWithoutRecovery()
6969
} else if flags.contains(.operators), let (_, _) = self.at(anyIn: Operator.self) {
70-
ident = self.consumeAnyToken(remapping: .unspacedBinaryOperator)
70+
ident = self.consumeAnyToken(remapping: .binaryOperator)
7171
} else if flags.contains(.keywords) && self.currentToken.tokenKind.isKeyword {
7272
ident = self.consumeAnyToken(remapping: .identifier)
7373
} else {

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,6 @@ enum AccessorKind: SyntaxText, ContextualKeywords, Equatable {
8787
case _modify = "_modify"
8888
}
8989

90-
enum BinaryOperator: RawTokenKindSubset {
91-
case spacedBinaryOperator
92-
case unspacedBinaryOperator
93-
94-
init?(lexeme: Lexer.Lexeme) {
95-
switch lexeme.tokenKind {
96-
case .spacedBinaryOperator: self = .spacedBinaryOperator
97-
case .unspacedBinaryOperator: self = .unspacedBinaryOperator
98-
default: return nil
99-
}
100-
}
101-
102-
var rawTokenKind: RawTokenKind {
103-
switch self {
104-
case .spacedBinaryOperator: return .spacedBinaryOperator
105-
case .unspacedBinaryOperator: return .unspacedBinaryOperator
106-
}
107-
}
108-
}
109-
11090
enum CanBeStatementStart: RawTokenKindSubset {
11191
case breakKeyword
11292
case continueKeyword
@@ -413,15 +393,13 @@ enum IdentifierOrRethrowsTokens: RawTokenKindSubset {
413393
}
414394

415395
enum Operator: RawTokenKindSubset {
416-
case spacedBinaryOperator
417-
case unspacedBinaryOperator
396+
case binaryOperator
418397
case postfixOperator
419398
case prefixOperator
420399

421400
init?(lexeme: Lexer.Lexeme) {
422401
switch lexeme.tokenKind {
423-
case .spacedBinaryOperator: self = .spacedBinaryOperator
424-
case .unspacedBinaryOperator: self = .unspacedBinaryOperator
402+
case .binaryOperator: self = .binaryOperator
425403
case .postfixOperator: self = .postfixOperator
426404
case .prefixOperator: self = .prefixOperator
427405
default: return nil
@@ -430,8 +408,7 @@ enum Operator: RawTokenKindSubset {
430408

431409
var rawTokenKind: RawTokenKind {
432410
switch self {
433-
case .spacedBinaryOperator: return .spacedBinaryOperator
434-
case .unspacedBinaryOperator: return .unspacedBinaryOperator
411+
case .binaryOperator: return .binaryOperator
435412
case .postfixOperator: return .postfixOperator
436413
case .prefixOperator: return .prefixOperator
437414
}
@@ -489,7 +466,7 @@ enum OperatorLike: RawTokenKindSubset {
489466

490467
var precedence: TokenPrecedence? {
491468
switch self {
492-
case .regexLiteral: return TokenPrecedence(.spacedBinaryOperator)
469+
case .regexLiteral: return TokenPrecedence(.binaryOperator)
493470
default: return nil
494471
}
495472
}

Sources/SwiftParser/Statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ extension Parser.Lookahead {
12761276
// context. We always consider it an apply expression of a function
12771277
// called `yield` for the purposes of the parse.
12781278
return false
1279-
case .spacedBinaryOperator, .unspacedBinaryOperator:
1279+
case .binaryOperator:
12801280
// 'yield &= x' treats yield as an identifier.
12811281
return false
12821282
default:

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public enum TokenPrecedence: Comparable {
125125
// Keywords in function types (we should be allowed to skip them inside parenthesis)
126126
.rethrowsKeyword, .throwsKeyword,
127127
// Operators can occur inside expressions
128-
.postfixOperator, .prefixOperator, .spacedBinaryOperator, .unspacedBinaryOperator,
128+
.postfixOperator, .prefixOperator, .binaryOperator,
129129
// Consider 'any' and 'inout' like a prefix operator to a type and a type is expression-like.
130130
.anyKeyword, .inoutKeyword,
131131
// 'where' can only occur in the signature of declarations. Consider the signature expression-like.

0 commit comments

Comments
 (0)