From 588177afde68d57671519b56af1b887f55c79a81 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 8 Nov 2023 20:03:16 -0800 Subject: [PATCH 1/2] Case key path support --- Package.resolved | 13 ++++++++++-- Package.swift | 2 +- Sources/Parsing/Conversions/Enum.swift | 29 +++++++++++++++++++------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Package.resolved b/Package.resolved index 908ee008e9..177362a3d9 100644 --- a/Package.resolved +++ b/Package.resolved @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-case-paths", "state" : { - "revision" : "5da6989aae464f324eef5c5b52bdb7974725ab81", - "version" : "1.0.0" + "branch" : "case-key-paths", + "revision" : "7112451690777c2145aa86310d7f205c40e40998" } }, { @@ -36,6 +36,15 @@ "version" : "1.0.0" } }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036", + "version" : "509.0.2" + } + }, { "identity" : "xctest-dynamic-overlay", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 6a6a93bba5..ee3b8eadf5 100644 --- a/Package.swift +++ b/Package.swift @@ -18,8 +18,8 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), - .package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.0.0"), .package(url: "https://github.com/google/swift-benchmark", from: "0.1.1"), + .package(url: "https://github.com/pointfreeco/swift-case-paths", branch: "case-key-paths"), ], targets: [ .target( diff --git a/Sources/Parsing/Conversions/Enum.swift b/Sources/Parsing/Conversions/Enum.swift index 8818d9a72f..5419ce8d85 100644 --- a/Sources/Parsing/Conversions/Enum.swift +++ b/Sources/Parsing/Conversions/Enum.swift @@ -7,17 +7,23 @@ extension Conversion { /// Useful for transforming the output of a ``ParserPrinter`` into an enum: /// /// ```swift + /// @CasePathable /// enum Expression { /// case add(Int, Int) /// ... /// } /// - /// let add = ParsePrint(.case(Expression.add)) { - /// Int.parser() - /// "+" - /// Int.parser() + /// struct Add: ParserPrinter{ + /// var body: some ParserPrinter { + /// ParsePrint(.case(\Expression.Cases.add)) { + /// Int.parser() + /// "+" + /// Int.parser() + /// } + /// } /// } - /// try add.parse("1+2") // Expression.add(1, 2) + /// + /// try Add().parse("1+2") // Expression.add(1, 2) /// ``` /// /// To transform the output of a ``ParserPrinter`` into a struct, see ``memberwise(_:)``. @@ -27,22 +33,29 @@ extension Conversion { /// synthesized for structs. /// - Returns: A conversion that can embed the associated values of an enum case into the case, /// and extract the associated values from the case. + @inlinable + public static func `case`( + _ keyPath: CaseKeyPath + ) -> Self where Self == AnyCasePath { + AnyCasePath(keyPath) + } + @inlinable public static func `case`( _ initializer: @escaping (Values) -> Enum - ) -> Self where Self == CasePath { + ) -> Self where Self == AnyCasePath { /initializer } @inlinable public static func `case`( _ initializer: Enum - ) -> Self where Self == CasePath { + ) -> Self where Self == AnyCasePath { /initializer } } -extension CasePath: Conversion { +extension AnyCasePath: Conversion { @inlinable public func apply(_ input: Value) -> Root { self.embed(input) From 7625f381508b638eeaf052e21546354dc0dcbc75 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 8 Nov 2023 20:25:37 -0800 Subject: [PATCH 2/2] wip --- .github/workflows/ci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d2d1f2be5..89db844cb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - test # - benchmarks steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Select Xcode ${{ matrix.xcode }} run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app - name: System @@ -29,15 +29,15 @@ jobs: run: make ${{ matrix.command }} ubuntu_tests: + name: Ubuntu (Swift ${{ matrix.swift }}) + runs-on: ubuntu-20.04 strategy: matrix: - os: [ubuntu-20.04] - - runs-on: ${{ matrix.os }} - + swift: + - '5.9' steps: - - uses: actions/checkout@v3 - - name: Build - run: swift build - - name: Run tests - run: swift test + - uses: swift-actions/setup-swift@v1 + with: + swift-version: ${{ matrix.swift }} + - uses: actions/checkout@v4 + - run: swift test