Skip to content

Commit

Permalink
Remove SyntaxKind conformance to CaseIterable
Browse files Browse the repository at this point in the history
There’s no good reason to iterate over all cases in `SyntaxKind` and if `SyntaxKind` conforms to `CaseIterable`, we can’t mark members of it as deprecated (https://github.com/apple/swift-syntax/pull/2237/files#r1359917461)
  • Loading branch information
ahoppen committed Oct 17, 2023
1 parent ccab07f commit a318593
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let syntaxKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! EnumDeclSyntax(
"""
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
public enum SyntaxKind: CaseIterable
public enum SyntaxKind
"""
) {
DeclSyntax("case token")
Expand Down
3 changes: 3 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- Effect specifiers:
- Description: The `unexpectedAfterThrowsSpecifier` node of the various effect specifiers has been removed.
- Pull request: https://github.com/apple/swift-syntax/pull/2219
- `SyntaxKind` removed conformance to `CaseIterable`
- Description: `SyntaxKind` no longer conforms to `CaseIterable` since there is no good use case to iterate over all syntax kinds.
- Pull request: https://github.com/apple/swift-syntax/pull/2292


## Template
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/generated/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

/// Enumerates the known kinds of Syntax represented in the Syntax tree.
public enum SyntaxKind: CaseIterable {
public enum SyntaxKind {
case token
case accessorBlock
case accessorDeclList
Expand Down
11 changes: 9 additions & 2 deletions SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ struct BasicFormat: ParsableCommand, ParseCommand {
var nodeType: String = "SourceFileSyntax"

func run() throws {
let parsableMetatypes = SyntaxKind.allCases.compactMap {
$0.syntaxNodeType as? SyntaxParseable.Type
guard case .choices(let choices) = Syntax.structure else {
fatalError("Expected `Syntax.structure` to be the `choices` case")
}

let parsableMetatypes = choices.compactMap { (choice) -> SyntaxParseable.Type? in
guard case .node(let nodeType) = choice else {
return nil
}
return nodeType as? SyntaxParseable.Type
}
let parsableMetatypesByName = Dictionary(
parsableMetatypes.map {
Expand Down

0 comments on commit a318593

Please sign in to comment.