Add support for the “prefix” keyword (#91)

This patch makes Splash correctly highlight the `prefix` keyword, which
can only appear before `func`, so a special case was added for it (for now).
This commit is contained in:
John Sundell 2019-12-30 23:39:54 +00:00 committed by GitHub
parent 3de0275b52
commit 4da9bbd0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -287,6 +287,10 @@ private extension SwiftGrammar {
var tokenType: TokenType { return .keyword }
func matches(_ segment: Segment) -> Bool {
if segment.tokens.current == "prefix" && segment.tokens.next == "func" {
return true
}
if segment.tokens.next == ":" {
// Nil pattern matching inside of a switch statement case
if segment.tokens.current == "nil" {

View File

@ -955,6 +955,31 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testPrefixFunctionDeclaration() {
let components = highlighter.highlight("prefix func !(rhs: Bool) -> Bool { !rhs }")
XCTAssertEqual(components, [
.token("prefix", .keyword),
.whitespace(" "),
.token("func", .keyword),
.whitespace(" "),
.plainText("!(rhs:"),
.whitespace(" "),
.token("Bool", .type),
.plainText(")"),
.whitespace(" "),
.plainText("->"),
.whitespace(" "),
.token("Bool", .type),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("!rhs"),
.whitespace(" "),
.plainText("}")
])
}
func testIndirectEnumDeclaration() {
let components = highlighter.highlight("""
indirect enum Content {
@ -1064,6 +1089,7 @@ extension DeclarationTests {
("testNonMutatingFunction", testNonMutatingFunction),
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
("testFunctionDeclarationWithOpaqueReturnType", testFunctionDeclarationWithOpaqueReturnType),
("testPrefixFunctionDeclaration", testPrefixFunctionDeclaration),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration),
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations)
]