Swiftpack.co - omochi/SwiftTypeReader as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by omochi.
omochi/SwiftTypeReader 2.10.1
You can gather type definitions from Swift source code.
⭐️ 28
🕓 1 week ago
macOS
.package(url: "https://github.com/omochi/SwiftTypeReader.git", from: "2.10.1")

SwiftTypeReader

You can gather type definitions from Swift source code.

Example

    func testReadmeExample() throws {
        try withExtendedLifetime(Context()) { (context) in
            let module = context.getOrCreateModule(name: "main")
            let reader = Reader(context: context, module: module)

            let source = try reader.read(
                source: """
struct S {
    var a: Int?
}
""",
                file: URL(fileURLWithPath: "S.swift")
            )
            _ = source

            let s = try XCTUnwrap(module.find(name: "S")?.asStruct)
            XCTAssertEqual(s.name, "S")

            XCTAssertEqual(s.storedProperties.count, 1)
            let a = try XCTUnwrap(s.find(name: "a")?.asVar)
            XCTAssertIdentical(a, s.storedProperties[safe: 0])
            XCTAssertEqual(a.name, "a")

            let aType = try XCTUnwrap(a.interfaceType.asEnum)
            XCTAssertEqual(aType.name, "Optional")
            XCTAssertEqual(aType.genericArgs.count, 1)

            let aWrappedType = try XCTUnwrap(aType.genericArgs[safe: 0]?.asStruct)
            XCTAssertEqual(aWrappedType.name, "Int")
        }
    }

More documents

Unsupported language features

Function body

It handles only signature.

Generic signatures of function

Variable without type annotation

struct S {
    var a = 0
}

It doesn't have type inference.

Vision

This library focus to use for building other libraries below.

But It's useful in standalone for other purpose like meta programming for Swift.

Development

Design consideration

This library refer to the Swift compiler and Slava's book to build architecture. It provides decls, types, and type reprs.

Code generation

$ swift package codegen

GitHub

link
Stars: 28
Last commit: 1 week ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

2.10.1
1 week ago

What's Changed

Full Changelog: https://github.com/omochi/SwiftTypeReader/compare/2.10.0...2.10.1

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