diff --git a/Sources/Splash/Grammar/SwiftGrammar.swift b/Sources/Splash/Grammar/SwiftGrammar.swift index d98aba4..0a4a023 100644 --- a/Sources/Splash/Grammar/SwiftGrammar.swift +++ b/Sources/Splash/Grammar/SwiftGrammar.swift @@ -41,8 +41,8 @@ private extension SwiftGrammar { "extension", "let", "var", "func", "typealias", "init", "guard", "if", "else", "return", "get", "throw", "throws", "for", "in", "open", "weak", - "import", "mutating", "associatedtype", "case", - "switch", "static", "do", "try", "catch", "as", + "import", "mutating", "nonmutating", "associatedtype", + "case", "switch", "static", "do", "try", "catch", "as", "super", "self", "set", "true", "false", "nil", "override", "where", "_", "default", "break", "#selector", "required", "willSet", "didSet", diff --git a/Tests/SplashTests/Tests/DeclarationTests.swift b/Tests/SplashTests/Tests/DeclarationTests.swift index 97c015c..688f8e3 100644 --- a/Tests/SplashTests/Tests/DeclarationTests.swift +++ b/Tests/SplashTests/Tests/DeclarationTests.swift @@ -722,6 +722,34 @@ final class DeclarationTests: SyntaxHighlighterTestCase { ]) } + func testNonMutatingFunction() { + let components = highlighter.highlight(""" + struct MyStruct { + nonmutating func doNotChangeState() { } + } + """) + + XCTAssertEqual(components, [ + .token("struct", .keyword), + .whitespace(" "), + .plainText("MyStruct"), + .whitespace(" "), + .plainText("{"), + .whitespace("\n "), + .token("nonmutating", .keyword), + .whitespace(" "), + .token("func", .keyword), + .whitespace(" "), + .plainText("doNotChangeState()"), + .whitespace(" "), + .plainText("{"), + .whitespace(" "), + .plainText("}"), + .whitespace("\n"), + .plainText("}") + ]) + } + func testIndirectEnumDeclaration() { let components = highlighter.highlight(""" indirect enum Content { @@ -793,6 +821,7 @@ extension DeclarationTests { ("testFunctionDeclarationWithNonEscapedKeywordAsName", testFunctionDeclarationWithNonEscapedKeywordAsName), ("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName), ("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors), + ("testNonMutatingFunction", testNonMutatingFunction), ("testIndirectEnumDeclaration", testIndirectEnumDeclaration) ] }