diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index a47064d..1c9f277 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -433,8 +433,10 @@ private extension SwiftGrammar { } // Handling generic lists for parameters, rather than declarations - if foundOpeningBracket && token.isAny(of: ":", ">:") { - return true + if foundOpeningBracket { + if token.isAny(of: ":", ">:") || token.first == "@" { + return true + } } guard !declarationKeywords.contains(token) else { diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index f49fd2c..baabf81 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -1093,6 +1093,33 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testPropertyWrapperDeclaration() { + let components = highlighter.highlight(""" + @propertyWrapper + struct Wrapped { + var wrappedValue: Value + } + """) + + XCTAssertEqual(components, [ + .token("@propertyWrapper", .keyword), + .whitespace("\n"), + .token("struct", .keyword), + .whitespace(" "), + .plainText("Wrapped"), + .whitespace(" "), + .plainText("{"), + .whitespace("\n "), + .token("var", .keyword), + .whitespace(" "), + .plainText("wrappedValue:"), + .whitespace(" "), + .token("Value", .type), + .whitespace("\n"), + .plainText("}") + ]) + } + func testWrappedPropertyDeclarations() { let components = highlighter.highlight(""" struct User { @@ -1151,6 +1178,37 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testWrappedPropertyDeclarationUsingExplicitType() { + let components = highlighter.highlight(""" + struct Model { + @Wrapper(key: "setting") + var setting + } + """) + + XCTAssertEqual(components, [ + .token("struct", .keyword), + .whitespace(" "), + .plainText("Model"), + .whitespace(" "), + .plainText("{"), + .whitespace("\n "), + .token("@Wrapper", .keyword), + .plainText("<"), + .token("Bool", .type), + .plainText(">(key:"), + .whitespace(" "), + .token(#""setting""#, .string), + .plainText(")"), + .whitespace("\n "), + .token("var", .keyword), + .whitespace(" "), + .plainText("setting"), + .whitespace("\n"), + .plainText("}") + ]) + } + func testGenericInitializerDeclaration() { let components = highlighter.highlight(""" struct Box { @@ -1232,8 +1290,10 @@ extension DeclarationTests { ("testPrefixFunctionDeclaration", testPrefixFunctionDeclaration), ("testEnumDeclarationWithSomeCase", testEnumDeclarationWithSomeCase), ("testIndirectEnumDeclaration", testIndirectEnumDeclaration), + ("testPropertyWrapperDeclaration", testPropertyWrapperDeclaration), ("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations), ("testWrappedPropertyDeclarationUsingNestedType", testWrappedPropertyDeclarationUsingNestedType), + ("testWrappedPropertyDeclarationUsingExplicitType", testWrappedPropertyDeclarationUsingExplicitType), ("testGenericInitializerDeclaration", testGenericInitializerDeclaration) ] }