Skip to content

Commit

Permalink
Swift 5.7 Improvements (#261)
Browse files Browse the repository at this point in the history
* Swift 5.7 Improvements

While we have some ideas to take Swift 5.7 even further, we need more
time to let the details bake. Till then, we can still offer a
quality-of-life improvement for folks using Swift 5.7, especially those
working on Advent of Code 2022!

Improving Parsing's builder limits
----------------------------------

This is perhaps the most notable improvement for now.

Currently, Parsing's builders limits the number of parsers allowed in a
block because of how many overloads need to be maintained and generated.

Using Swift 5.7's new [`buildPartialBlock`][se-0348], we can greatly
improve upon this limit:

| Builder          | Block limit `swift(<5.7)` | Block limit `swift(>=5.7)` |
| ---------------- | ------------------------- | -------------------------- |
| `OneOfBuilder`   | 10                        | ∞                          |
| `ParserBuilder`  | 6                         | 10–∞*                      |

\* Up to 10 non-`Void` captures in a block, plus unlimited `Void`
captures.

This should make working with larger builders much easier. The limit of
10 captures is arbitrary and could be expanded. If you hit it, please
[let us know][discussions]!

[se-0348]: https://github.com/apple/swift-evolution/blob/main/proposals/0348-buildpartialblock.md
[discussions]: https://github.com/pointfreeco/swift-parsing/discussions

Adding primary associated types
-------------------------------

We've added primary associated types to a number of protocols:

  * `Parser<Input, Output>`
  * `ParserPrinter<Intput, Output>`
  * `Conversion<Input, Output>`
  * `PrependableCollection<Element>`

This will allow you to express and constrain these protocols in a more
lightweight, natural manner.

Formatter parser-printer support
--------------------------------

We've added support for using formatters directly in your parser
printers with the `Formatted` parser-printer:

```swift
let total = ParsePrint {
  "TOTAL: "
  Formatted(.currency(code: "USD"))
}

try total.parse("TOTAL: $42.42")  // 42.42
try total.print(99.95)            // "TOTAL: $99.95"
```

`Formatted` takes any of the many formatters shipping in iOS 15 and more
recently.

---

We have more plans for Parsing in the coming months to take even greater
advantage of modern Swift features, and we hope to explore them soon!

* Fix

* wip

* Clean up schemes

* wip

* remove 5.6 docs

Co-authored-by: Brandon Williams <[email protected]>
  • Loading branch information
stephencelis and mbrandonw authored Dec 8, 2022
1 parent 3a0affb commit 645c688
Show file tree
Hide file tree
Showing 25 changed files with 9,887 additions and 9,661 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/.build
/.swiftpm
/Packages
/*.xcodeproj
xcuserdata/
10 changes: 0 additions & 10 deletions .spi.yml

This file was deleted.

67 changes: 0 additions & 67 deletions .swiftpm/xcode/xcshareddata/xcschemes/Parsing_watchOS.xcscheme

This file was deleted.

77 changes: 0 additions & 77 deletions .swiftpm/xcode/xcshareddata/xcschemes/_URLRouting.xcscheme

This file was deleted.

163 changes: 0 additions & 163 deletions .swiftpm/xcode/xcshareddata/xcschemes/swift-parsing-Package.xcscheme

This file was deleted.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ benchmarks:

test:
xcodebuild test \
-workspace Parsing.xcworkspace \
-scheme Parsing \
-destination platform="$(PLATFORM_IOS)"
xcodebuild test \
-workspace Parsing.xcworkspace \
-scheme Parsing \
-destination platform="$(PLATFORM_MACOS)"
xcodebuild test \
-workspace Parsing.xcworkspace \
-scheme Parsing \
-destination platform="$(PLATFORM_TVOS)"

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Parsing.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Loading

0 comments on commit 645c688

Please sign in to comment.