File tree Expand file tree Collapse file tree 3 files changed +24
-23
lines changed
_MatchingEngine/Regex/Parse Expand file tree Collapse file tree 3 files changed +24
-23
lines changed Original file line number Diff line number Diff line change @@ -29,22 +29,25 @@ public protocol Participant {
29
29
// ...
30
30
}
31
31
32
+ // Errors that may be thrown from default implementations
33
+ private enum ParticipantError : Error {
34
+ case unsupported
35
+ }
36
+
32
37
// Default impls
33
38
extension Participant {
34
- static var unsupported : Error { " Unsupported " }
35
-
36
39
// Produce a function that will parse a grapheme break entry from a line
37
40
public static func graphemeBreakProperty( ) throws -> ( String ) -> GraphemeBreakEntry ? {
38
- throw unsupported
41
+ throw ParticipantError . unsupported
39
42
}
40
43
41
44
// Produce a function that will extract the bodies of C-style comments from its input
42
45
public static func cComments( ) throws -> ( String ) -> [ Substring ] {
43
- throw unsupported
46
+ throw ParticipantError . unsupported
44
47
}
45
48
46
49
// Produce a function that will extract the bodies of Swift-style comments from its input
47
50
public static func swiftComments( ) throws -> ( String ) -> [ Substring ] {
48
- throw unsupported
51
+ throw ParticipantError . unsupported
49
52
}
50
53
}
Original file line number Diff line number Diff line change @@ -122,15 +122,6 @@ extension ParsingContext {
122
122
123
123
// Diagnostics
124
124
extension Parser {
125
- mutating func report(
126
- _ str: String , _ function: String = #function, _ line: Int = #line
127
- ) throws -> Never {
128
- throw """
129
- ERROR: \( str)
130
- (error detected in parser at \( function) : \( line) )
131
- """
132
- }
133
-
134
125
fileprivate func loc(
135
126
_ start: Source . Position
136
127
) -> SourceLocation {
@@ -529,5 +520,3 @@ public func parseWithDelimiters<S: StringProtocol>(
529
520
let ( contents, delim) = droppingRegexDelimiters ( String ( regex) )
530
521
return try parse ( contents, delim. defaultSyntaxOptions)
531
522
}
532
-
533
- extension String : Error { }
Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ import XCTest
13
13
@testable import _MatchingEngine
14
14
@testable import _StringProcessing
15
15
16
+ struct MatchError : Error {
17
+ var message : String
18
+ init ( _ message: String ) {
19
+ self . message = message
20
+ }
21
+ }
22
+
16
23
extension Executor {
17
24
func _firstMatch(
18
25
_ regex: String , input: String ,
@@ -31,7 +38,7 @@ extension Executor {
31
38
let caps = result. rawCaptures. slices ( from: input)
32
39
return ( input [ result. range] , caps)
33
40
} else if start == input. endIndex {
34
- throw " match not found for \( regex) in \( input) "
41
+ throw MatchError ( " match not found for \( regex) in \( input) " )
35
42
} else {
36
43
input. formIndex ( after: & start)
37
44
}
@@ -76,27 +83,29 @@ func flatCaptureTest(
76
83
if expect == nil {
77
84
continue
78
85
} else {
79
- throw " Match failed "
86
+ throw MatchError ( " Match failed " )
80
87
}
81
88
}
82
89
guard let expect = expect else {
83
- throw " Match of \( test) succeeded where failure expected in \( regex) "
90
+ throw MatchError ( """
91
+ Match of \( test) succeeded where failure expected in \( regex)
92
+ """ )
84
93
}
85
94
let capStrs = caps. map { $0 == nil ? nil : String ( $0!) }
86
95
guard expect. count == capStrs. count else {
87
- throw """
96
+ throw MatchError ( """
88
97
Capture count mismatch:
89
98
\( expect)
90
99
\( capStrs)
91
- """
100
+ """ )
92
101
}
93
102
94
103
guard expect. elementsEqual ( capStrs) else {
95
- throw """
104
+ throw MatchError ( """
96
105
Capture mismatch:
97
106
\( expect)
98
107
\( capStrs)
99
- """
108
+ """ )
100
109
}
101
110
} catch {
102
111
if !xfail {
You can’t perform that action at this time.
0 commit comments