Skip to content

Commit 31c84e1

Browse files
committed
Add string interpolation support for SourceFileSyntax
1 parent 42a1131 commit 31c84e1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Sources/SwiftParser/Syntax+StringInterpolation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ extension PatternSyntaxProtocol {
117117
}
118118

119119
// String interpolation support for the primary node kinds.
120+
extension SourceFileSyntax: SyntaxExpressibleByStringInterpolation {
121+
public static func parse(from parser: inout Parser) -> Self {
122+
return Syntax(raw: parser.parseSourceFile().raw).as(Self.self)!
123+
}
124+
}
125+
120126
extension DeclSyntax: SyntaxExpressibleByStringInterpolation { }
121127
extension ExprSyntax: SyntaxExpressibleByStringInterpolation { }
122128
extension StmtSyntax: SyntaxExpressibleByStringInterpolation { }

Tests/SwiftParserTest/StringInterpolation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ final class StringInterpolationTests: XCTestCase {
6565
XCTAssertTrue(structNode.is(StructDeclSyntax.self))
6666
}
6767

68+
func testSourceFile() throws {
69+
let _: SourceFileSyntax =
70+
"""
71+
print("Hello, world!")
72+
"""
73+
}
74+
75+
6876
func testRewriter() throws {
6977
let sourceFile = try Parser.parse(source: """
7078
class Foo {

0 commit comments

Comments
 (0)