Skip to content

Allow trivia to be added to SyntaxStringInterpolation without adding a raw: label #2020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

try! StructDeclSyntax(
"""
\(raw: node.documentation)
\(node.documentation)
public struct \(node.kind.syntaxType): \(node.kind.protocolType), SyntaxHashable
"""
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

try! StructDeclSyntax(
"""
\(raw: documentation)
\(documentation)
public struct \(node.kind.syntaxType): SyntaxCollection, SyntaxHashable
"""
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
"""
// MARK: - \(raw: node.kind.syntaxType)

\(raw: documentation)
\(documentation)
public struct \(raw: node.kind.syntaxType): \(raw: node.baseType.syntaxBaseName)Protocol, SyntaxHashable
"""
) {
Expand Down Expand Up @@ -78,7 +78,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {

try! InitializerDeclSyntax(
"""
\(raw: node.generateInitializerDocComment())
\(node.generateInitializerDocComment())
\(node.generateInitializerDeclHeader())
"""
) {
Expand Down Expand Up @@ -163,7 +163,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {

try! VariableDeclSyntax(
"""
\(raw: child.documentation)
\(child.documentation)
public var \(child.varOrCaseName.backtickedIfNeeded): \(type)
"""
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
"""
// MARK: - \(trait.protocolName)

\(raw: trait.documentation)
\(trait.documentation)
public protocol \(trait.protocolName): SyntaxProtocol
"""
) {
for child in trait.children {
DeclSyntax(
"""
\(raw: child.documentation)
\(child.documentation)
var \(child.varOrCaseName): \(child.syntaxNodeKind.syntaxType)\(raw: child.isOptional ? "?" : "") { get set }
"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let buildableCollectionNodesFile = SourceFileSyntax(leadingTrivia: copyrightHead
// Generate collection node struct
try! ExtensionDeclSyntax(
"""
\(raw: docComment)
\(docComment)
extension \(raw: node.type.syntaxBaseName): ExpressibleByArrayLiteral
"""
) {
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ extension SyntaxStringInterpolation: StringInterpolationProtocol {
self.appendInterpolation(buildable.formatted(using: format))
}

public mutating func appendInterpolation(
_ trivia: Trivia
) {
self.appendInterpolation(raw: trivia.description)
}

/// Interpolates a literal or similar expression syntax equivalent to `value`.
///
/// - SeeAlso: ``SwiftSyntax/ExprSyntax/init(literal:)``
Expand Down