Skip to content

Commit ec37e10

Browse files
authored
Fix highlighting for comments that appear next to curly brackets (JohnSundell#105)
This change makes Splash correctly highlight comments that are placed right next to either an opening or closing curly bracket.
1 parent b6c489c commit ec37e10

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/Splash/Grammar/SwiftGrammar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public struct SwiftGrammar: Grammar {
5555
return false
5656
case (".", "/"):
5757
return false
58+
case ("{", "/"), ("}", "/"):
59+
return false
5860
default:
5961
return true
6062
}

Tests/SplashTests/Tests/CommentTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ final class CommentTests: SyntaxHighlighterTestCase {
173173
])
174174
}
175175

176+
func testCommentsNextToCurlyBrackets() {
177+
let components = highlighter.highlight("""
178+
call {//commentA
179+
}//commentB
180+
""")
181+
182+
XCTAssertEqual(components, [
183+
.token("call", .call),
184+
.whitespace(" "),
185+
.plainText("{"),
186+
.token("//commentA", .comment),
187+
.whitespace("\n"),
188+
.plainText("}"),
189+
.token("//commentB", .comment)
190+
])
191+
}
192+
176193
func testAllTestsRunOnLinux() {
177194
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
178195
}
@@ -188,7 +205,8 @@ extension CommentTests {
188205
("testCommentStartingWithPunctuation", testCommentStartingWithPunctuation),
189206
("testCommentEndingWithComma", testCommentEndingWithComma),
190207
("testCommentWithNumber", testCommentWithNumber),
191-
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation)
208+
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation),
209+
("testCommentsNextToCurlyBrackets", testCommentsNextToCurlyBrackets)
192210
]
193211
}
194212
}

0 commit comments

Comments
 (0)