Fix highlighting for comments starting with a delimiter (#82)

This patch fixes syntax highlighting for any comments that begin with
a delimiter, which would previously prevent the comment’s leading token
from being parsed correctly. The fix is to prevent slashes to be merged
with any other delimiter, except for other slashes and asterisks.
This commit is contained in:
John Sundell 2019-08-07 16:07:22 +02:00 committed by GitHub
parent e03dac1dd6
commit 91adf9359f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -47,6 +47,10 @@ public struct SwiftGrammar: Grammar {
return false
case (")", _):
return false
case ("/", "/"), ("/", "*"):
return true
case ("/", _):
return false
default:
return true
}

View File

@ -112,6 +112,11 @@ final class CommentTests: SyntaxHighlighterTestCase {
])
}
func testCommentStartingWithPunctuation() {
let components = highlighter.highlight("//.call()")
XCTAssertEqual(components, [.token("//.call()", .comment)])
}
func testCommentEndingWithComma() {
let components = highlighter.highlight("""
// Hello,
@ -143,6 +148,7 @@ extension CommentTests {
("testMultiLineComment", testMultiLineComment),
("testMultiLineCommentWithDoubleAsterisks", testMultiLineCommentWithDoubleAsterisks),
("testMutliLineDocumentationComment", testMutliLineDocumentationComment),
("testCommentStartingWithPunctuation", testCommentStartingWithPunctuation),
("testCommentEndingWithComma", testCommentEndingWithComma)
]
}