Swiftpack.co -  k-ymmt/Cheetoh as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
k-ymmt/Cheetoh
SwiftSyntax Wrapper for Code Generation(Work In Progress)
.package(url: "https://github.com/k-ymmt/Cheetoh.git", from: "v0.0.1")

Cheetoh

SwiftSyntax wrapper for Code Generation like SwiftSyntaxBuilder.

Example

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!")
}

Supports

  • SourceFile

    • ☑ Import
    • ☐ Type Declaration
    • ☑ Top-level function
    • ☑ Top-level variable
  • Types

    • ☐ Class
    • ☑ Struct
    • ☐ Enum
  • Function

    • ☑ Declaration
    • ☑ Parameters
    • ☑ Return Type
    • ☑ throws, rethrows
    • ☑ Body
  • Variable

    • ☑ let
    • ☑ var
  • Generics

    • ☑ Parameters
    • ☐ Inherited Type
    • ☐ where
  • Literal

    • ☑ Int
    • ☑ Float
    • ☑ String
    • ☐ Array
    • ☐ Dictionary
  • Expression

    • ☑ Literal
    • ☑ Call Function
    • ☐ Method Chaining
    • ☐ Optional Chaining
  • ☑ Access Control(private, fileprivate, internal, public)

    • open currently not supported(SyntaxFactory.makeOpenKeyword() not found).
  • ☑ Initialize

  • ☑ Nillable type

  • @ Attributes

GitHub

link
Stars: 0
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Dependencies

Release Notes

v0.0.1
4 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics