@@ -39,10 +39,19 @@ public protocol ${kind}ListBuildable: SyntaxListBuildable {
39
39
func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]
40
40
}
41
41
42
+ % buildable_type = kind + 'Buildable'
43
+ public protocol ExpressibleAs${buildable_type} {
44
+ func create${buildable_type}() -> ${buildable_type}
45
+ }
46
+
42
47
% if kind == 'Syntax':
43
- public protocol ${kind}Buildable: ${kind}ListBuildable {
48
+ public protocol ${buildable_type}: ExpressibleAs${buildable_type}, ${kind}ListBuildable {
49
+ % elif kind == 'Decl':
50
+ public protocol ${buildable_type}: ExpressibleAs${buildable_type}, SyntaxBuildable, ${kind}ListBuildable, ExpressibleAsMemberDeclListItem, ExpressibleAsCodeBlockItem {
51
+ % elif kind == 'Stmt':
52
+ public protocol ${buildable_type}: ExpressibleAs${buildable_type}, SyntaxBuildable, ${kind}ListBuildable, ExpressibleAsCodeBlockItem {
44
53
% else:
45
- public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {
54
+ public protocol ${buildable_type}: ExpressibleAs${buildable_type}, SyntaxBuildable, ${kind}ListBuildable {
46
55
% end
47
56
/// Builds a `${build_kind}`.
48
57
/// - Parameter format: The `Format` to use.
@@ -51,7 +60,13 @@ public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {
51
60
func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}
52
61
}
53
62
54
- extension ${kind}Buildable {
63
+ extension ${buildable_type} {
64
+ public func create${buildable_type}() -> ${buildable_type} {
65
+ self
66
+ }
67
+ }
68
+
69
+ extension ${buildable_type} {
55
70
% if kind != 'Syntax':
56
71
/// Builds a `${build_kind}`.
57
72
/// - Returns: A `${build_kind}`.
@@ -82,6 +97,22 @@ extension ${kind}Buildable {
82
97
[build${kind}(format: format, leadingTrivia: leadingTrivia)]
83
98
}
84
99
}
100
+ % if kind == 'Decl':
101
+
102
+ extension DeclBuildable {
103
+ public func createMemberDeclListItem() -> MemberDeclListItem {
104
+ MemberDeclListItem(decl: self)
105
+ }
106
+ }
107
+ % end
108
+ % if kind in ['Decl', 'Stmt']:
109
+
110
+ extension ${kind}Buildable {
111
+ public func createCodeBlockItem() -> CodeBlockItem {
112
+ CodeBlockItem(item: self)
113
+ }
114
+ }
115
+ % end
85
116
86
117
% end
87
118
% end
@@ -196,5 +227,26 @@ public struct ${node.syntax_kind}: SyntaxBuildable {
196
227
}
197
228
}
198
229
230
+ % end
231
+ % if node.is_buildable() or node.is_syntax_collection():
232
+ public protocol ExpressibleAs${node.syntax_kind} {
233
+ func create${node.syntax_kind}() -> ${node.syntax_kind}
234
+ }
235
+
236
+ extension ${node.syntax_kind}: ExpressibleAs${node.syntax_kind} {
237
+ public func create${node.syntax_kind}() -> ${node.syntax_kind} {
238
+ self
239
+ }
240
+ }
241
+
199
242
% end
200
243
% end
244
+ public protocol ExpressibleAsTokenSyntax {
245
+ func createTokenSyntax() -> TokenSyntax
246
+ }
247
+
248
+ extension TokenSyntax: ExpressibleAsTokenSyntax {
249
+ public func createTokenSyntax() -> TokenSyntax {
250
+ self
251
+ }
252
+ }
0 commit comments