Swiftpack.co - k-ymmt/Cheetoh as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by k-ymmt.
k-ymmt/Cheetoh v0.0.1
SwiftSyntax Wrapper for Code Generation(Work In Progress)
⭐️ 0
🕓 2 years ago
.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: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v0.0.1
2 years ago

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