Skip to content

Commit

Permalink
Merge pull request #45 from JohnSundell/function-pre-processors
Browse files Browse the repository at this point in the history
Support function argument pre-processors
  • Loading branch information
JohnSundell authored Mar 9, 2019
2 parents 74c3b8a + 59161f2 commit e4718f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Splash/Grammar/SwiftGrammar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private extension SwiftGrammar {
"#selector", "required", "willSet", "didSet",
"lazy", "subscript", "defer", "inout", "while",
"continue", "fallthrough", "repeat", "indirect",
"deinit", "is"
"deinit", "is", "#file", "#line", "#function"
] as Set<String>).union(accessControlKeywords)

static let accessControlKeywords: Set<String> = [
Expand Down
36 changes: 36 additions & 0 deletions Tests/SplashTests/Tests/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,41 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}

func testFunctionDeclarationWithPreProcessors() {
let components = highlighter.highlight("""
func log(_ file: StaticString = #file, _ function: StaticString = #function) {}
""")

XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("log("),
.token("_", .keyword),
.whitespace(" "),
.plainText("file:"),
.whitespace(" "),
.token("StaticString", .type),
.whitespace(" "),
.plainText("="),
.whitespace(" "),
.token("#file", .keyword),
.plainText(","),
.whitespace(" "),
.token("_", .keyword),
.whitespace(" "),
.plainText("function:"),
.whitespace(" "),
.token("StaticString", .type),
.whitespace(" "),
.plainText("="),
.whitespace(" "),
.token("#function", .keyword),
.plainText(")"),
.whitespace(" "),
.plainText("{}")
])
}

func testIndirectEnumDeclaration() {
let components = highlighter.highlight("""
indirect enum Content {
Expand Down Expand Up @@ -725,6 +760,7 @@ extension DeclarationTests {
("testFunctionDeclarationWithInOutParameter", testFunctionDeclarationWithInOutParameter),
("testFunctionDeclarationWithNonEscapedKeywordAsName", testFunctionDeclarationWithNonEscapedKeywordAsName),
("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName),
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
]
}
Expand Down

0 comments on commit e4718f3

Please sign in to comment.