diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index f50e5ef..1a9a628 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -286,7 +286,7 @@ private extension SwiftGrammar { return false } - guard segment.tokens.current != "self" else { + guard !segment.tokens.current.isAny(of: "self", "init") else { return false } diff --git a/Tests/SplashTests/Tests/FunctionCallTests.swift b/Tests/SplashTests/Tests/FunctionCallTests.swift index 13b52e4..7d46283 100644 --- a/Tests/SplashTests/Tests/FunctionCallTests.swift +++ b/Tests/SplashTests/Tests/FunctionCallTests.swift @@ -55,6 +55,24 @@ final class FunctionCallTests: SyntaxHighlighterTestCase { ]) } + func testDotSyntaxInitializerCall() { + let components = highlighter.highlight("let string: String = .init()") + + XCTAssertEqual(components, [ + .token("let", .keyword), + .whitespace(" "), + .plainText("string:"), + .whitespace(" "), + .token("String", .type), + .whitespace(" "), + .plainText("="), + .whitespace(" "), + .plainText("."), + .token("init", .keyword), + .plainText("()") + ]) + } + func testAccessingPropertyAfterFunctionCallWithoutArguments() { let components = highlighter.highlight("call().property") @@ -112,6 +130,7 @@ extension FunctionCallTests { ("testFunctionCallWithIntegers", testFunctionCallWithIntegers), ("testImplicitInitializerCall", testImplicitInitializerCall), ("testExplicitInitializerCall", testExplicitInitializerCall), + ("testDotSyntaxInitializerCall", testDotSyntaxInitializerCall), ("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments), ("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments), ("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType),