Skip to content

Commit b6c489c

Browse files
authored
Correctly highlight the “try” keyword when used within a function call (JohnSundell#104)
This change makes Splash highlight the `try` keyword when it appears within a function’s argument list.
1 parent 03ea9bd commit b6c489c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Sources/Splash/Grammar/SwiftGrammar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private extension SwiftGrammar {
354354
}
355355

356356
// Don't highlight most keywords when used as a parameter label
357-
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout", "nil") {
357+
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout", "nil", "try") {
358358
guard !previousToken.isAny(of: "(", ",", ">(") else {
359359
return false
360360
}

Tests/SplashTests/Tests/FunctionCallTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
170170
])
171171
}
172172

173+
func testUsingTryKeywordWithinFunctionCall() {
174+
let components = highlighter.highlight("XCTAssertThrowsError(try function())")
175+
176+
XCTAssertEqual(components, [
177+
.token("XCTAssertThrowsError", .call),
178+
.plainText("("),
179+
.token("try", .keyword),
180+
.whitespace(" "),
181+
.token("function", .call),
182+
.plainText("())")
183+
])
184+
}
185+
173186
func testAllTestsRunOnLinux() {
174187
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
175188
}
@@ -189,7 +202,8 @@ extension FunctionCallTests {
189202
("testPassingTypeToFunction", testPassingTypeToFunction),
190203
("testPassingBoolToUnnamedArgument", testPassingBoolToUnnamedArgument),
191204
("testIndentedFunctionCalls", testIndentedFunctionCalls),
192-
("testXCTAssertCalls", testXCTAssertCalls)
205+
("testXCTAssertCalls", testXCTAssertCalls),
206+
("testUsingTryKeywordWithinFunctionCall", testUsingTryKeywordWithinFunctionCall)
193207
]
194208
}
195209
}

0 commit comments

Comments
 (0)