Skip to content

Commit b1f77c9

Browse files
authored
Fix highlighting for interpolated closure shorthand arguments (#75)
This patch fixes syntax highlighting for when shorthand closure arguments ($0, $1…) are interpolated into a string literal. The fix is to no longer treat “$” as a delimiter, which should help solve similar issues that might be encountered in the future as well.
1 parent c582abf commit b1f77c9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Sources/Splash/Grammar/SwiftGrammar.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public struct SwiftGrammar: Grammar {
1818
delimiters.remove("\"")
1919
delimiters.remove("#")
2020
delimiters.remove("@")
21+
delimiters.remove("$")
2122
self.delimiters = delimiters
2223

2324
syntaxRules = [

Tests/SplashTests/Tests/LiteralTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ final class LiteralTests: SyntaxHighlighterTestCase {
7676
])
7777
}
7878

79+
func testStringLiteralWithInterpolatedClosureArgumentShorthand() {
80+
let components = highlighter.highlight(#""\($0)""#)
81+
82+
XCTAssertEqual(components, [
83+
.token("\"", .string),
84+
.plainText(#"\($0)"#),
85+
.token("\"", .string)
86+
])
87+
}
88+
7989
func testStringLiteralWithCustomIterpolation() {
8090
let components = highlighter.highlight("""
8191
"Hello \\(label: a, b) world \\(label: call())"
@@ -254,6 +264,7 @@ extension LiteralTests {
254264
("testStringLiteralWithEscapedQuote", testStringLiteralWithEscapedQuote),
255265
("testStringLiteralWithAttribute", testStringLiteralWithAttribute),
256266
("testStringLiteralInterpolation", testStringLiteralInterpolation),
267+
("testStringLiteralWithInterpolatedClosureArgumentShorthand", testStringLiteralWithInterpolatedClosureArgumentShorthand),
257268
("testStringLiteralWithCustomIterpolation", testStringLiteralWithCustomIterpolation),
258269
("testMultiLineStringLiteral", testMultiLineStringLiteral),
259270
("testSingleLineRawStringLiteral", testSingleLineRawStringLiteral),

0 commit comments

Comments
 (0)