@@ -14,10 +14,10 @@ import Foundation
14
14
15
15
// MARK: - Parser
16
16
17
- struct Parser < A> {
17
+ struct Parser < A: Sendable > : Sendable {
18
18
/// Parses the given string. Returns the matched element `A` and the
19
19
/// remaining substring if the match is successful. Returns `nil` otherwise.
20
- let parse : ( _ string: Substring ) throws -> ( A , Substring ) ?
20
+ let parse : @ Sendable ( _ string: Substring ) throws -> ( A , Substring ) ?
21
21
}
22
22
23
23
extension Parser {
@@ -59,11 +59,11 @@ extension Parsers {
59
59
60
60
/// Matches any character contained in the given string.
61
61
static func char( from string: String ) -> Parser < Character > {
62
- char. filter ( string. contains)
62
+ char. filter { string. contains ( $0 ) }
63
63
}
64
64
65
65
static func char( from characterSet: CharacterSet ) -> Parser < Character > {
66
- char. filter ( characterSet. contains)
66
+ char. filter { characterSet. contains ( $0 ) }
67
67
}
68
68
69
69
/// Matches characters while the given string doesn't contain them.
@@ -75,7 +75,7 @@ extension Parsers {
75
75
static let int = digit. oneOrMore. map { Int ( String ( $0) ) }
76
76
77
77
/// Matches a single digit.
78
- static let digit = char. filter ( CharacterSet . decimalDigits. contains)
78
+ static let digit = char. filter { CharacterSet . decimalDigits. contains ( $0 ) }
79
79
}
80
80
81
81
extension Parser : ExpressibleByStringLiteral , ExpressibleByUnicodeScalarLiteral , ExpressibleByExtendedGraphemeClusterLiteral where A == Void {
@@ -123,22 +123,22 @@ extension Parsers {
123
123
}
124
124
125
125
extension Parser {
126
- func map< B> ( _ transform: @escaping ( A ) throws -> B ? ) -> Parser < B > {
126
+ func map< B: Sendable > ( _ transform: @ Sendable @escaping ( A) throws -> B ? ) -> Parser < B > {
127
127
flatMap { match in
128
128
Parser< B> { str in
129
129
( try transform ( match) ) . map { ( $0, str) }
130
130
}
131
131
}
132
132
}
133
133
134
- func flatMap< B> ( _ transform: @escaping ( A ) throws -> Parser < B > ) -> Parser < B > {
134
+ func flatMap< B> ( _ transform: @Sendable @ escaping ( A) throws -> Parser < B > ) -> Parser < B > {
135
135
Parser< B> { str in
136
136
guard let ( a, str) = try self . parse ( str) else { return nil }
137
137
return try transform ( a) . parse ( str)
138
138
}
139
139
}
140
140
141
- func filter( _ predicate: @escaping ( A ) -> Bool ) -> Parser < A > {
141
+ func filter( _ predicate: @Sendable @ escaping ( A ) -> Bool ) -> Parser < A > {
142
142
map { predicate ( $0) ? $0 : nil }
143
143
}
144
144
}
0 commit comments