Skip to content

Commit 8e96992

Browse files
authored
Fix syntax highlighting for leading function calls within closures (JohnSundell#102)
This patch fixes syntax highlighting when a function call appears as the first expression within a closure that accepts arguments or capture lists using the ‘in’ keyword.
1 parent 26d4bbe commit 8e96992

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Sources/Splash/Grammar/SwiftGrammar.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ private extension SwiftGrammar {
231231
keywordsToAvoid.remove("try")
232232
keywordsToAvoid.remove("throw")
233233
keywordsToAvoid.remove("if")
234+
keywordsToAvoid.remove("in")
234235
self.keywordsToAvoid = keywordsToAvoid
235236

236237
var callLikeKeywords = accessControlKeywords

Tests/SplashTests/Tests/ClosureTests.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,25 @@ final class ClosureTests: SyntaxHighlighterTestCase {
241241
])
242242
}
243243

244+
func testClosureWithSingleFunctionCall() {
245+
let components = highlighter.highlight("closure { a in call(a) }")
246+
247+
XCTAssertEqual(components, [
248+
.token("closure", .call),
249+
.whitespace(" "),
250+
.plainText("{"),
251+
.whitespace(" "),
252+
.plainText("a"),
253+
.whitespace(" "),
254+
.token("in", .keyword),
255+
.whitespace(" "),
256+
.token("call", .call),
257+
.plainText("(a)"),
258+
.whitespace(" "),
259+
.plainText("}")
260+
])
261+
}
262+
244263
func testAllTestsRunOnLinux() {
245264
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
246265
}
@@ -260,7 +279,8 @@ extension ClosureTests {
260279
("testNestedEscapingClosure", testNestedEscapingClosure),
261280
("testClosureArgumentShorthands", testClosureArgumentShorthands),
262281
("testClosureWithWeakSelfCaptureList", testClosureWithWeakSelfCaptureList),
263-
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList)
282+
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList),
283+
("testClosureWithSingleFunctionCall", testClosureWithSingleFunctionCall)
264284
]
265285
}
266286
}

0 commit comments

Comments
 (0)