Correctly highlight the root level of a key path (#60)
When key path literals are used, Splash will now correctly highlight the root level of that key path as a property, rather than as plain text.
This commit is contained in:
parent
2cdc99ce60
commit
72837ce7f0
@ -29,6 +29,7 @@ public struct SwiftGrammar: Grammar {
|
||||
NumberRule(),
|
||||
TypeRule(),
|
||||
CallRule(),
|
||||
KeyPathRule(),
|
||||
PropertyRule(),
|
||||
DotAccessRule(),
|
||||
KeywordRule()
|
||||
@ -371,6 +372,14 @@ private extension SwiftGrammar {
|
||||
}
|
||||
}
|
||||
|
||||
struct KeyPathRule: SyntaxRule {
|
||||
var tokenType: TokenType { return .property }
|
||||
|
||||
func matches(_ segment: Segment) -> Bool {
|
||||
return segment.tokens.previous == "\\."
|
||||
}
|
||||
}
|
||||
|
||||
struct PropertyRule: SyntaxRule {
|
||||
var tokenType: TokenType { return .property }
|
||||
|
||||
|
@ -205,6 +205,24 @@ final class LiteralTests: SyntaxHighlighterTestCase {
|
||||
])
|
||||
}
|
||||
|
||||
func testKeyPathLiteral() {
|
||||
let components = highlighter.highlight("let value = object[keyPath: \\.property]")
|
||||
|
||||
XCTAssertEqual(components, [
|
||||
.token("let", .keyword),
|
||||
.whitespace(" "),
|
||||
.plainText("value"),
|
||||
.whitespace(" "),
|
||||
.plainText("="),
|
||||
.whitespace(" "),
|
||||
.plainText("object[keyPath:"),
|
||||
.whitespace(" "),
|
||||
.plainText("\\."),
|
||||
.token("property", .property),
|
||||
.plainText("]")
|
||||
])
|
||||
}
|
||||
|
||||
func testAllTestsRunOnLinux() {
|
||||
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
|
||||
}
|
||||
@ -223,7 +241,8 @@ extension LiteralTests {
|
||||
("testSingleLineRawStringLiteral", testSingleLineRawStringLiteral),
|
||||
("testMultiLineRawStringLiteral", testMultiLineRawStringLiteral),
|
||||
("testDoubleLiteral", testDoubleLiteral),
|
||||
("testIntegerLiteralWithSeparators", testIntegerLiteralWithSeparators)
|
||||
("testIntegerLiteralWithSeparators", testIntegerLiteralWithSeparators),
|
||||
("testKeyPathLiteral", testKeyPathLiteral)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user