Skip to content

Commit 97cc869

Browse files
committed
Improve documentation comments of StringSegmentSyntax
1 parent eae92fe commit 97cc869

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,16 +2277,31 @@ public struct StringLiteralExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _Leaf
22772277

22782278
// MARK: - StringSegmentSyntax
22792279

2280-
/// A literal segment inside a string segment.
2281-
///
2282-
/// - SeeAlso: ``ExpressionSegmentSyntax``
2280+
/// A string literal segment that represents plain text content within a string literal expression.
2281+
///
2282+
/// Used to construct string literals programmatically, especially in macros that need to generate or manipulate string content. For example, in a string literal `"Hello \(name)"`, the `"Hello "` part would be represented by a `StringSegmentSyntax`.
2283+
///
2284+
/// Creating a string segment requires special attention to use `.stringSegment()` for the content token to ensure proper formatting. For example, when creating a simple string segment:
2285+
/// ```swift
2286+
/// let segment = StringSegmentSyntax(content: .stringSegment("Hello World"))
2287+
/// ```
2288+
///
2289+
/// This type is commonly used in macros for:
2290+
/// - Creating and validating string literals at compile time (e.g., URL validation)
2291+
/// - Building string-based error messages and diagnostics
2292+
/// - Generating code that contains string literals
2293+
/// - Constructing string interpolations
2294+
///
2295+
/// Important: When creating a string segment from a string literal, always use `.stringSegment(string)` rather than just passing the string directly. Using the raw string will create an identifier token instead of a string segment token, which can lead to formatting issues.
2296+
///
2297+
/// - SeeAlso: ``ExpressionSegmentSyntax`` for segments containing string interpolations
22832298
///
22842299
/// ### Children
2285-
///
2300+
///
22862301
/// - `content`: `<stringSegment>`
22872302
///
22882303
/// ### Contained in
2289-
///
2304+
///
22902305
/// - ``SimpleStringLiteralSegmentListSyntax``
22912306
/// - ``StringLiteralSegmentListSyntax``
22922307
public struct StringSegmentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol {
@@ -2299,9 +2314,23 @@ public struct StringSegmentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
22992314
self._syntaxNode = node._syntaxNode
23002315
}
23012316

2317+
/// Creates a new string segment with the given content and optional trivia.
2318+
///
2319+
/// Example:
2320+
/// ```swift
2321+
/// let stringLiteral = StringLiteralExprSyntax(
2322+
/// openingQuote: .stringQuoteToken(),
2323+
/// segments: StringLiteralSegmentListSyntax([.stringSegment(.stringSegment("Some Text"))]),
2324+
/// closingQuote: .stringQuoteToken()
2325+
/// )
2326+
/// ```
2327+
///
23022328
/// - Parameters:
2303-
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
2304-
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
2329+
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node's first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
2330+
/// - unexpectedBeforeContent: Used internally by swift-syntax to handle malformed source code. When creating string segments programmatically, you should pass nil.
2331+
/// - content: The string content token, created using `.stringSegment("your string")`
2332+
/// - unexpectedAfterContent: Used internally by swift-syntax to handle malformed source code. When creating string segments programmatically, you should pass nil.
2333+
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node's last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
23052334
public init(
23062335
leadingTrivia: Trivia? = nil,
23072336
_ unexpectedBeforeContent: UnexpectedNodesSyntax? = nil,

0 commit comments

Comments
 (0)