Skip to content

Commit 3cff8d7

Browse files
committed
Add editor place holder pattern
1 parent 59f04f4 commit 3cff8d7

File tree

20 files changed

+287
-7
lines changed

20 files changed

+287
-7
lines changed

CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,22 @@ public let PATTERN_NODES: [Node] = [
182182
]
183183
),
184184

185+
Node(
186+
kind: .editorPlaceholderPattern,
187+
base: .pattern,
188+
nameForDiagnostics: "editor placeholder",
189+
documentation: """
190+
An editor placeholder, e.g. `<#pattern#>` that is used in a position that expects a pattern.
191+
""",
192+
children: [
193+
Child(
194+
name: "placeholder",
195+
kind: .token(choices: [.token(.identifier)]),
196+
documentation: """
197+
The actual editor placeholder that starts with `<#` and ends with `#>`.
198+
"""
199+
)
200+
]
201+
),
202+
185203
]

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
111111
case dynamicReplacementAttributeArguments
112112
case editorPlaceholderDecl
113113
case editorPlaceholderExpr
114+
case editorPlaceholderPattern
114115
case effectsAttributeArgumentList
115116
case enumCaseDecl
116117
case enumCaseElement

Release Notes/510.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
- Description: Remarks are used by the Swift compiler and other tools to describe some aspect of translation that doesn't reflect correctness, but may be useful for the user. Remarks have been added to the diagnostic severity enums to align with the Swift compiler.
2222
- Pull Request: https://github.com/apple/swift-syntax/pull/2143
2323

24+
- New pattern node `EditorPlaceholderPatternSyntax`
25+
- Description: This node type will be placeholder that is used in a position that expects a pattern.
26+
- Issue: https://github.com/apple/swift-syntax/issues/2147
27+
- Pull Request: https://github.com/apple/swift-syntax/pull/2150
28+
2429
## API Behavior Changes
2530

2631
## Deprecations

