Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akkyie/SyntaxBuilder
A *toy* Swift code generator based on SwiftSyntax, leveraging Function Builders.
https://github.com/akkyie/SyntaxBuilder
Last synced: about 1 month ago
JSON representation
A *toy* Swift code generator based on SwiftSyntax, leveraging Function Builders.
- Host: GitHub
- URL: https://github.com/akkyie/SyntaxBuilder
- Owner: akkyie
- Created: 2019-07-12T16:56:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-17T13:51:01.000Z (over 5 years ago)
- Last Synced: 2024-08-02T08:10:05.611Z (4 months ago)
- Language: Swift
- Size: 39.1 KB
- Stars: 40
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-result-builders - SyntaxBuilder - A *toy* Swift code generator based on SwiftSyntax (Other)
README
# SyntaxBuilder
A *toy* Swift code generator based on SwiftSyntax, leveraging [`Function Builders`](https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX-function-builders.md).
## Requirements
Xcode 11 beta-bundled Swift 5.1
## Example
```swift
import SyntaxBuilderstruct 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.
""", .docBlock)
}
}let user = UserSourceFile(idType: "String")
var str: String = ""
user.write(to: &str)print(str)
```
### Output
```swift
import Foundation/**
User is an user.
*/
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
}
```