Skip to content

Commit 1264fba

Browse files
committed
Move SyntaxKind from gyb to codegen
1 parent f492984 commit 1264fba

File tree

6 files changed

+677
-341
lines changed

6 files changed

+677
-341
lines changed

CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
2828
templates: [
2929
(miscFile, "Misc.swift"),
3030
(syntaxEnumFile, "SyntaxEnum.swift"),
31+
(syntaxKindFile, "SyntaxKind.swift")
3132
],
3233
destination: URL(fileURLWithPath: generatedPath),
3334
verbose: verbose
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SwiftSyntax
14+
import SwiftSyntaxBuilder
15+
import SyntaxSupport
16+
import Utils
17+
18+
let syntaxKindFile = SourceFile(leadingTrivia: .docLineComment(generateCopyrightHeader(for: "generate-swiftsyntax"))) {
19+
EnumDecl("""
20+
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
21+
@frozen // FIXME: Not actually stable, works around a miscompile
22+
public enum SyntaxKind
23+
""") {
24+
EnumCaseDecl("case token")
25+
for node in NON_BASE_SYNTAX_NODES {
26+
EnumCaseDecl("case \(raw: node.swiftSyntaxKind)")
27+
}
28+
29+
VariableDecl(
30+
modifiers: [DeclModifier(name: .public)],
31+
name: IdentifierPattern("isSyntaxCollection"),
32+
type: TypeAnnotation(
33+
colon: .colon,
34+
type: SimpleTypeIdentifier("Bool")
35+
)
36+
) {
37+
SwitchStmt(expression: Expr("self")) {
38+
for node in SYNTAX_NODES where node.baseKind == "SyntaxCollection"{
39+
SwitchCase("case .\(raw: node.swiftSyntaxKind):") {
40+
ReturnStmt("return true")
41+
}
42+
}
43+
44+
SwitchCase("default:") {
45+
ReturnStmt("return false")
46+
}
47+
}
48+
}
49+
50+
VariableDecl(
51+
modifiers: [DeclModifier(name: .public)],
52+
name: IdentifierPattern("isMissing"),
53+
type: TypeAnnotation(
54+
colon: .colon,
55+
type: SimpleTypeIdentifier("Bool")
56+
)
57+
) {
58+
SwitchStmt(expression: Expr("self")) {
59+
for name in SYNTAX_BASE_KINDS where !["Syntax", "SyntaxCollection"].contains(name) {
60+
SwitchCase("case .missing\(raw: name):") {
61+
ReturnStmt("return true")
62+
}
63+
}
64+
65+
SwitchCase("default:") {
66+
ReturnStmt("return false")
67+
}
68+
}
69+
}
70+
}
71+
}

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ let package = Package(
6969
"SyntaxBaseNodes.swift.gyb",
7070
"SyntaxCollections.swift.gyb",
7171
"SyntaxFactory.swift.gyb",
72-
"SyntaxKind.swift.gyb",
7372
"SyntaxNodes.swift.gyb.template",
7473
"SyntaxRewriter.swift.gyb",
7574
"SyntaxTransform.swift.gyb",

Sources/SwiftSyntax/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ add_swift_host_library(SwiftSyntax
3737
gyb_generated/SyntaxCollections.swift
3838
generated/SyntaxEnum.swift
3939
gyb_generated/SyntaxFactory.swift
40-
gyb_generated/SyntaxKind.swift
40+
generated/SyntaxKind.swift
4141
gyb_generated/SyntaxRewriter.swift
4242
gyb_generated/SyntaxTraits.swift
4343
gyb_generated/SyntaxTransform.swift

Sources/SwiftSyntax/SyntaxKind.swift.gyb

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)