Skip to content

Commit 5c8b87b

Browse files
authored
Merge pull request rarestype#121 from rarestype/typed-throws
[major]: port the parser over to typed throws
2 parents 5ad57a3 + d942aa5 commit 5c8b87b

16 files changed

Lines changed: 33 additions & 47 deletions

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let package: Package = .init(
1515
],
1616
dependencies: [
1717
.package(url: "https://github.com/ordo-one/dollup", from: "1.0.1"),
18-
.package(url: "https://github.com/rarestype/gram", from: "1.0.0"),
18+
.package(url: "https://github.com/rarestype/gram", from: "2.0.0"),
1919
],
2020
targets: [
2121
.target(name: "JSONAST"),

Snippets/ParsingErrors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ let invalid: String = """
66
"""
77
do {
88
let _: JSON.Node = try .init(parsing: invalid)
9-
} catch is Pattern.UnexpectedValueError {
10-
print("JSON failed to parse!")
9+
} catch let error {
10+
print("JSON failed to parse! (\(error))")
1111
}

Sources/JSONAST/JSON.Number.Inline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ extension JSON.Number {
3838
}
3939
}
4040
extension JSON.Number.Inline {
41-
@available(*, deprecated, message: "prefer initializing 'JSON.Number' directly")
41+
@available(*, unavailable, message: "prefer initializing 'JSON.Number' directly")
4242
@inlinable public init<T>(_ signed: T) where T: SignedInteger {
4343
self.init(sign: signed < 0 ? .minus : .plus, units: UInt64.init(signed.magnitude))
4444
}
45-
@available(*, deprecated, message: "prefer initializing 'JSON.Number' directly")
45+
@available(*, unavailable, message: "prefer initializing 'JSON.Number' directly")
4646
@inlinable public init<T>(_ unsigned: T) where T: UnsignedInteger {
4747
self.init(sign: .plus, units: UInt64.init(unsigned))
4848
}

Sources/JSONDecoding/Decoding/JSON.DecodingError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension JSON.DecodingError: Equatable where Location: Equatable {
2121
/// the underlying ``Error`` existentials are not ``Equatable``.
2222
public static func == (lhs: Self, rhs: Self) -> Bool {
2323
lhs.location == rhs.location &&
24-
lhs.underlying == rhs.underlying
24+
lhs.underlying ~= rhs.underlying
2525
}
2626
}
2727
extension JSON.DecodingError: TraceableError {

Sources/JSONParsing/JSON.Array (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ extension JSON.Array {
2626
extension JSON.Array: LosslessStringConvertible {
2727
/// See ``init(parsing:) (String)``.
2828
public init?(_ description: String) {
29-
do { try self.init(parsing: description) } catch { return nil }
29+
do { try self.init(parsing: description) } catch { return nil }
3030
}
3131
}

Sources/JSONParsing/JSON.Node (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ extension JSON.Node {
3737
extension JSON.Node: LosslessStringConvertible {
3838
/// See ``init(parsingFragment:) (String)``.
3939
public init?(_ description: String) {
40-
do { try self.init(parsingFragment: description) } catch { return nil }
40+
do { try self.init(parsingFragment: description) } catch { return nil }
4141
}
4242
}

Sources/JSONParsing/JSON.Object (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ extension JSON.Object {
3535
extension JSON.Object: LosslessStringConvertible {
3636
/// See ``init(parsing:) (String)``.
3737
public init?(_ description: String) {
38-
do { try self.init(parsing: description) } catch { return nil }
38+
do { try self.init(parsing: description) } catch { return nil }
3939
}
4040
}

Sources/JSONParsing/Rules/JSON.NodeRule.Array.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ extension JSON.NodeRule {
66
/// Array literals begin and end with square brackets (`[` and `]`), and
77
/// recursively contain instances of ``JSON.NodeRule`` separated by ``JSON.CommaRule``s.
88
/// Trailing commas (a JSON5 extension) are not allowed.
9-
enum Array {
10-
}
9+
enum Array {}
1110
}
1211
extension JSON.NodeRule.Array: ParsingRule {
1312
typealias Terminal = UInt8
1413

1514
static func parse<Source>(
1615
_ input: inout ParsingInput<some ParsingDiagnostics<Source>>
17-
) throws -> [JSON.Node]
18-
where Source.Element == Terminal,
19-
Source.Index == Location {
16+
) throws(PatternMatchingError) -> [JSON.Node]
17+
where Source.Element == Terminal, Source.Index == Location {
2018
try input.parse(as: JSON.BracketLeftRule<Location>.self)
2119
var elements: [JSON.Node]
2220
if let head: JSON.Node = try? input.parse(as: JSON.NodeRule<Location>.self) {

Sources/JSONParsing/Rules/JSON.NodeRule.Nonfinite.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extension JSON.NodeRule {
66

77
static func parse<Source>(
88
_ input: inout ParsingInput<some ParsingDiagnostics<Source>>
9-
) throws -> JSON.Number
9+
) throws(PatternMatchingError) -> JSON.Number
1010
where Source.Element == Terminal, Source.Index == Location {
1111

1212
if let _: Void = input.parse(

Sources/JSONParsing/Rules/JSON.NodeRule.Object.Item.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ extension JSON.NodeRule.Object {
55
///
66
/// A key-value expression consists of a ``JSON.StringRule``, a ``JSON.ColonRule``, and
77
/// a recursive instance of ``JSON.NodeRule``.
8-
enum Item {
9-
}
8+
enum Item {}
109
}
1110
extension JSON.NodeRule.Object.Item: ParsingRule {
1211
typealias Terminal = UInt8
1312

1413
static func parse<Source>(
1514
_ input: inout ParsingInput<some ParsingDiagnostics<Source>>
16-
) throws -> (
15+
) throws(PatternMatchingError) -> (
1716
key: JSON.Key,
1817
value: JSON.Node
1918
)

0 commit comments

Comments
 (0)