Support ‘is’ keyword
This change makes Splash support the `is` keyword, for example in type pattern matching in `switch` statements.
This commit is contained in:
parent
45ca85e299
commit
d72e816cd8
@ -48,7 +48,7 @@ private extension SwiftGrammar {
|
|||||||
"#selector", "required", "willSet", "didSet",
|
"#selector", "required", "willSet", "didSet",
|
||||||
"lazy", "subscript", "defer", "inout", "while",
|
"lazy", "subscript", "defer", "inout", "while",
|
||||||
"continue", "fallthrough", "repeat", "indirect",
|
"continue", "fallthrough", "repeat", "indirect",
|
||||||
"deinit"
|
"deinit", "is"
|
||||||
] as Set<String>).union(accessControlKeywords)
|
] as Set<String>).union(accessControlKeywords)
|
||||||
|
|
||||||
static let accessControlKeywords: Set<String> = [
|
static let accessControlKeywords: Set<String> = [
|
||||||
|
@ -169,6 +169,39 @@ final class StatementTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testSwitchStatementWithTypePatternMatching() {
|
||||||
|
let components = highlighter.highlight("""
|
||||||
|
switch variable {
|
||||||
|
case is MyType: break
|
||||||
|
default: break
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("switch", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("variable"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{"),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.token("case", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("is", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("MyType", .type),
|
||||||
|
.plainText(":"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("break", .keyword),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.token("default", .keyword),
|
||||||
|
.plainText(":"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("break", .keyword),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.plainText("}")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func testForStatementWithStaticProperty() {
|
func testForStatementWithStaticProperty() {
|
||||||
let components = highlighter.highlight("for value in Enum.allCases { }")
|
let components = highlighter.highlight("for value in Enum.allCases { }")
|
||||||
|
|
||||||
@ -272,6 +305,7 @@ extension StatementTests {
|
|||||||
("testSwitchStatement", testSwitchStatement),
|
("testSwitchStatement", testSwitchStatement),
|
||||||
("testSwitchStatementWithAssociatedValues", testSwitchStatementWithAssociatedValues),
|
("testSwitchStatementWithAssociatedValues", testSwitchStatementWithAssociatedValues),
|
||||||
("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough),
|
("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough),
|
||||||
|
("testSwitchStatementWithTypePatternMatching", testSwitchStatementWithTypePatternMatching),
|
||||||
("testForStatementWithStaticProperty", testForStatementWithStaticProperty),
|
("testForStatementWithStaticProperty", testForStatementWithStaticProperty),
|
||||||
("testForStatementWithContinue", testForStatementWithContinue),
|
("testForStatementWithContinue", testForStatementWithContinue),
|
||||||
("testRepeatWhileStatement", testRepeatWhileStatement)
|
("testRepeatWhileStatement", testRepeatWhileStatement)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user