22private typealias ASCIIBitset = DSLTree . CustomCharacterClass . AsciiBitset
33
44extension Processor {
5- private func maybeASCIIBitset(
6- _ payload: QuantifyPayload
7- ) -> ASCIIBitset ? {
8- guard payload. type == . asciiBitset else { return nil }
9- return registers [ payload. bitset]
10- }
11-
125 internal mutating func runQuantify( _ payload: QuantifyPayload ) -> Bool {
13- let asciiBitset = maybeASCIIBitset ( payload)
6+ if payload. type == . asciiBitset {
7+ guard let ( next, savePointRange) = input. matchQuantifiedASCIIBitset (
8+ registers [ payload. bitset] ,
9+ at: currentPosition,
10+ limitedBy: end,
11+ minMatches: payload. minTrips,
12+ maxMatches: payload. maxTrips,
13+ quantificationKind: payload. quantKind,
14+ isScalarSemantics: payload. isScalarSemantics
15+ ) else {
16+ signalFailure ( )
17+ return false
18+ }
19+ if let savePointRange {
20+ savePoints. append ( makeQuantifiedSavePoint (
21+ savePointRange, isScalarSemantics: payload. isScalarSemantics) )
22+ }
23+ currentPosition = next
24+ return true
25+ }
1426
1527 // TODO: Refactor below called functions to be non-mutating.
1628 // They might need to communicate save-point info upwards in addition to
@@ -25,7 +37,7 @@ extension Processor {
2537 case ( _, 0 , nil ) :
2638 let ( next, savePointRange) = input. runZeroOrMoreQuantify (
2739 payload,
28- asciiBitset: asciiBitset ,
40+ asciiBitset: nil ,
2941 at: currentPosition,
3042 limitedBy: end)
3143 if let savePointRange {
@@ -37,7 +49,7 @@ extension Processor {
3749 case ( _, 1 , nil ) :
3850 guard let ( next, savePointRange) = input. runOneOrMoreQuantify (
3951 payload,
40- asciiBitset: asciiBitset ,
52+ asciiBitset: nil ,
4153 at: currentPosition,
4254 limitedBy: end
4355 ) else {
@@ -53,7 +65,7 @@ extension Processor {
5365 case ( _, _, nil ) :
5466 guard let ( next, savePointRange) = input. runNOrMoreQuantify (
5567 payload,
56- asciiBitset: asciiBitset ,
68+ asciiBitset: nil ,
5769 at: currentPosition,
5870 limitedBy: end
5971 ) else {
@@ -70,7 +82,7 @@ extension Processor {
7082 // FIXME: Is this correct for lazy zero-or-one?
7183 let ( next, savePointRange) = input. runZeroOrOneQuantify (
7284 payload,
73- asciiBitset: asciiBitset ,
85+ asciiBitset: nil ,
7486 at: currentPosition,
7587 limitedBy: end)
7688 if let savePointRange {
@@ -82,7 +94,7 @@ extension Processor {
8294 default :
8395 guard let ( next, savePointRange) = input. runGeneralQuantify (
8496 payload,
85- asciiBitset: asciiBitset ,
97+ asciiBitset: nil ,
8698 at: currentPosition,
8799 limitedBy: end
88100 ) else {
@@ -232,24 +244,7 @@ extension String {
232244
233245 switch payload. type {
234246 case . asciiBitset:
235- while numMatches < maxTrips {
236- assert ( asciiBitset != nil , " Invariant: needs to be passed in " )
237- guard let next = matchASCIIBitset (
238- asciiBitset!,
239- at: currentPosition,
240- limitedBy: end,
241- isScalarSemantics: isScalarSemantics)
242- else {
243- break
244- }
245- numMatches &+= 1
246- if numMatches == minTrips {
247- rangeStart = next
248- }
249- rangeEnd = currentPosition
250- currentPosition = next
251- assert ( currentPosition > rangeEnd)
252- }
247+ fatalError ( " handled above " )
253248 case . asciiChar:
254249 let asciiScalar = UnicodeScalar . init ( _value: UInt32 ( payload. asciiChar) )
255250 while numMatches < maxTrips {
0 commit comments