SwiftSyntax wrapper for Code Generation like SwiftSyntaxBuilder.
import Foundation
import Cheetoh
var output: String = ""
SourceFile {
Import("Foundation")
Newlines()
Struct("Hoge") {
Let("hoge", String.self)
.initializer("hoge")
Var("foo", Int.self)
}.accessLevel(.public)
Newlines()
Let("hoge", TypeIdentifier("Hoge"))
.initializer(Call("Hoge", ["foo": 10]))
.accessLevel(.private)
Newlines()
Func("main") {
Call("print", [nil: "Hello World!"])
}
}.build(format: .init(indent: 4)).write(to: &output)
print(output)
Output:
import Foundation
public struct Hoge {
let hoge: String = "hoge"
var foo: Int
}
private let hoge: Hoge = Hoge(foo: 10)
func main() {
print("Hello World!")
}
SourceFile
Types
Function
Variable
Generics
Literal
Expression
☑ Access Control(private, fileprivate, internal, public)
open
currently not supported(SyntaxFactory.makeOpenKeyword()
not found).☑ Initialize
☑ Nillable type
☐ @
Attributes
link |
Stars: 0 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics