Skip to content

Commit 05e610a

Browse files
committed
Improve the wording of a diagnostic
1 parent 61965c3 commit 05e610a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Sources/_RegexParser/Regex/Parse/Diagnostics.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ extension ParseError: CustomStringConvertible {
105105
case let .expectedNumDigits(s, i):
106106
return "expected \(i) digits in '\(s)'"
107107
case let .expectedNumber(s, kind: kind):
108-
let radix: String
109-
if kind == .decimal {
110-
radix = ""
111-
} else {
112-
radix = " of radix \(kind.radix)"
108+
let number: String
109+
switch kind {
110+
case .octal:
111+
number = "octal number"
112+
case .decimal:
113+
number = "number"
114+
case .hex:
115+
number = "hexadecimal number"
113116
}
114-
return "expected a numbers in '\(s)'\(radix)"
117+
let suffix = s.isEmpty ? "" : " in '\(s)'"
118+
return "expected \(number)\(suffix)"
115119
case let .expected(s):
116120
return "expected '\(s)'"
117121
case .unexpectedEndOfInput:

Tests/RegexTests/ParseTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,5 +2739,7 @@ extension RegexTests {
27392739
"#/[x*/#", "cannot parse regular expression: expected ']'")
27402740
compilerInterfaceDiagnosticMessageTest(
27412741
"/a{3,2}/", "cannot parse regular expression: range lower bound '3' must be less than or equal to upper bound '2'")
2742+
compilerInterfaceDiagnosticMessageTest(
2743+
#"#/\u{}/#"#, "cannot parse regular expression: expected hexadecimal number")
27422744
}
27432745
}

0 commit comments

Comments
 (0)