Swiftpack.co - sdidla/Hatch as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sdidla.
sdidla/Hatch 509.0.0
Generate Swift with Swift
⭐️ 11
🕓 7 weeks ago
iOS macOS
.package(url: "https://github.com/sdidla/Hatch.git", from: "509.0.0")

GitHub license Tests Documentation

Hatch

A simple, extensible parser to to get a hierarchical list of symbols from swift code using SwiftSyntax

Documentation

Usage

When using Swift Package Manager, add the following to your package dependencies in the Package.swift file:

  .package(url: "https://github.com/sdidla/Hatch.git", from: "<#latest swift-syntax tag#>")

Releases

Hatch releases correspond to releases of SwiftSyntax

Example

import Hatch

let source: String = <some swift code>
let symbols = SymbolParser.parse(source: source)
dump(symbols)

Input:

struct A1 {

    struct BC {
        struct C1 {}
        struct C2 {}
        struct C3 {}
    }

    struct BD {
        struct D1 {}
        struct D2 {}
    }

    struct BX {}
}

struct A2 {}

enum MyEnum {}

Output:

▿ 3 elements
  ▿ Hatch.Struct
    - name: "A1"
    ▿ children: 3 elements
      ▿ Hatch.Struct
        - name: "BC"
        ▿ children: 3 elements
          ▿ Hatch.Struct
            - name: "C1"
            - children: 0 elements
            - inheritedTypes: 0 elements
          ▿ Hatch.Struct
            - name: "C2"
            - children: 0 elements
            - inheritedTypes: 0 elements
          ▿ Hatch.Struct
            - name: "C3"
            - children: 0 elements
            - inheritedTypes: 0 elements
        - inheritedTypes: 0 elements
      ▿ Hatch.Struct
        - name: "BD"
        ▿ children: 2 elements
          ▿ Hatch.Struct
            - name: "D1"
            - children: 0 elements
            - inheritedTypes: 0 elements
          ▿ Hatch.Struct
            - name: "D2"
            - children: 0 elements
            - inheritedTypes: 0 elements
        - inheritedTypes: 0 elements
      ▿ Hatch.Struct
        - name: "BX"
        - children: 0 elements
        - inheritedTypes: 0 elements
    - inheritedTypes: 0 elements
  ▿ Hatch.Struct
    - name: "A2"
    - children: 0 elements
    - inheritedTypes: 0 elements
  ▿ Hatch.Enum
    - name: "MyEnum"
    - children: 0 elements
    - inheritedTypes: 0 elements

GitHub

link
Stars: 11
Last commit: 7 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

509.0.0
7 weeks ago

This is the 509.0.0 release of Hatch, that aligns with Swift 5.9.

With this release, HatchParser and HatchBuilder have been unified into a single library called Hatch. Previously, HatchBuilder provided only a simple result builder to help with string concatenation called StringBuilder which is now part of Hatch.

To use this snapshot add the following dependency to your Package.swift:

.package(url: "https://github.com/sdidla/Hatch.git", from: "509.0.0")

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