Skip to content

Commit 8520cc1

Browse files
committed
Merge spacedBinaryOperator and unspacedBinaryOperator
rdar://103774663
1 parent f5f6ae2 commit 8520cc1

38 files changed

+105
-216
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"),

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -334,7 +334,7 @@ open class BasicFormat: SyntaxRewriter {
334334
return true
335335
case .poundHasSymbolKeyword:
336336
return true
337-
case .spacedBinaryOperator:
337+
case .binaryOperator:
338338
return true
339339
case .contextualKeyword("async"):
340340
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.

Sources/SwiftParser/Types.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,13 +1050,8 @@ extension Parser {
10501050
}
10511051

10521052
extension Lexer.Lexeme {
1053-
var isBinaryOperator: Bool {
1054-
return self.tokenKind == .spacedBinaryOperator
1055-
|| self.tokenKind == .unspacedBinaryOperator
1056-
}
1057-
10581053
var isAnyOperator: Bool {
1059-
return self.isBinaryOperator
1054+
return self.tokenKind == .binaryOperator
10601055
|| self.tokenKind == .postfixOperator
10611056
|| self.tokenKind == .prefixOperator
10621057
}
@@ -1079,10 +1074,9 @@ extension Lexer.Lexeme {
10791074
.postfixQuestionMark,
10801075
.colon:
10811076
return true
1082-
case .spacedBinaryOperator:
1077+
case .binaryOperator:
10831078
return self.tokenText == "&"
1084-
case .unspacedBinaryOperator,
1085-
.postfixOperator:
1079+
case .postfixOperator:
10861080
return false
10871081
case .leftParen, .leftSquareBracket:
10881082
// These only apply to the generic type if they don't start a new line.

Sources/SwiftSyntax/SyntaxFactory.swift.gyb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,6 @@ public enum SyntaxFactory {
228228
trailingTrivia: trailingTrivia)
229229
}
230230

231-
@available(*, deprecated, message: "Use TokenSyntax.spacedBinaryOperator")
232-
public static func makeBinaryOperator(_ name: String,
233-
leadingTrivia: Trivia = [],
234-
trailingTrivia: Trivia = []) -> TokenSyntax {
235-
return makeToken(.spacedBinaryOperator(name),
236-
presence: .present,
237-
leadingTrivia: leadingTrivia,
238-
trailingTrivia: trailingTrivia)
239-
}
240-
241231
@available(*, deprecated, message: "Use initializer on StringLiteralExprSyntax")
242232
public static func makeStringLiteralExpr(_ text: String,
243233
leadingTrivia: Trivia = [],

0 commit comments

Comments
 (0)