You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Swift 5.8 Support
Co-authored-by: Jaap Wijnen <[email protected]>
* wip
* wip
* wip
* wip
* wip
* omit some benchmarks from swift 5.7
* wip
* FromSubstring ParseBuilder needs Substring as Input (#292)
* Downstream ParseBuilder should use Downstream.Input as Input (#291)
* Downstream ParseBuilder should use Downstream.Input as Input
The ParseBuilder is for Downstream so it should use it’s input. Or Upstream.Output as pipe runs the downstream parser on the output of the upstream parser. Which is why Upstream.Output == Downstream.Input.
With the 5.8 changes pipe uses the wrong input here. This only causes issues, if Upstream and Downstream have a different Input type.
* Pipe - Use Upstream.Output instead of Downstream.Input
* wip
* wip
* wip
* wip
* wip
* fix
* wip
---------
Co-authored-by: Jaap Wijnen <[email protected]>
Co-authored-by: Brandon Williams <[email protected]>
Co-authored-by: Kai Oelfke <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+52-47
Original file line number
Diff line number
Diff line change
@@ -103,22 +103,26 @@ It would be more straightforward and efficient to instead describe how to consum
103
103
We can start by describing what it means to parse a single row, first by parsing an integer off the front of the string, and then parsing a comma. We can do this by using the `Parse` type, which acts as an entry point into describing a list of parsers that you want to run one after the other to consume from an input:
104
104
105
105
```swift
106
-
let user =Parse {
106
+
let user =Parse(input: Substring.self) {
107
107
Int.parser()
108
108
","
109
109
}
110
110
```
111
111
112
+
Note that this parsing library is quite general, allowing one to parse _any_ kind of input into
113
+
_any_ kind of output. For this reason we sometimes need to specify the exact input type the parser
114
+
can process, in this case substrings.
115
+
112
116
Already this can consume the beginning of the input:
113
117
114
118
```swift
115
-
try user.parse("1,") // 1
119
+
try user.parse("1,") // 1
116
120
```
117
121
118
122
Next we want to take everything up until the next comma for the user's name, and then consume the comma:
119
123
120
124
```swift
121
-
let user =Parse {
125
+
let user =Parse(input: Substring.self) {
122
126
Int.parser()
123
127
","
124
128
Prefix { $0!="," }
@@ -129,7 +133,7 @@ let user = Parse {
129
133
And then we want to take the boolean at the end of the row for the user's admin status:
130
134
131
135
```swift
132
-
let user =Parse {
136
+
let user =Parse(input: Substring.self) {
133
137
Int.parser()
134
138
","
135
139
Prefix { $0!="," }
@@ -141,7 +145,7 @@ let user = Parse {
141
145
Currently this will parse a tuple `(Int, Substring, Bool)` from the input, and we can `.map` on that to turn it into a `User`:
142
146
143
147
```swift
144
-
let user =Parse {
148
+
let user =Parse(input: Substring.self) {
145
149
Int.parser()
146
150
","
147
151
Prefix { $0!="," }
@@ -154,7 +158,7 @@ let user = Parse {
154
158
To make the data we are parsing to more prominent, we can instead pass the transform closure as the first argument to `Parse`:
155
159
156
160
```swift
157
-
let user =Parse {
161
+
let user =Parse(input: Substring.self) {
158
162
User(id: $0, name: String($1), isAdmin: $2)
159
163
} with: {
160
164
Int.parser()
@@ -168,7 +172,7 @@ let user = Parse {
168
172
Or we can pass the `User` initializer to `Parse` in a point-free style by transforming the `Prefix` parser's output from a `Substring` to ` String` first:
169
173
170
174
```swift
171
-
let user =Parse(User.init(id:name:isAdmin:)) {
175
+
let user =Parse(input: Substring.self, User.init(id:name:isAdmin:)) {
172
176
Int.parser()
173
177
","
174
178
Prefix { $0!="," }.map(String.init)
@@ -305,46 +309,47 @@ Apple M1 Pro (10 cores, 8 performance and 2 efficiency)
0 commit comments