Fix comments with punctuation just prior or after (#93)
This change makes Splash correctly handle connected multiline comment delimiters; `/*` and `*/`, when those are either connected, or directly placed next to punctuation.
This commit is contained in:
parent
97541c8835
commit
b7e9141e1b
|
@ -47,10 +47,14 @@ public struct SwiftGrammar: Grammar {
|
|||
return false
|
||||
case (")", _):
|
||||
return false
|
||||
case ("/", "/"), ("/", "*"):
|
||||
case ("/", "/"), ("/", "*"), ("*", "/"):
|
||||
return true
|
||||
case ("/", _):
|
||||
return false
|
||||
case ("(", _) where delimiterB != ".":
|
||||
return false
|
||||
case (".", "/"):
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
|
@ -106,6 +110,12 @@ private extension SwiftGrammar {
|
|||
var tokenType: TokenType { return .comment }
|
||||
|
||||
func matches(_ segment: Segment) -> Bool {
|
||||
if segment.tokens.current.hasPrefix("/*") {
|
||||
if segment.tokens.current.hasSuffix("*/") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if segment.tokens.current.hasPrefix("//") {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -136,6 +136,33 @@ final class CommentTests: SyntaxHighlighterTestCase {
|
|||
])
|
||||
}
|
||||
|
||||
func testCommentWithNoWhiteSpaceToPunctuation() {
|
||||
let components = highlighter.highlight("""
|
||||
(/* Hello */)
|
||||
.// World
|
||||
(/**/)
|
||||
""")
|
||||
|
||||
XCTAssertEqual(components, [
|
||||
.plainText("("),
|
||||
.token("/*", .comment),
|
||||
.whitespace(" "),
|
||||
.token("Hello", .comment),
|
||||
.whitespace(" "),
|
||||
.token("*/", .comment),
|
||||
.plainText(")"),
|
||||
.whitespace("\n"),
|
||||
.plainText("."),
|
||||
.token("//", .comment),
|
||||
.whitespace(" "),
|
||||
.token("World", .comment),
|
||||
.whitespace("\n"),
|
||||
.plainText("("),
|
||||
.token("/**/", .comment),
|
||||
.plainText(")"),
|
||||
])
|
||||
}
|
||||
|
||||
func testAllTestsRunOnLinux() {
|
||||
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
|
||||
}
|
||||
|
@ -149,7 +176,8 @@ extension CommentTests {
|
|||
("testMultiLineCommentWithDoubleAsterisks", testMultiLineCommentWithDoubleAsterisks),
|
||||
("testMutliLineDocumentationComment", testMutliLineDocumentationComment),
|
||||
("testCommentStartingWithPunctuation", testCommentStartingWithPunctuation),
|
||||
("testCommentEndingWithComma", testCommentEndingWithComma)
|
||||
("testCommentEndingWithComma", testCommentEndingWithComma),
|
||||
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue