Hatch

510.0.0

Simplified Swift Parsing
sdidla/Hatch

What's New

510.0.0

2024-03-08T11:42:23Z

Updated to use swift-syntax 510.0.0 (Swift 5.10).

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

.package(url: "https://github.com/apple/swift-syntax", from: "510.0.0")

GitHub license Tests

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

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Sun Oct 20 2024 22:32:49 GMT-0900 (Hawaii-Aleutian Daylight Time)