@@ -14,10 +14,10 @@ import Foundation
1414
1515// MARK: - Parser
1616
17- struct Parser < A> {
17+ struct Parser < A: Sendable > : Sendable {
1818 /// Parses the given string. Returns the matched element `A` and the
1919 /// 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 ) ?
2121}
2222
2323extension Parser {
@@ -59,11 +59,11 @@ extension Parsers {
5959
6060 /// Matches any character contained in the given string.
6161 static func char( from string: String ) -> Parser < Character > {
62- char. filter ( string. contains)
62+ char. filter { string. contains ( $0 ) }
6363 }
6464
6565 static func char( from characterSet: CharacterSet ) -> Parser < Character > {
66- char. filter ( characterSet. contains)
66+ char. filter { characterSet. contains ( $0 ) }
6767 }
6868
6969 /// Matches characters while the given string doesn't contain them.
@@ -75,7 +75,7 @@ extension Parsers {
7575 static let int = digit. oneOrMore. map { Int ( String ( $0) ) }
7676
7777 /// Matches a single digit.
78- static let digit = char. filter ( CharacterSet . decimalDigits. contains)
78+ static let digit = char. filter { CharacterSet . decimalDigits. contains ( $0 ) }
7979}
8080
8181extension Parser : ExpressibleByStringLiteral , ExpressibleByUnicodeScalarLiteral , ExpressibleByExtendedGraphemeClusterLiteral where A == Void {
@@ -123,22 +123,22 @@ extension Parsers {
123123}
124124
125125extension 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 > {
127127 flatMap { match in
128128 Parser< B> { str in
129129 ( try transform ( match) ) . map { ( $0, str) }
130130 }
131131 }
132132 }
133133
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 > {
135135 Parser< B> { str in
136136 guard let ( a, str) = try self . parse ( str) else { return nil }
137137 return try transform ( a) . parse ( str)
138138 }
139139 }
140140
141- func filter( _ predicate: @escaping ( A ) -> Bool ) -> Parser < A > {
141+ func filter( _ predicate: @Sendable @ escaping ( A ) -> Bool ) -> Parser < A > {
142142 map { predicate ( $0) ? $0 : nil }
143143 }
144144}
0 commit comments