Skip to content

Commit ccc812e

Browse files
authored
Merge pull request #1751 from kimdv/kimdv/1749-rename-tokenkindleftsquarebracket-to-tokenkindleftsquare
Rename `leftSquareBracket` and `rightSquareBracket`
2 parents 4db7cb2 + 8de4b83 commit ccc812e

36 files changed

+572
-321
lines changed

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public let EXPR_NODES: [Node] = [
4848
children: [
4949
Child(
5050
name: "LeftSquare",
51-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
51+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
5252
),
5353
Child(
5454
name: "Elements",
@@ -57,7 +57,7 @@ public let EXPR_NODES: [Node] = [
5757
),
5858
Child(
5959
name: "RightSquare",
60-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
60+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
6161
),
6262
]
6363
),
@@ -341,7 +341,7 @@ public let EXPR_NODES: [Node] = [
341341
children: [
342342
Child(
343343
name: "LeftSquare",
344-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
344+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
345345
),
346346
Child(
347347
name: "Items",
@@ -350,7 +350,7 @@ public let EXPR_NODES: [Node] = [
350350
),
351351
Child(
352352
name: "RightSquare",
353-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
353+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
354354
),
355355
]
356356
),
@@ -654,7 +654,7 @@ public let EXPR_NODES: [Node] = [
654654
children: [
655655
Child(
656656
name: "LeftSquare",
657-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
657+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
658658
),
659659
Child(
660660
name: "Content",
@@ -672,7 +672,7 @@ public let EXPR_NODES: [Node] = [
672672
),
673673
Child(
674674
name: "RightSquare",
675-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
675+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
676676
),
677677
]
678678
),
@@ -1106,7 +1106,7 @@ public let EXPR_NODES: [Node] = [
11061106
children: [
11071107
Child(
11081108
name: "LeftBracket",
1109-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
1109+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
11101110
),
11111111
Child(
11121112
name: "ArgumentList",
@@ -1115,7 +1115,7 @@ public let EXPR_NODES: [Node] = [
11151115
),
11161116
Child(
11171117
name: "RightBracket",
1118-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
1118+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
11191119
),
11201120
]
11211121
),
@@ -1506,7 +1506,7 @@ public let EXPR_NODES: [Node] = [
15061506
),
15071507
Child(
15081508
name: "LeftBracket",
1509-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
1509+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
15101510
),
15111511
Child(
15121512
name: "ArgumentList",
@@ -1515,7 +1515,7 @@ public let EXPR_NODES: [Node] = [
15151515
),
15161516
Child(
15171517
name: "RightBracket",
1518-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
1518+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
15191519
),
15201520
Child(
15211521
name: "TrailingClosure",

CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
194194
PunctuatorSpec(name: "LeftAngle", kind: "l_angle", text: "<"),
195195
PunctuatorSpec(name: "LeftBrace", kind: "l_brace", text: "{", requiresLeadingSpace: true),
196196
PunctuatorSpec(name: "LeftParen", kind: "l_paren", text: "("),
197-
PunctuatorSpec(name: "LeftSquareBracket", kind: "l_square", text: "["),
197+
PunctuatorSpec(name: "LeftSquare", kind: "l_square", text: "["),
198198
PunctuatorSpec(name: "MultilineStringQuote", kind: "multiline_string_quote", text: "\"\"\"", classification: "StringLiteral"),
199199
PunctuatorSpec(name: "Period", kind: "period", text: "."),
200200
MiscSpec(name: "PostfixOperator", kind: "oper_postfix", nameForDiagnostics: "postfix operator", classification: "OperatorIdentifier"),
@@ -215,7 +215,7 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
215215
PunctuatorSpec(name: "RightAngle", kind: "r_angle", text: ">"),
216216
PunctuatorSpec(name: "RightBrace", kind: "r_brace", text: "}"),
217217
PunctuatorSpec(name: "RightParen", kind: "r_paren", text: ")"),
218-
PunctuatorSpec(name: "RightSquareBracket", kind: "r_square", text: "]"),
218+
PunctuatorSpec(name: "RightSquare", kind: "r_square", text: "]"),
219219
PunctuatorSpec(name: "Semicolon", kind: "semi", text: ";"),
220220
PunctuatorSpec(name: "SingleQuote", kind: "single_quote", text: "\'", classification: "StringLiteral"),
221221
PunctuatorSpec(name: "StringQuote", kind: "string_quote", text: "\"", classification: "StringLiteral"),

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public let TYPE_NODES: [Node] = [
1818
nameForDiagnostics: "array type",
1919
children: [
2020
Child(
21-
name: "LeftSquareBracket",
22-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
21+
name: "LeftSquare",
22+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
2323
),
2424
Child(
2525
name: "ElementType",
2626
kind: .node(kind: .type)
2727
),
2828
Child(
29-
name: "RightSquareBracket",
30-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
29+
name: "RightSquare",
30+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
3131
),
3232
]
3333
),
@@ -143,8 +143,8 @@ public let TYPE_NODES: [Node] = [
143143
nameForDiagnostics: "dictionary type",
144144
children: [
145145
Child(
146-
name: "LeftSquareBracket",
147-
kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])
146+
name: "LeftSquare",
147+
kind: .token(choices: [.token(tokenKind: "LeftSquareToken")])
148148
),
149149
Child(
150150
name: "KeyType",
@@ -161,8 +161,8 @@ public let TYPE_NODES: [Node] = [
161161
nameForDiagnostics: "value type"
162162
),
163163
Child(
164-
name: "RightSquareBracket",
165-
kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])
164+
name: "RightSquare",
165+
kind: .token(choices: [.token(tokenKind: "RightSquareToken")])
166166
),
167167
]
168168
),

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ open class BasicFormat: SyntaxRewriter {
203203
(.extendedRegexDelimiter, .regexSlash), // opening extended regex delimiter should never be separate by a space
204204
(.identifier, .leftAngle), // MyType<Int>
205205
(.identifier, .leftParen), // foo()
206-
(.identifier, .leftSquareBracket), // myArray[1]
206+
(.identifier, .leftSquare), // myArray[1]
207207
(.identifier, .period), // a.b
208208
(.integerLiteral, .period), // macOS 11.2.1
209209
(.keyword(.`init`), .leftAngle), // init<T>()
@@ -215,7 +215,7 @@ open class BasicFormat: SyntaxRewriter {
215215
(.keyword(.super), .period), // super.someProperty
216216
(.leftBrace, _),
217217
(.leftParen, _),
218-
(.leftSquareBracket, _),
218+
(.leftSquare, _),
219219
(.multilineStringQuote, .rawStringDelimiter), // closing raw string delimiter should never be separate by a space
220220
(.period, _),
221221
(.postfixQuestionMark, .leftAngle), // init?<T>()
@@ -235,7 +235,7 @@ open class BasicFormat: SyntaxRewriter {
235235
(.rightBrace, .leftParen), // { return 1 }()
236236
(.rightParen, .leftParen), // returnsClosure()()
237237
(.rightParen, .period), // foo().bar
238-
(.rightSquareBracket, .period), // myArray[1].someProperty
238+
(.rightSquare, .period), // myArray[1].someProperty
239239
(.singleQuote, .rawStringDelimiter), // closing raw string delimiter should never be separate by a space
240240
(.stringQuote, .rawStringDelimiter), // closing raw string delimiter should never be separate by a space
241241
(.stringSegment, _),
@@ -247,7 +247,7 @@ open class BasicFormat: SyntaxRewriter {
247247
(_, .postfixQuestionMark),
248248
(_, .rightBrace),
249249
(_, .rightParen),
250-
(_, .rightSquareBracket),
250+
(_, .rightSquare),
251251
(_, .semicolon),
252252
(_, nil),
253253
(nil, _):

Sources/SwiftIDEUtils/generated/SyntaxClassification.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extension RawTokenKind {
144144
return .none
145145
case .leftParen:
146146
return .none
147-
case .leftSquareBracket:
147+
case .leftSquare:
148148
return .none
149149
case .multilineStringQuote:
150150
return .stringLiteral
@@ -186,7 +186,7 @@ extension RawTokenKind {
186186
return .none
187187
case .rightParen:
188188
return .none
189-
case .rightSquareBracket:
189+
case .rightSquare:
190190
return .none
191191
case .semicolon:
192192
return .none

Sources/SwiftParser/Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ extension Parser.Lookahead {
11701170
TokenSpec(.rethrows),
11711171
TokenSpec(.rightParen),
11721172
TokenSpec(.rightBrace),
1173-
TokenSpec(.rightSquareBracket),
1173+
TokenSpec(.rightSquare),
11741174
TokenSpec(.rightAngle):
11751175
return false
11761176
case _ where lookahead.at(.keyword(.async)):

Sources/SwiftParser/Expressions.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,14 @@ extension Parser {
813813

814814
// Check for a [expr] suffix.
815815
// Note that this cannot be the start of a new line.
816-
if let lsquare = self.consume(if: TokenSpec(.leftSquareBracket, allowAtStartOfLine: false)) {
816+
if let lsquare = self.consume(if: TokenSpec(.leftSquare, allowAtStartOfLine: false)) {
817817
let args: [RawTupleExprElementSyntax]
818-
if self.at(.rightSquareBracket) {
818+
if self.at(.rightSquare) {
819819
args = []
820820
} else {
821821
args = self.parseArgumentListElements(pattern: pattern)
822822
}
823-
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquareBracket)
823+
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquare)
824824

825825
// If we can parse trailing closures, do so.
826826
let trailingClosure: RawClosureExprSyntax?
@@ -1053,26 +1053,26 @@ extension Parser {
10531053
while loopCondition.evaluate(currentToken) {
10541054
// Check for a [] or .[] suffix. The latter is only permitted when there
10551055
// are no components.
1056-
if self.at(TokenSpec(.leftSquareBracket, allowAtStartOfLine: false))
1057-
|| (components.isEmpty && self.at(.period) && self.peek().rawTokenKind == .leftSquareBracket)
1056+
if self.at(TokenSpec(.leftSquare, allowAtStartOfLine: false))
1057+
|| (components.isEmpty && self.at(.period) && self.peek().rawTokenKind == .leftSquare)
10581058
{
10591059
// Consume the '.', if it's allowed here.
10601060
let period: RawTokenSyntax?
1061-
if !self.at(.leftSquareBracket) {
1061+
if !self.at(.leftSquare) {
10621062
period = self.consumeAnyToken()
10631063
} else {
10641064
period = nil
10651065
}
10661066

1067-
precondition(self.at(.leftSquareBracket))
1067+
precondition(self.at(.leftSquare))
10681068
let lsquare = self.consumeAnyToken()
10691069
let args: [RawTupleExprElementSyntax]
1070-
if self.at(.rightSquareBracket) {
1070+
if self.at(.rightSquare) {
10711071
args = []
10721072
} else {
10731073
args = self.parseArgumentListElements(pattern: pattern)
10741074
}
1075-
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquareBracket)
1075+
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquare)
10761076

10771077
components.append(
10781078
RawKeyPathComponentSyntax(
@@ -1335,7 +1335,7 @@ extension Parser {
13351335
// element without label.
13361336
return RawExprSyntax(self.parseTupleExpression(pattern: pattern))
13371337

1338-
case (.leftSquareBracket, _)?:
1338+
case (.leftSquare, _)?:
13391339
return self.parseCollectionLiteral()
13401340

13411341
case nil:
@@ -1637,17 +1637,17 @@ extension Parser {
16371637
return RawExprSyntax(
16381638
RawArrayExprSyntax(
16391639
remainingTokens,
1640-
leftSquare: missingToken(.leftSquareBracket),
1640+
leftSquare: missingToken(.leftSquare),
16411641
elements: RawArrayElementListSyntax(elements: [], arena: self.arena),
1642-
rightSquare: missingToken(.rightSquareBracket),
1642+
rightSquare: missingToken(.rightSquare),
16431643
arena: self.arena
16441644
)
16451645
)
16461646
}
16471647

1648-
let (unexpectedBeforeLSquare, lsquare) = self.expect(.leftSquareBracket)
1648+
let (unexpectedBeforeLSquare, lsquare) = self.expect(.leftSquare)
16491649

1650-
if let rsquare = self.consume(if: .rightSquareBracket) {
1650+
if let rsquare = self.consume(if: .rightSquare) {
16511651
return RawExprSyntax(
16521652
RawArrayExprSyntax(
16531653
unexpectedBeforeLSquare,
@@ -1659,7 +1659,7 @@ extension Parser {
16591659
)
16601660
}
16611661

1662-
if let (colon, rsquare) = self.consume(if: .colon, followedBy: .rightSquareBracket) {
1662+
if let (colon, rsquare) = self.consume(if: .colon, followedBy: .rightSquare) {
16631663
// FIXME: We probably want a separate node for the empty case.
16641664
return RawExprSyntax(
16651665
RawDictionaryExprSyntax(
@@ -1713,12 +1713,12 @@ extension Parser {
17131713
// If we saw a comma, that's a strong indicator we have more elements
17141714
// to process. If that's not the case, we have to do some legwork to
17151715
// determine if we should bail out.
1716-
guard comma == nil || self.at(.rightSquareBracket, .eof) else {
1716+
guard comma == nil || self.at(.rightSquare, .eof) else {
17171717
continue
17181718
}
17191719

17201720
// If we found EOF or the closing square bracket, bailout.
1721-
if self.at(.rightSquareBracket, .eof) {
1721+
if self.at(.rightSquare, .eof) {
17221722
break
17231723
}
17241724

@@ -1732,7 +1732,7 @@ extension Parser {
17321732
}
17331733
}
17341734

1735-
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquareBracket)
1735+
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquare)
17361736
switch elementKind! {
17371737
case .dictionary:
17381738
return RawExprSyntax(
@@ -1862,7 +1862,7 @@ extension Parser {
18621862
mutating func parseClosureSignatureIfPresent() -> RawClosureSignatureSyntax? {
18631863
// If we have a leading token that may be part of the closure signature, do a
18641864
// speculative parse to validate it and look for 'in'.
1865-
guard self.at(.atSign, .leftParen, .leftSquareBracket) || self.at(.wildcard, .identifier) else {
1865+
guard self.at(.atSign, .leftParen, .leftSquare) || self.at(.wildcard, .identifier) else {
18661866
// No closure signature.
18671867
return nil
18681868
}
@@ -1874,11 +1874,11 @@ extension Parser {
18741874
let attrs = self.parseAttributeList()
18751875

18761876
let captures: RawClosureCaptureSignatureSyntax?
1877-
if let lsquare = self.consume(if: .leftSquareBracket) {
1877+
if let lsquare = self.consume(if: .leftSquare) {
18781878
// At this point, we know we have a closure signature. Parse the capture list
18791879
// and parameters.
18801880
var elements = [RawClosureCaptureItemSyntax]()
1881-
if !self.at(.rightSquareBracket) {
1881+
if !self.at(.rightSquare) {
18821882
var keepGoing: RawTokenSyntax? = nil
18831883
var loopProgress = LoopProgressCondition()
18841884
repeat {
@@ -1924,10 +1924,10 @@ extension Parser {
19241924
}
19251925
// We were promised a right square bracket, so we're going to get it.
19261926
var unexpectedNodes = [RawSyntax]()
1927-
while !self.at(.eof) && !self.at(.rightSquareBracket) && !self.at(.keyword(.in)) {
1927+
while !self.at(.eof) && !self.at(.rightSquare) && !self.at(.keyword(.in)) {
19281928
unexpectedNodes.append(RawSyntax(self.consumeAnyToken()))
19291929
}
1930-
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquareBracket)
1930+
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquare)
19311931
unexpectedNodes.append(contentsOf: unexpectedBeforeRSquare?.elements ?? [])
19321932

19331933
captures = RawClosureCaptureSignatureSyntax(
@@ -2090,7 +2090,7 @@ extension Parser {
20902090
// follows a proper subexpression.
20912091
let expr: RawExprSyntax
20922092
if self.at(.binaryOperator)
2093-
&& (self.peek().rawTokenKind == .comma || self.peek().rawTokenKind == .rightParen || self.peek().rawTokenKind == .rightSquareBracket)
2093+
&& (self.peek().rawTokenKind == .comma || self.peek().rawTokenKind == .rightParen || self.peek().rawTokenKind == .rightSquare)
20942094
{
20952095
let (ident, args) = self.parseDeclNameRef(.operators)
20962096
expr = RawExprSyntax(
@@ -2246,7 +2246,7 @@ extension Parser.Lookahead {
22462246
TokenSpec(.where),
22472247
TokenSpec(.comma):
22482248
return true
2249-
case TokenSpec(.leftSquareBracket),
2249+
case TokenSpec(.leftSquare),
22502250
TokenSpec(.leftParen),
22512251
TokenSpec(.period),
22522252
TokenSpec(.is),
@@ -2679,9 +2679,9 @@ extension Parser.Lookahead {
26792679
}
26802680

26812681
// Skip by a closure capture list if present.
2682-
if lookahead.consume(if: .leftSquareBracket) != nil {
2683-
lookahead.skipUntil(.rightSquareBracket, .rightSquareBracket)
2684-
if lookahead.consume(if: .rightSquareBracket) == nil {
2682+
if lookahead.consume(if: .leftSquare) != nil {
2683+
lookahead.skipUntil(.rightSquare, .rightSquare)
2684+
if lookahead.consume(if: .rightSquare) == nil {
26852685
return false
26862686
}
26872687
}

0 commit comments

Comments
 (0)