Skip to content

Commit 465b4e5

Browse files
committed
Add leading space for in keyword
1 parent edd2d0c commit 465b4e5

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
230230
StmtKeywordSpec(name: "Repeat", text: "repeat", requiresTrailingSpace: true),
231231
StmtKeywordSpec(name: "Else", text: "else", requiresTrailingSpace: true),
232232
StmtKeywordSpec(name: "For", text: "for", requiresTrailingSpace: true),
233-
StmtKeywordSpec(name: "In", text: "in", requiresTrailingSpace: true),
233+
StmtKeywordSpec(name: "In", text: "in", requiresLeadingSpace: true, requiresTrailingSpace: true),
234234
StmtKeywordSpec(name: "While", text: "while", requiresTrailingSpace: true),
235235
StmtKeywordSpec(name: "Return", text: "return", requiresTrailingSpace: true),
236236
StmtKeywordSpec(name: "Break", text: "break", requiresTrailingSpace: true),

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ open class BasicFormat: SyntaxRewriter {
125125

126126
open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool {
127127
switch token.tokenKind {
128+
case .inKeyword:
129+
return true
128130
case .whereKeyword:
129131
return true
130132
case .catchKeyword:

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8997,7 +8997,7 @@ public enum SyntaxFactory {
89978997
}
89988998
@available(*, deprecated, message: "Use TokenSyntax.inKeywordKeyword instead")
89998999
public static func makeInKeyword(
9000-
leadingTrivia: Trivia = [],
9000+
leadingTrivia: Trivia = .space,
90019001
trailingTrivia: Trivia = .space
90029002
) -> TokenSyntax {
90039003
return makeToken(.inKeyword, presence: .present,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
import SwiftSyntax
15+
import SwiftSyntaxBuilder
16+
17+
final class ClosureExprTests: XCTestCase {
18+
func testClosureExpr() {
19+
let buildable = ClosureExpr(
20+
signature: ClosureSignature(
21+
input: .simpleInput(
22+
ClosureParamList {
23+
ClosureParamSyntax(name: .identifier("area"))
24+
}
25+
)
26+
)
27+
) {}
28+
29+
AssertBuildResult(
30+
buildable,
31+
"""
32+
{area in
33+
}
34+
"""
35+
)
36+
}
37+
}

gyb_syntax_support/Token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def macro_name(self):
216216
StmtKeyword('Repeat', 'repeat'),
217217
StmtKeyword('Else', 'else'),
218218
StmtKeyword('For', 'for'),
219-
StmtKeyword('In', 'in'),
219+
StmtKeyword('In', 'in', requires_leading_space=True),
220220
StmtKeyword('While', 'while'),
221221
StmtKeyword('Return', 'return'),
222222
StmtKeyword('Break', 'break'),

0 commit comments

Comments
 (0)