Skip to content

Commit 6096ddc

Browse files
committed
Move Files in Code-Generation that mirror gyb_syntax_support to a separate module
1 parent 04cbd9e commit 6096ddc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+240
-212
lines changed

Code-Generation/Package.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ let package = Package(
1919
name: "generate-swiftsyntaxbuilder",
2020
dependencies: [
2121
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
22-
.product(name: "ArgumentParser", package: "swift-argument-parser")
23-
],
22+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
23+
"SyntaxSupport"
24+
]
25+
),
26+
.target(
27+
name: "SyntaxSupport",
2428
exclude: [
2529
"gyb_helpers",
2630
"AttributeNodes.swift.gyb",

Code-Generation/Sources/generate-swiftsyntaxbuilder/AttributeNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/AttributeNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let ATTRIBUTE_NODES: [Node] = [
21+
public let ATTRIBUTE_NODES: [Node] = [
2222
% for node in ATTRIBUTE_NODES:
2323
${make_swift_node(node)},
2424

Code-Generation/Sources/generate-swiftsyntaxbuilder/AvailabilityNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/AvailabilityNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let AVAILABILITY_NODES: [Node] = [
21+
public let AVAILABILITY_NODES: [Node] = [
2222
% for node in AVAILABILITY_NODES:
2323
${make_swift_node(node)},
2424

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let BUILDER_INITIALIZABLE_TYPES: [String: String?] = [
21+
public let BUILDER_INITIALIZABLE_TYPES: [String: String?] = [
2222
% for type, resolved_type in BUILDER_INITIALIZABLE_TYPES.items():
2323
"${type}": ${'"' + resolved_type + '"' if resolved_type is not None else 'nil'},
2424
% end

Code-Generation/Sources/generate-swiftsyntaxbuilder/Child.swift renamed to Code-Generation/Sources/SyntaxSupport/Child.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,36 @@
1212

1313
/// A child of a node, that may be declared optional or a token with a
1414
/// restricted subset of acceptable kinds or texts.
15-
class Child {
16-
let name: String
17-
let syntaxKind: String
18-
let description: String?
19-
let collectionElementName: String?
20-
let forceClassification: Bool
21-
let isIndented: Bool
22-
let requiresLeadingNewline: Bool
23-
let isOptional: Bool
24-
let textChoices: [String]
25-
let nodeChoices: [Child]
26-
let classification: SyntaxClassification?
15+
public class Child {
16+
public let name: String
17+
public let syntaxKind: String
18+
public let description: String?
19+
public let collectionElementName: String?
20+
public let forceClassification: Bool
21+
public let isIndented: Bool
22+
public let requiresLeadingNewline: Bool
23+
public let isOptional: Bool
24+
public let textChoices: [String]
25+
public let nodeChoices: [Child]
26+
public let classification: SyntaxClassification?
2727
/// A restricted set of token kinds that will be accepted for this child.
28-
let tokenChoices: [TokenSpec]
29-
let tokenCanContainArbitraryText: Bool
28+
public let tokenChoices: [TokenSpec]
29+
public let tokenCanContainArbitraryText: Bool
3030

31-
var swiftName: String {
31+
public var swiftName: String {
3232
return lowercaseFirstWord(name: name)
3333
}
3434

35-
var swiftSyntaxKind: String {
35+
public var swiftSyntaxKind: String {
3636
return lowercaseFirstWord(name: syntaxKind)
3737
}
3838

39-
var typeName: String {
39+
public var typeName: String {
4040
return kindToType(kind: syntaxKind)
4141
}
4242

4343
/// If the child ends with "token" in the kind, it's considered a token node. Grab the existing reference to that token from the global list.
44-
var tokenKind: String? {
44+
public var tokenKind: String? {
4545
if syntaxKind.hasSuffix("Token") {
4646
return syntaxKind
4747
} else {
@@ -50,22 +50,22 @@ class Child {
5050
}
5151

5252
/// Returns `true` if this child has a token kind.
53-
var isToken: Bool {
53+
public var isToken: Bool {
5454
return tokenKind != nil
5555
}
5656

57-
var token: TokenSpec? {
57+
public var token: TokenSpec? {
5858
guard let tokenKind = tokenKind else { return nil }
5959
return SYNTAX_TOKEN_MAP[tokenKind]
6060
}
6161

6262
/// Returns the first choice from the `tokenChoices` if there are any, otherwise returns `nil`.
63-
var mainToken: TokenSpec? {
63+
public var mainToken: TokenSpec? {
6464
return tokenChoices.first
6565
}
6666

6767
/// Whether this child has syntax kind `UnexpectedNodes`.
68-
var isUnexpectedNodes: Bool {
68+
public var isUnexpectedNodes: Bool {
6969
syntaxKind == "UnexpectedNodes"
7070
}
7171

Code-Generation/Sources/generate-swiftsyntaxbuilder/Classification.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/Classification.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//===----------------------------------------------------------------------===//
2121

2222
/// Represents a classification a token can receive for syntax highlighting.
23-
class SyntaxClassification {
23+
public class SyntaxClassification {
2424
public let name: String
2525
public let description: String
2626

@@ -34,7 +34,7 @@ class SyntaxClassification {
3434
}
3535
}
3636

37-
let SYNTAX_CLASSIFICATIONS: [SyntaxClassification] = [
37+
public let SYNTAX_CLASSIFICATIONS: [SyntaxClassification] = [
3838
% for syntaxClassification in SYNTAX_CLASSIFICATIONS:
3939
SyntaxClassification(name: "${syntaxClassification.name}", description: "${syntaxClassification.description.strip()}"),
4040
% end

Code-Generation/Sources/generate-swiftsyntaxbuilder/CommonNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/CommonNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let COMMON_NODES: [Node] = [
21+
public let COMMON_NODES: [Node] = [
2222
% for node in COMMON_NODES:
2323
${make_swift_node(node)},
2424

Code-Generation/Sources/generate-swiftsyntaxbuilder/DeclNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/DeclNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let DECL_NODES: [Node] = [
21+
public let DECL_NODES: [Node] = [
2222
% for node in DECL_NODES:
2323
${make_swift_node(node)},
2424

Code-Generation/Sources/generate-swiftsyntaxbuilder/ExprNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/ExprNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let EXPR_NODES: [Node] = [
21+
public let EXPR_NODES: [Node] = [
2222
% for node in EXPR_NODES:
2323
${make_swift_node(node)},
2424

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES: [String: [String]] = [
21+
public let SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES: [String: [String]] = [
2222
% for buildable, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
2323
"${buildable}": [
2424
% for conformance in conformances:

Code-Generation/Sources/generate-swiftsyntaxbuilder/GenericNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/GenericNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let GENERIC_NODES: [Node] = [
21+
public let GENERIC_NODES: [Node] = [
2222
% for node in GENERIC_NODES:
2323
${make_swift_node(node)},
2424

Code-Generation/Sources/generate-swiftsyntaxbuilder/Node.swift renamed to Code-Generation/Sources/SyntaxSupport/Node.swift

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,65 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Foundation
14+
1315
/// A Syntax node, possibly with children.
1416
/// If the kind is "SyntaxCollection", then this node is considered a Syntax
1517
/// Collection that will expose itself as a typedef rather than a concrete
1618
/// subclass.
17-
class Node {
18-
let syntaxKind: String
19-
let swiftSyntaxKind: String
20-
let name: String
21-
let nameForDiagnostics: String?
22-
let description: String?
23-
let baseKind: String
24-
let traits: [String]
25-
let children: [Child]
26-
let nonUnexpectedChildren: [Child]
27-
let collectionElementName: String?
28-
let collectionElementChoices: [String]?
29-
let omitWhenEmpty: Bool
30-
let elementsSeparatedByNewline: Bool
31-
let collectionElement: String
19+
public class Node {
20+
public let syntaxKind: String
21+
public let swiftSyntaxKind: String
22+
public let name: String
23+
public let nameForDiagnostics: String?
24+
public let description: String?
25+
public let baseKind: String
26+
public let traits: [String]
27+
public let children: [Child]
28+
public let nonUnexpectedChildren: [Child]
29+
public let collectionElementName: String?
30+
public let collectionElementChoices: [String]?
31+
public let omitWhenEmpty: Bool
32+
public let elementsSeparatedByNewline: Bool
33+
public let collectionElement: String
3234

3335
/// Returns `True` if this node declares one of the base syntax kinds.
34-
var isBase: Bool {
36+
public var isBase: Bool {
3537
return SYNTAX_BASE_KINDS.contains(syntaxKind)
3638
}
3739

3840
/// Returns `True` if this node is a subclass of SyntaxCollection.
39-
var isSyntaxCollection: Bool {
41+
public var isSyntaxCollection: Bool {
4042
return baseKind == "SyntaxCollection"
4143
}
4244

4345
/// Returns `True` if this node should have a `validate` method associated.
44-
var requiresValidation: Bool {
46+
public var requiresValidation: Bool {
4547
return isBuildable
4648
}
4749

4850
/// Returns `True` if this node is an `Unknown` syntax subclass.
49-
var isUnknown: Bool {
51+
public var isUnknown: Bool {
5052
return syntaxKind.contains("Unknown")
5153
}
5254

5355
/// Returns `True` if this node is an `Unknown` syntax subclass.
54-
var isMissing: Bool {
56+
public var isMissing: Bool {
5557
return syntaxKind.contains("Missing")
5658
}
5759

5860
/// Returns `True` if this node should have a builder associated.
59-
var isBuildable: Bool {
61+
public var isBuildable: Bool {
6062
return !isBase && !isUnknown && !isMissing && !isSyntaxCollection
6163
}
6264

6365
/// Returns 'True' if this node shall not be created while parsing if it has no children.
64-
var shallBeOmittedWhenEmpty: Bool {
66+
public var shallBeOmittedWhenEmpty: Bool {
6567
return omitWhenEmpty
6668
}
6769

6870
/// Returns true if this child has a token kind.
69-
var isToken: Bool {
71+
public var isToken: Bool {
7072
return syntaxKind.contains("Token") || collectionElement.contains("Token")
7173
}
7274

Code-Generation/Sources/generate-swiftsyntaxbuilder/PatternNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/PatternNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let PATTERN_NODES: [Node] = [
21+
public let PATTERN_NODES: [Node] = [
2222
% for node in PATTERN_NODES:
2323
${make_swift_node(node)},
2424

Code-Generation/Sources/generate-swiftsyntaxbuilder/StmtNodes.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/StmtNodes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let STMT_NODES: [Node] = [
21+
public let STMT_NODES: [Node] = [
2222
% for node in STMT_NODES:
2323
${make_swift_node(node)},
2424

Code-Generation/Sources/generate-swiftsyntaxbuilder/SyntaxBaseKinds.swift.gyb renamed to Code-Generation/Sources/SyntaxSupport/SyntaxBaseKinds.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
let SYNTAX_BASE_KINDS: Set<String> = [
21+
public let SYNTAX_BASE_KINDS: Set<String> = [
2222
% for name in SYNTAX_BASE_KINDS:
2323
"${name}",
2424
% end

Code-Generation/Sources/generate-swiftsyntaxbuilder/SyntaxNodes.swift renamed to Code-Generation/Sources/SyntaxSupport/SyntaxNodes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
let SYNTAX_NODES: [Node] = COMMON_NODES
13+
public let SYNTAX_NODES: [Node] = COMMON_NODES
1414
+ EXPR_NODES
1515
+ DECL_NODES
1616
+ ATTRIBUTE_NODES
@@ -21,6 +21,6 @@ let SYNTAX_NODES: [Node] = COMMON_NODES
2121
+ AVAILABILITY_NODES
2222

2323
/// A lookup table of nodes indexed by their kind.
24-
let SYNTAX_NODE_MAP: [String: Node] = Dictionary(
24+
public let SYNTAX_NODE_MAP: [String: Node] = Dictionary(
2525
uniqueKeysWithValues: SYNTAX_NODES.map { node in (node.syntaxKind, node) }
2626
)

0 commit comments

Comments
 (0)