Sources/SwiftParser/Patterns.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,21 @@ extension Parser {
7070
)
7171
case (.lhs(.identifier), let handle)?:
7272
let identifier = self.eat(handle)
73-
return RawPatternSyntax(
74-
RawIdentifierPatternSyntax(
75-
identifier: identifier,
76-
arena: self.arena
73+
if identifier.tokenText.isEditorPlaceholder {
74+
return RawPatternSyntax(
75+
RawEditorPlaceholderPatternSyntax(
76+
placeholder: identifier,
77+
arena: self.arena
78+
)
7779
)
78-
)
80+
} else {
81+
return RawPatternSyntax(
82+
RawIdentifierPatternSyntax(
83+
identifier: identifier,
84+
arena: self.arena
85+
)
86+
)
87+
}
7988
case (.lhs(.dollarIdentifier), let handle)?:
8089
let dollarIdent = self.eat(handle)
8190
let unexpectedBeforeIdentifier = RawUnexpectedNodesSyntax(elements: [RawSyntax(dollarIdent)], arena: self.arena)

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ extension SyntaxKind {
143143
return "editor placeholder"
144144
case .editorPlaceholderExpr:
145145
return "editor placeholder"
146+
case .editorPlaceholderPattern:
147+
return "editor placeholder"
146148
case .effectsAttributeArgumentList:
147149
return "@_effects arguments"
148150
case .enumCaseDecl:

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
151151
- <doc:SwiftSyntax/PatternSyntax>
152152
- <doc:SwiftSyntax/PatternSyntaxProtocol>
153153
- <doc:SwiftSyntax/MissingPatternSyntax>
154+
- <doc:SwiftSyntax/EditorPlaceholderPatternSyntax>
154155
- <doc:SwiftSyntax/ExpressionPatternSyntax>
155156
- <doc:SwiftSyntax/IdentifierPatternSyntax>
156157
- <doc:SwiftSyntax/IsTypePatternSyntax>

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
10771077
return "placeholder"
10781078
case \EditorPlaceholderExprSyntax.unexpectedAfterPlaceholder:
10791079
return "unexpectedAfterPlaceholder"
1080+
case \EditorPlaceholderPatternSyntax.unexpectedBeforePlaceholder:
1081+
return "unexpectedBeforePlaceholder"
1082+
case \EditorPlaceholderPatternSyntax.placeholder:
1083+
return "placeholder"
1084+
case \EditorPlaceholderPatternSyntax.unexpectedAfterPlaceholder:
1085+
return "unexpectedAfterPlaceholder"
10801086
case \EnumCaseDeclSyntax.unexpectedBeforeAttributes:
10811087
return "unexpectedBeforeAttributes"
10821088
case \EnumCaseDeclSyntax.attributes:

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
776776
visitAnyPost(node._syntaxNode)
777777
}
778778

779+
override open func visit(_ node: EditorPlaceholderPatternSyntax) -> SyntaxVisitorContinueKind {
780+
return visitAny(node._syntaxNode)
781+
}
782+
783+
override open func visitPost(_ node: EditorPlaceholderPatternSyntax) {
784+
visitAnyPost(node._syntaxNode)
785+
}
786+
779787
override open func visit(_ node: EffectsAttributeArgumentListSyntax) -> SyntaxVisitorContinueKind {
780788
return visitAny(node._syntaxNode)
781789
}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public struct PatternSyntax: PatternSyntaxProtocol, SyntaxHashable {
770770

771771
public init?(_ node: some SyntaxProtocol) {
772772
switch node.raw.kind {
773-
case .expressionPattern, .identifierPattern, .isTypePattern, .missingPattern, .tuplePattern, .valueBindingPattern, .wildcardPattern:
773+
case .editorPlaceholderPattern, .expressionPattern, .identifierPattern, .isTypePattern, .missingPattern, .tuplePattern, .valueBindingPattern, .wildcardPattern:
774774
self._syntaxNode = node._syntaxNode
775775
default:
776776
return nil
@@ -795,6 +795,7 @@ public struct PatternSyntax: PatternSyntaxProtocol, SyntaxHashable {
795795

796796
public static var structure: SyntaxNodeStructure {
797797
return .choices([
798+
.node(EditorPlaceholderPatternSyntax.self),
798799
.node(ExpressionPatternSyntax.self),
799800
.node(IdentifierPatternSyntax.self),
800801
.node(IsTypePatternSyntax.self),
@@ -1486,6 +1487,7 @@ extension Syntax {
14861487
.node(DynamicReplacementAttributeArgumentsSyntax.self),
14871488
.node(EditorPlaceholderDeclSyntax.self),
14881489
.node(EditorPlaceholderExprSyntax.self),
1490+
.node(EditorPlaceholderPatternSyntax.self),
14891491
.node(EffectsAttributeArgumentListSyntax.self),
14901492
.node(EnumCaseDeclSyntax.self),
14911493
.node(EnumCaseElementListSyntax.self),

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public enum SyntaxEnum {
105105
case dynamicReplacementAttributeArguments(DynamicReplacementAttributeArgumentsSyntax)
106106
case editorPlaceholderDecl(EditorPlaceholderDeclSyntax)
107107
case editorPlaceholderExpr(EditorPlaceholderExprSyntax)
108+
case editorPlaceholderPattern(EditorPlaceholderPatternSyntax)
108109
case effectsAttributeArgumentList(EffectsAttributeArgumentListSyntax)
109110
case enumCaseDecl(EnumCaseDeclSyntax)
110111
case enumCaseElementList(EnumCaseElementListSyntax)
@@ -479,6 +480,8 @@ public extension Syntax {
479480
return .editorPlaceholderDecl(EditorPlaceholderDeclSyntax(self)!)
480481
case .editorPlaceholderExpr:
481482
return .editorPlaceholderExpr(EditorPlaceholderExprSyntax(self)!)
483+
case .editorPlaceholderPattern:
484+
return .editorPlaceholderPattern(EditorPlaceholderPatternSyntax(self)!)
482485
case .effectsAttributeArgumentList:
483486
return .effectsAttributeArgumentList(EffectsAttributeArgumentListSyntax(self)!)
484487
case .enumCaseDecl:

0 commit comments

Comments
 (0)