SyntaxBuilder
A *toy* Swift code generator based on SwiftSyntax, leveraging Function Builders.
Install / Use
/learn @akkyie/SyntaxBuilderREADME
SyntaxBuilder
A toy Swift code generator based on SwiftSyntax, leveraging Function Builders.
Requirements
Xcode 11 beta-bundled Swift 5.1
Example
import SyntaxBuilder
struct UserSourceFile: SourceFile {
let idType: Type
@SyntaxListBuilder
var body: Body {
Import("Foundation")
Struct("User") {
Typealias("ID", of: idType)
Let("id", of: "ID")
.prependingComment("The user's ID.", .docLine)
Let("name", of: "String")
.prependingComment("The user's name.", .docLine)
Var("age", of: "Int")
.prependingComment("The user's age.", .docLine)
ForEach(0 ..< 3) { i in
Let("value\(i)", of: "String")
.prependingNewline()
}
}
.prependingComment("""
User is an user.
<https://github.com/akkyie/SyntaxBuilder/>
""", .docBlock)
}
}
let user = UserSourceFile(idType: "String")
var str: String = ""
user.write(to: &str)
print(str)
Output
import Foundation
/**
User is an user.
<https://github.com/akkyie/SyntaxBuilder/>
*/
struct User {
typealias ID = String
/// The user's ID.
let id: ID
/// The user's name.
let name: String
/// The user's age.
var age: Int
let value0: String
let value1: String
let value2: String
}
Related Skills
node-connect
335.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
335.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.7kCommit, push, and open a PR
