Merge pull request #36 from JohnSundell/keywords-as-function-names
Don’t treat keywords used as function names as keywords
This commit is contained in:
commit
b6232fc67f
@ -221,6 +221,10 @@ private extension SwiftGrammar {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
guard !segment.tokens.previous.isAny(of: "func", "`") else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return keywords.contains(segment.tokens.current)
|
||||
|
@ -520,6 +520,50 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
|
||||
])
|
||||
}
|
||||
|
||||
func testFunctionDeclarationWithNonEscapedKeywordAsName() {
|
||||
let components = highlighter.highlight("func get() -> Int { return 7 }")
|
||||
|
||||
XCTAssertEqual(components, [
|
||||
.token("func", .keyword),
|
||||
.whitespace(" "),
|
||||
.plainText("get()"),
|
||||
.whitespace(" "),
|
||||
.plainText("->"),
|
||||
.whitespace(" "),
|
||||
.token("Int", .type),
|
||||
.whitespace(" "),
|
||||
.plainText("{"),
|
||||
.whitespace(" "),
|
||||
.token("return", .keyword),
|
||||
.whitespace(" "),
|
||||
.token("7", .number),
|
||||
.whitespace(" "),
|
||||
.plainText("}")
|
||||
])
|
||||
}
|
||||
|
||||
func testFunctionDeclarationWithEscapedKeywordAsName() {
|
||||
let components = highlighter.highlight("func `public`() -> Int { return 7 }")
|
||||
|
||||
XCTAssertEqual(components, [
|
||||
.token("func", .keyword),
|
||||
.whitespace(" "),
|
||||
.plainText("`public`()"),
|
||||
.whitespace(" "),
|
||||
.plainText("->"),
|
||||
.whitespace(" "),
|
||||
.token("Int", .type),
|
||||
.whitespace(" "),
|
||||
.plainText("{"),
|
||||
.whitespace(" "),
|
||||
.token("return", .keyword),
|
||||
.whitespace(" "),
|
||||
.token("7", .number),
|
||||
.whitespace(" "),
|
||||
.plainText("}")
|
||||
])
|
||||
}
|
||||
|
||||
func testIndirectEnumDeclaration() {
|
||||
let components = highlighter.highlight("""
|
||||
indirect enum Content {
|
||||
@ -583,6 +627,8 @@ extension DeclarationTests {
|
||||
("testSubscriptDeclaration", testSubscriptDeclaration),
|
||||
("testDeferDeclaration", testDeferDeclaration),
|
||||
("testFunctionDeclarationWithInOutParameter", testFunctionDeclarationWithInOutParameter),
|
||||
("testFunctionDeclarationWithNonEscapedKeywordAsName", testFunctionDeclarationWithNonEscapedKeywordAsName),
|
||||
("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName),
|
||||
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user