File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ public struct SwiftGrammar: Grammar {
29
29
NumberRule ( ) ,
30
30
TypeRule ( ) ,
31
31
CallRule ( ) ,
32
+ KeyPathRule ( ) ,
32
33
PropertyRule ( ) ,
33
34
DotAccessRule ( ) ,
34
35
KeywordRule ( )
@@ -371,6 +372,14 @@ private extension SwiftGrammar {
371
372
}
372
373
}
373
374
375
+ struct KeyPathRule : SyntaxRule {
376
+ var tokenType : TokenType { return . property }
377
+
378
+ func matches( _ segment: Segment ) -> Bool {
379
+ return segment. tokens. previous == " \\ . "
380
+ }
381
+ }
382
+
374
383
struct PropertyRule : SyntaxRule {
375
384
var tokenType : TokenType { return . property }
376
385
Original file line number Diff line number Diff line change @@ -205,6 +205,24 @@ final class LiteralTests: SyntaxHighlighterTestCase {
205
205
] )
206
206
}
207
207
208
+ func testKeyPathLiteral( ) {
209
+ let components = highlighter. highlight ( " let value = object[keyPath: \\ .property] " )
210
+
211
+ XCTAssertEqual ( components, [
212
+ . token( " let " , . keyword) ,
213
+ . whitespace( " " ) ,
214
+ . plainText( " value " ) ,
215
+ . whitespace( " " ) ,
216
+ . plainText( " = " ) ,
217
+ . whitespace( " " ) ,
218
+ . plainText( " object[keyPath: " ) ,
219
+ . whitespace( " " ) ,
220
+ . plainText( " \\ . " ) ,
221
+ . token( " property " , . property) ,
222
+ . plainText( " ] " )
223
+ ] )
224
+ }
225
+
208
226
func testAllTestsRunOnLinux( ) {
209
227
XCTAssertTrue ( TestCaseVerifier . verifyLinuxTests ( ( type ( of: self ) ) . allTests) )
210
228
}
@@ -223,7 +241,8 @@ extension LiteralTests {
223
241
( " testSingleLineRawStringLiteral " , testSingleLineRawStringLiteral) ,
224
242
( " testMultiLineRawStringLiteral " , testMultiLineRawStringLiteral) ,
225
243
( " testDoubleLiteral " , testDoubleLiteral) ,
226
- ( " testIntegerLiteralWithSeparators " , testIntegerLiteralWithSeparators)
244
+ ( " testIntegerLiteralWithSeparators " , testIntegerLiteralWithSeparators) ,
245
+ ( " testKeyPathLiteral " , testKeyPathLiteral)
227
246
]
228
247
}
229
248
}
You can’t perform that action at this time.
0 commit comments