File tree Expand file tree Collapse file tree 3 files changed +19
-10
lines changed
Sources/_RegexParser/Regex/Parse Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,16 @@ public func swiftCompilerParseRegexLiteral(
107107 // however that it will need plumbing through on the compiler side.
108108 return ( regexToEmit: input, version: currentRegexLiteralFormatVersion)
109109 } catch {
110+ let message : String
111+ if
112+ let located = error as? Source . LocatedError ,
113+ let errorDiag = located. error as? Diagnostics . ErrorDiagnostic {
114+ message = errorDiag. description
115+ } else {
116+ message = String ( describing: error)
117+ }
110118 throw CompilerParseError (
111- message: " cannot parse regular expression: \( String ( describing : error ) ) " ,
119+ message: " cannot parse regular expression: \( message ) " ,
112120 location: ( error as? LocatedErrorProtocol ) ? . location. start
113121 )
114122 }
Original file line number Diff line number Diff line change @@ -337,13 +337,14 @@ public struct Diagnostics: Hashable {
337337 diags. contains ( where: { $0. behavior == . fatalError } )
338338 }
339339
340+ struct ErrorDiagnostic : Error , CustomStringConvertible {
341+ var diag : Diagnostic
342+ var description : String { diag. message }
343+ }
344+
340345 /// If any error diagnostic has been added, throw it as an Error.
341346 func throwAnyError( ) throws {
342347 for diag in diags where diag. isAnyError {
343- struct ErrorDiagnostic : Error , CustomStringConvertible {
344- var diag : Diagnostic
345- var description : String { diag. message }
346- }
347348 throw Source . LocatedError ( ErrorDiagnostic ( diag: diag) , diag. location)
348349 }
349350 }
Original file line number Diff line number Diff line change @@ -63,15 +63,15 @@ public protocol LocatedErrorProtocol: Error {
6363
6464extension Source {
6565 /// An error that includes information about the location in source code.
66- public struct LocatedError < E : Error > : Error , LocatedErrorProtocol {
67- public let error : E
66+ public struct LocatedError : Error , LocatedErrorProtocol {
67+ public let error : Error
6868 public let location : SourceLocation
6969
70- init ( _ e: E , _ r: SourceLocation ) {
70+ init ( _ e: Error , _ r: SourceLocation ) {
7171 self . error = e
7272 self . location = r
7373 }
74- public init ( _ v: E , _ r: Range < Source . Position > ) {
74+ public init ( _ v: Error , _ r: Range < Source . Position > ) {
7575 self . error = v
7676 self . location = Location ( r)
7777 }
@@ -133,6 +133,6 @@ extension Error {
133133 if self is LocatedErrorProtocol {
134134 return self
135135 }
136- return Source . LocatedError< Self > ( self , loc)
136+ return Source . LocatedError ( self , loc)
137137 }
138138}
You can’t perform that action at this time.
0 commit comments