diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 8d94078..5ad2afa 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -419,7 +419,7 @@ private extension SwiftGrammar { } // Handling generic lists for parameters, rather than declarations - if foundOpeningBracket && token == ":" { + if foundOpeningBracket && token.isAny(of: ":", ">:") { return true } diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index d44c05f..d6b1fef 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -368,6 +368,23 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testGenericSubclassDeclaration() { + let components = highlighter.highlight("class Promise: Future {}") + + XCTAssertEqual(components, [ + .token("class", .keyword), + .whitespace(" "), + .plainText("Promise:"), + .whitespace(" "), + .token("Future", .type), + .plainText("<"), + .token("Value", .type), + .plainText(">"), + .whitespace(" "), + .plainText("{}") + ]) + } + func testProtocolDeclaration() { let components = highlighter.highlight(""" protocol Hello { @@ -1161,6 +1178,7 @@ extension DeclarationTests { ("testClassDeclarationWithDeinit", testClassDeclarationWithDeinit), ("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances), ("testSubclassDeclaration", testSubclassDeclaration), + ("testGenericSubclassDeclaration", testGenericSubclassDeclaration), ("testProtocolDeclaration", testProtocolDeclaration), ("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes), ("testExtensionDeclaration", testExtensionDeclaration),