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.
This commit is contained in:
John Sundell 2019-07-17 10:57:30 +02:00 committed by GitHub
parent c582abf0a4
commit b1f77c9ff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -18,6 +18,7 @@ public struct SwiftGrammar: Grammar {
delimiters.remove("\"")
delimiters.remove("#")
delimiters.remove("@")
delimiters.remove("$")
self.delimiters = delimiters
syntaxRules = [

View File

@ -76,6 +76,16 @@ final class LiteralTests: SyntaxHighlighterTestCase {
])
}
func testStringLiteralWithInterpolatedClosureArgumentShorthand() {
let components = highlighter.highlight(#""\($0)""#)
XCTAssertEqual(components, [
.token("\"", .string),
.plainText(#"\($0)"#),
.token("\"", .string)
])
}
func testStringLiteralWithCustomIterpolation() {
let components = highlighter.highlight("""
"Hello \\(label: a, b) world \\(label: call())"
@ -254,6 +264,7 @@ extension LiteralTests {
("testStringLiteralWithEscapedQuote", testStringLiteralWithEscapedQuote),
("testStringLiteralWithAttribute", testStringLiteralWithAttribute),
("testStringLiteralInterpolation", testStringLiteralInterpolation),
("testStringLiteralWithInterpolatedClosureArgumentShorthand", testStringLiteralWithInterpolatedClosureArgumentShorthand),
("testStringLiteralWithCustomIterpolation", testStringLiteralWithCustomIterpolation),
("testMultiLineStringLiteral", testMultiLineStringLiteral),
("testSingleLineRawStringLiteral", testSingleLineRawStringLiteral),