Skip to content

Commit

Permalink
Merge pull request swiftlang#2292 from ahoppen/ahoppen/case-iterable
Browse files Browse the repository at this point in the history
Remove `SyntaxKind` conformance to `CaseIterable`
  • Loading branch information
ahoppen committed Oct 17, 2023
2 parents e8659bb + aa33736 commit 106183a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 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
6 changes: 6 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
- 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
- `IntegerLiteralExprSyntax.Radix` removed conformance to `CaseIterable`
- Description: `IntegerLiteralExprSyntax.Radix` no longer conforms to `CaseIterable` since there is no good use case to iterate over all radix kinds.
- Pull request: https://github.com/apple/swift-syntax/pull/2292


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

extension IntegerLiteralExprSyntax {
public enum Radix: CaseIterable {
public enum Radix {
case binary
case octal
case decimal
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 106183a

Please sign in to comment.