From d978081933e2abd1ad275c8622c740ea478f7cf4 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Sun, 9 Jun 2019 12:33:00 +0200 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20Swift=205.1=E2=80=99s=20o?= =?UTF-8?q?paque=20return=20types=20(#71)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds support for the Swift 5.1 `some` keyword, which is used to declare opaque return types. --- Sources/Splash/Grammar/SwiftGrammar.swift | 2 +- .../SplashTests/Tests/DeclarationTests.swift | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index 40b47d9..87d468d 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -52,7 +52,7 @@ private extension SwiftGrammar { "lazy", "subscript", "defer", "inout", "while", "continue", "fallthrough", "repeat", "indirect", "deinit", "is", "#file", "#line", "#function", - "dynamic" + "dynamic", "some" ] as Set).union(accessControlKeywords) static let accessControlKeywords: Set = [ diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index 80df6eb..f7c5f1d 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -858,6 +858,31 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testFunctionDeclarationWithOpaqueReturnType() { + let components = highlighter.highlight(#"func make() -> some View { Text("!") }"#) + + XCTAssertEqual(components, [ + .token("func", .keyword), + .whitespace(" "), + .plainText("make()"), + .whitespace(" "), + .plainText("->"), + .whitespace(" "), + .token("some", .keyword), + .whitespace(" "), + .token("View", .type), + .whitespace(" "), + .plainText("{"), + .whitespace(" "), + .token("Text", .type), + .plainText("("), + .token(#""!""#, .string), + .plainText(")"), + .whitespace(" "), + .plainText("}") + ]) + } + func testIndirectEnumDeclaration() { let components = highlighter.highlight(""" indirect enum Content { @@ -934,6 +959,7 @@ extension DeclarationTests { ("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors), ("testNonMutatingFunction", testNonMutatingFunction), ("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration), + ("testFunctionDeclarationWithOpaqueReturnType", testFunctionDeclarationWithOpaqueReturnType), ("testIndirectEnumDeclaration", testIndirectEnumDeclaration) ] }