Skip to content

Commit

Permalink
Fix syntax highlighting for leading function calls within closures (#102
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
JohnSundell authored Apr 16, 2020
1 parent 26d4bbe commit 8e96992
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Sources/Splash/Grammar/SwiftGrammar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ private extension SwiftGrammar {
keywordsToAvoid.remove("try")
keywordsToAvoid.remove("throw")
keywordsToAvoid.remove("if")
keywordsToAvoid.remove("in")
self.keywordsToAvoid = keywordsToAvoid

var callLikeKeywords = accessControlKeywords
Expand Down
22 changes: 21 additions & 1 deletion Tests/SplashTests/Tests/ClosureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ final class ClosureTests: SyntaxHighlighterTestCase {
])
}

func testClosureWithSingleFunctionCall() {
let components = highlighter.highlight("closure { a in call(a) }")

XCTAssertEqual(components, [
.token("closure", .call),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("a"),
.whitespace(" "),
.token("in", .keyword),
.whitespace(" "),
.token("call", .call),
.plainText("(a)"),
.whitespace(" "),
.plainText("}")
])
}

func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
Expand All @@ -260,7 +279,8 @@ extension ClosureTests {
("testNestedEscapingClosure", testNestedEscapingClosure),
("testClosureArgumentShorthands", testClosureArgumentShorthands),
("testClosureWithWeakSelfCaptureList", testClosureWithWeakSelfCaptureList),
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList)
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList),
("testClosureWithSingleFunctionCall", testClosureWithSingleFunctionCall)
]
}
}

0 comments on commit 8e96992

Please sign in to comment.