Skip to content

Commit 76859c6

Browse files
authored
Unify/abstract what it means to parse "a number of things" (#190)
* Unify parsing a number of things Called `Length` for now, but open to other ideas! * wip * wip * wip * wip * wip * wip
1 parent c174609 commit 76859c6

File tree

12 files changed

+1004
-331
lines changed

12 files changed

+1004
-331
lines changed

Sources/Parsing/CountingRange.swift

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public protocol CountingRange {
2+
var minimum: Int { get }
3+
var maximum: Int? { get }
4+
}
5+
6+
extension Int: CountingRange {
7+
public var minimum: Int { self }
8+
public var maximum: Int? { self }
9+
}
10+
11+
extension ClosedRange: CountingRange where Bound == Int {
12+
public var minimum: Int { self.lowerBound }
13+
public var maximum: Int? { self.upperBound }
14+
}
15+
16+
extension PartialRangeFrom: CountingRange where Bound == Int {
17+
public var minimum: Int { self.lowerBound }
18+
public var maximum: Int? { nil }
19+
}
20+
21+
extension PartialRangeThrough: CountingRange where Bound == Int {
22+
public var minimum: Int { 0 }
23+
public var maximum: Int? { self.upperBound }
24+
}

0 commit comments

Comments
 (0)