diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 1d3942f..df6225c 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -41,7 +41,7 @@ private extension SwiftGrammar { "final", "class", "struct", "enum", "protocol", "extension", "let", "var", "func", "typealias", "init", "guard", "if", "else", "return", "get", - "throw", "throws", "for", "in", "open", "weak", + "throw", "throws", "rethrows", "for", "in", "open", "weak", "import", "mutating", "nonmutating", "associatedtype", "case", "switch", "static", "do", "try", "catch", "as", "super", "self", "set", "true", "false", "nil", diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index 688f8e3..664d274 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -635,7 +635,7 @@ final class DeclarationTests: SyntaxHighlighterTestCase { .token("inout", .keyword), .whitespace(" "), .token("Int", .type), - .plainText(")"), + .plainText(")"), .whitespace(" "), .plainText("{"), .whitespace(" "), @@ -750,6 +750,40 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testRethrowingFunctionDeclaration() { + let components = highlighter.highlight(""" + func map(_ transform: (Element) throws -> T) rethrows -> [T] + """) + + XCTAssertEqual(components, [ + .token("func", .keyword), + .whitespace(" "), + .plainText("map("), + .token("_", .keyword), + .whitespace(" "), + .plainText("transform:"), + .whitespace(" "), + .plainText("("), + .token("Element", .type), + .plainText(")"), + .whitespace(" "), + .token("throws", .keyword), + .whitespace(" "), + .plainText("->"), + .whitespace(" "), + .token("T", .type), + .plainText(")"), + .whitespace(" "), + .token("rethrows", .keyword), + .whitespace(" "), + .plainText("->"), + .whitespace(" "), + .plainText("["), + .token("T", .type), + .plainText("]") + ]) + } + func testIndirectEnumDeclaration() { let components = highlighter.highlight(""" indirect enum Content { @@ -822,6 +856,7 @@ extension DeclarationTests { ("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName), ("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors), ("testNonMutatingFunction", testNonMutatingFunction), + ("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration), ("testIndirectEnumDeclaration", testIndirectEnumDeclaration) ] }