@@ -15,6 +15,8 @@ enum ParseError: Error, Hashable {
1515 // TODO: I wonder if it makes sense to store the string.
1616 // This can make equality weird.
1717
18+ // MARK: Syntactic Errors
19+
1820 case numberOverflow( String )
1921 case expectedNumDigits( String , Int )
2022 case expectedNumber( String , kind: RadixKind )
@@ -43,7 +45,6 @@ enum ParseError: Error, Hashable {
4345
4446 case cannotReferToWholePattern
4547
46- case notQuantifiable
4748 case quantifierRequiresOperand( String )
4849
4950 case backtrackingDirectiveMustHaveName( String )
@@ -55,7 +56,6 @@ enum ParseError: Error, Hashable {
5556 case cannotRemoveMatchingOptionsAfterCaret
5657
5758 case expectedCustomCharacterClassMembers
58- case invalidCharacterClassRangeOperand
5959
6060 case emptyProperty
6161 case unknownProperty( key: String ? , value: String )
@@ -73,6 +73,17 @@ enum ParseError: Error, Hashable {
7373 case cannotRemoveExtendedSyntaxInMultilineMode
7474
7575 case expectedCalloutArgument
76+
77+ // MARK: Semantic Errors
78+
79+ case unsupported( String )
80+ case deprecatedUnicode( String )
81+ case invalidReference( Int )
82+ case duplicateNamedCapture( String )
83+ case invalidCharacterClassRangeOperand
84+ case invalidQuantifierRange( Int , Int )
85+ case invalidCharacterRange( from: Character , to: Character )
86+ case notQuantifiable
7687}
7788
7889extension IdentifierKind {
@@ -88,6 +99,7 @@ extension IdentifierKind {
8899extension ParseError : CustomStringConvertible {
89100 var description : String {
90101 switch self {
102+ // MARK: Syntactic Errors
91103 case let . numberOverflow( s) :
92104 return " number overflow: \( s) "
93105 case let . expectedNumDigits( s, i) :
@@ -114,8 +126,6 @@ extension ParseError: CustomStringConvertible {
114126 return " invalid escape sequence ' \\ \( c) ' "
115127 case . cannotReferToWholePattern:
116128 return " cannot refer to whole pattern here "
117- case . notQuantifiable:
118- return " expression is not quantifiable "
119129 case . quantifierRequiresOperand( let q) :
120130 return " quantifier ' \( q) ' must appear after expression "
121131 case . backtrackingDirectiveMustHaveName( let b) :
@@ -167,6 +177,23 @@ extension ParseError: CustomStringConvertible {
167177 return " extended syntax may not be disabled in multi-line mode "
168178 case . expectedCalloutArgument:
169179 return " expected argument to callout "
180+
181+ // MARK: Semantic Errors
182+
183+ case let . unsupported( kind) :
184+ return " \( kind) is not currently supported "
185+ case let . deprecatedUnicode( kind) :
186+ return " \( kind) is a deprecated Unicode property, and is not supported "
187+ case let . invalidReference( i) :
188+ return " no capture numbered \( i) "
189+ case let . duplicateNamedCapture( str) :
190+ return " group named ' \( str) ' already exists "
191+ case let . invalidQuantifierRange( lhs, rhs) :
192+ return " range lower bound ' \( lhs) ' must be less than or equal to upper bound ' \( rhs) ' "
193+ case let . invalidCharacterRange( from: lhs, to: rhs) :
194+ return " character ' \( lhs) ' must compare less than or equal to ' \( rhs) ' "
195+ case . notQuantifiable:
196+ return " expression is not quantifiable "
170197 }
171198 }
172199}
0 commit comments