SwiftSyntaxBuilder a new library that makes it possible to generate Swift code in a declarative way using result builders.
The library contains everything to get started generating Swift code with a nice and convenient API, but there is space for improvements!
I would like to encourage everyone interested to give SwiftSyntaxBuilder a try, report any feedback you have or contribute to the library. Any contributions would be amazing and this is a community driven library so if you want to get involved, please do!
Based on your feedback, we will be working on finding the missing parts and implementing them.
If you find a bug or have a suggestion to improve the API, you can find the guide to report them here.
Congratulations on the initial take on the lib! This is awesome and really a lifesaver for source generation plugins I've been cheering on this effort from the sidelines ever since
For better or worse, for my current work we moved away from source generation but the shape of the lib and APIs looks excellent, exactly what one would have hoped for - congrats and thanks for your work!
You can perform this kind of code generation anywhere in your application. It is not bound to a main function. The examples in the swift-syntax repository are supposed to be readily executable. That's why they perform all the generation and transformation steps right in the main function.
Speaking about transformations, you can also rewrite an existing piece of code implementing a SyntaxRewriter (available in the SwiftSyntax module). AddOneToIntegerLiterals.swift is an example for that. To get from source code to an AST you want to use the Parser provided by SwiftParser.