SyntaxKit is a Swift package that allows developers to build Swift code using result builders.
SyntaxKit provides a declarative way to generate Swift code structures using SwiftSyntax.
Add SyntaxKit to your project using Swift Package Manager:
dependencies: [
.package(url: "https://github.com/brightdigit/SyntaxKit.git", from: "0.0.1")
]
SyntaxKit provides a set of result builders that allow you to create Swift code structures in a declarative way. Here's an example:
import SyntaxKit
let code = Struct("BlackjackCard") {
Enum("Suit") {
Case("spades").equals("♠")
Case("hearts").equals("♡")
Case("diamonds").equals("♢")
Case("clubs").equals("♣")
}
.inherits("Character")
.comment{
Line("nested Suit enumeration")
}
}
let generatedCode = code.generateCode()
This will generate the following Swift code:
struct BlackjackCard {
// nested Suit enumeration
enum Suit: Character {
case spades = "♠"
case hearts = "♡"
case diamonds = "♢"
case clubs = "♣"
}
}
- Create structs, enums, and cases using result builders
- Add inheritance and comments to your code structures
- Generate formatted Swift code using SwiftSyntax
- Type-safe code generation
- Swift 6.1+
- macOS 13.0+
This project is licensed under the MIT License - see the LICENSE file for details.