Skip to content

brightdigit/SyntaxKit

Repository files navigation

SyntaxKit

SyntaxKit is a Swift package that allows developers to build Swift code using result builders.

SwiftPM GitHub GitHub issues GitHub Workflow Status

Codecov CodeFactor Grade codebeat badge Maintainability

SyntaxKit provides a declarative way to generate Swift code structures using SwiftSyntax.

Installation

Add SyntaxKit to your project using Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/brightdigit/SyntaxKit.git", from: "0.0.1")
]

Usage

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 = ""
    }
}

Features

  • 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

Requirements

  • Swift 6.1+
  • macOS 13.0+

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

More Friendly SwiftSyntax API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •