Skip to content

Commit f2aff2e

Browse files
committed
Improve documentation comments of LabeledExprSyntax
1 parent ed6a983 commit f2aff2e

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -788,35 +788,89 @@ public struct KeyPathSubscriptComponentSyntax: SyntaxProtocol, SyntaxHashable, _
788788

789789
// MARK: - LabeledExprSyntax
790790

791-
/// An expression that is prefixed by a label.
792-
///
793-
/// For example, labeled expressions occur in
794-
/// - Function calls, where the label is the parameter label.
795-
/// - Tuples, where the label is the name of the tuple element.
791+
/// An expression with an optional label and colon, used in function calls, tuple elements, and macro arguments.
792+
///
793+
/// This type represents labeled expressions in Swift syntax, commonly used for:
794+
/// - Function call arguments with parameter labels
795+
/// - Tuple elements with names
796+
/// - Macro arguments with labels
797+
///
798+
/// Example creating a labeled expression for a function call:
799+
/// ```swift
800+
/// let labeledArg = LabeledExprSyntax(
801+
/// label: .identifier("localized"),
802+
/// colon: .colonToken(),
803+
/// expression: stringLiteral
804+
/// )
805+
/// ```
806+
///
807+
/// Example creating multiple labeled expressions in a list:
808+
/// ```swift
809+
/// let arguments = LabeledExprListSyntax {
810+
/// LabeledExprSyntax(
811+
/// label: .identifier("name"),
812+
/// colon: .colonToken(),
813+
/// expression: nameExpr
814+
/// )
815+
/// LabeledExprSyntax(
816+
/// label: .identifier("value"),
817+
/// colon: .colonToken(),
818+
/// expression: valueExpr,
819+
/// trailingComma: .commaToken()
820+
/// )
821+
/// }
822+
/// ```
796823
///
797824
/// ### Children
798-
///
825+
///
799826
/// - `label`: (`<identifier>` | `_`)?
800827
/// - `colon`: `:`?
801828
/// - `expression`: ``ExprSyntax``
802829
/// - `trailingComma`: `,`?
803830
///
804831
/// ### Contained in
805-
///
832+
///
806833
/// - ``LabeledExprListSyntax``
807834
public struct LabeledExprSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol {
808835
public let _syntaxNode: Syntax
809836

837+
/// Internal initializer used by swift-syntax to create labeled expressions from existing syntax nodes.
838+
///
839+
/// This initializer is not intended for direct use when creating labeled expressions programmatically.
840+
/// Instead, use the main initializer that accepts individual components.
841+
///
842+
/// - Parameters:
843+
/// - node: An existing syntax node to convert. Must be of kind `.labeledExpr`.
810844
public init?(_ node: __shared some SyntaxProtocol) {
811845
guard node.raw.kind == .labeledExpr else {
812846
return nil
813847
}
814848
self._syntaxNode = node._syntaxNode
815849
}
816850

851+
/// Creates a new labeled expression with the given components.
852+
///
853+
/// Example creating a labeled string literal argument:
854+
/// ```swift
855+
/// let argument = LabeledExprSyntax(
856+
/// label: .identifier("defaultValue"),
857+
/// colon: .colonToken(),
858+
/// expression: stringLiteral
859+
/// )
860+
/// ```
861+
///
817862
/// - Parameters:
818-
/// - 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.
819-
/// - 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.
863+
/// - 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.
864+
/// - unexpectedBeforeLabel: Used internally by swift-syntax to handle malformed source code. When creating expressions programmatically, you should pass nil.
865+
/// - label: The optional label for this expression, created using `.identifier()` for named labels or `._` for unnamed ones.
866+
/// - unexpectedBetweenLabelAndColon: Used internally by swift-syntax to handle malformed source code. When creating expressions programmatically, you should pass nil.
867+
/// - colon: The colon token that follows the label, created using `.colonToken()`.
868+
/// - unexpectedBetweenColonAndExpression: Used internally by swift-syntax to handle malformed source code. When creating expressions programmatically, you should pass nil.
869+
/// - expression: The expression being labeled.
870+
/// - unexpectedBetweenExpressionAndTrailingComma: Used internally by swift-syntax to handle malformed source code. When creating expressions programmatically, you should pass nil.
871+
/// - trailingComma: An optional trailing comma, useful when this expression is part of a list.
872+
/// - unexpectedAfterTrailingComma: Used internally by swift-syntax to handle malformed source code. When creating expressions programmatically, you should pass nil.
873+
/// - 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.
820874
public init(
821875
leadingTrivia: Trivia? = nil,
822876
_ unexpectedBeforeLabel: UnexpectedNodesSyntax? = nil,

0 commit comments

Comments
 (0)