@@ -39,10 +39,19 @@ public protocol ${kind}ListBuildable: SyntaxListBuildable {
3939 func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]
4040}
4141
42+ % buildable_type = kind + 'Buildable'
43+ public protocol ExpressibleAs${buildable_type} {
44+ func create${buildable_type}() -> ${buildable_type}
45+ }
46+
4247% 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 {
4453% else:
45- public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {
54+ public protocol ${buildable_type}: ExpressibleAs${buildable_type}, SyntaxBuildable, ${kind}ListBuildable {
4655% end
4756 /// Builds a `${build_kind}`.
4857 /// - Parameter format: The `Format` to use.
@@ -51,7 +60,13 @@ public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {
5160 func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}
5261}
5362
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} {
5570% if kind != 'Syntax':
5671 /// Builds a `${build_kind}`.
5772 /// - Returns: A `${build_kind}`.
@@ -82,6 +97,22 @@ extension ${kind}Buildable {
8297 [build${kind}(format: format, leadingTrivia: leadingTrivia)]
8398 }
8499}
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
85116
86117% end
87118% end
@@ -196,5 +227,26 @@ public struct ${node.syntax_kind}: SyntaxBuildable {
196227 }
197228}
198229
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+
199242% end
200243% 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