Skip to content

Commit 3c93b41

Browse files
committed
Generate @resultbuilder with SwiftSyntaxBuilder
1 parent 7400e1d commit 3c93b41

File tree

12 files changed

+528
-5
lines changed

12 files changed

+528
-5
lines changed

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ let package = Package(
8181
"BuildableBaseProtocols.swift.gyb",
8282
"BuildableCollectionNodes.swift.gyb",
8383
"BuildableNodes.swift.gyb",
84-
"ResultBuilders.swift.gyb",
8584
"TokenSyntax.swift.gyb",
8685
]
8786
),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
15+
extension ArrayElement: ExpressibleAsArrayExpr {
16+
public func createArrayExpr() -> ArrayExpr {
17+
ArrayExpr(elements: ArrayElementList([self]))
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
15+
extension ArrayElementList: ExpressibleAsArrayExpr {
16+
public func createArrayExpr() -> ArrayExpr {
17+
ArrayExpr(elements: self)
18+
}
19+
}

Sources/SwiftSyntaxBuilderGeneration/Kinds.swift.gyb

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

2121
% quotedSyntaxBaseKinds = map(lambda x: '"%s"' % x, SYNTAX_BASE_KINDS)
22-
let SyntaxBaseKinds: [String] = [
22+
let SYNTAX_BASE_KINDS: [String] = [
2323
${",\n ".join(quotedSyntaxBaseKinds)}
2424
]

Sources/SwiftSyntaxBuilderGeneration/Node.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Node {
4242

4343
/// Returns `True` if this node declares one of the base syntax kinds.
4444
var isBase: Bool {
45-
return SyntaxBaseKinds.contains(syntaxKind)
45+
return SYNTAX_BASE_KINDS.contains(syntaxKind)
4646
}
4747

4848
/// Returns `True` if this node is a subclass of SyntaxCollection.
@@ -94,7 +94,7 @@ class Node {
9494
self.children = children
9595
self.baseKind = kind
9696

97-
if !SyntaxBaseKinds.contains(baseKind) {
97+
if !SYNTAX_BASE_KINDS.contains(baseKind) {
9898
fatalError("unknown base kind '\(baseKind)' for node '\(syntaxKind)'")
9999
}
100100

0 commit comments

Comments
 (0)