Skip to content

Commit 895f67b

Browse files
committed
Add string interpolation for FunctionParameterClauseSyntax
1 parent 491c5c9 commit 895f67b

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/LayoutNodesParsableFile.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ let layoutNodesParsableFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6464
}
6565
}
6666

67+
// Custom implementations for nodes with special handling.
68+
DeclSyntax(
69+
"""
70+
extension FunctionParameterClauseSyntax: SyntaxParseable {
71+
public static func parse(from parser: inout Parser) -> Self {
72+
parse(from: &parser) {
73+
$0.parseParameterClause(RawFunctionParameterClauseSyntax.self) { parser in
74+
parser.parseFunctionParameter()
75+
}
76+
}
77+
}
78+
}
79+
"""
80+
)
81+
6782
try! ExtensionDeclSyntax("fileprivate extension Parser") {
6883
DeclSyntax(
6984
"""

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,15 @@ let syntaxExpressibleByStringInterpolationConformancesFile = SourceFileSyntax(le
4040
"""
4141
)
4242
}
43+
44+
// Due to we cannot parse the `FunctionParameterClauseSyntax` from string interpolation in the normal way
45+
// we need to hand-write the conformance.
46+
DeclSyntax("extension FunctionParameterClauseSyntax: SyntaxExpressibleByStringInterpolation {}")
47+
DeclSyntax(
48+
"""
49+
#if compiler(>=6)
50+
extension FunctionParameterClauseSyntax: Swift.ExpressibleByStringInterpolation {}
51+
#endif
52+
"""
53+
)
4354
}

Sources/SwiftParser/generated/LayoutNodes+Parsable.swift

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SwiftSyntax
14+
import SwiftSyntaxBuilder
15+
import XCTest
16+
17+
final class FunctionParameterClauseSyntaxTests: XCTestCase {
18+
func testFunctionParameterClauseSyntax() {
19+
let builder = FunctionParameterClauseSyntax("(x: Int)")
20+
assertBuildResult(
21+
builder,
22+
"""
23+
(x: Int)
24+
"""
25+
)
26+
}
27+
}

0 commit comments

Comments
 (0)