@@ -15,8 +15,7 @@ extension Processor {
15
15
var pos : Position ?
16
16
17
17
// Quantifiers may store a range of positions to restore to
18
- var rangeStart : Position ?
19
- var rangeEnd : Position ?
18
+ var quantifiedRange : Range < Position > ?
20
19
21
20
// FIXME: refactor, for now this field is only used for quantifier save
22
21
// points. We should try to separate out the concerns better.
@@ -53,43 +52,28 @@ extension Processor {
53
52
// Whether this save point is quantified, meaning it has a range of
54
53
// possible positions to explore.
55
54
var isQuantified : Bool {
56
- if rangeEnd == nil {
57
- assert ( rangeStart == nil )
58
- return false
59
- }
60
- assert ( rangeStart != nil )
61
- return true
62
- }
63
-
64
- mutating func updateRange( newEnd: Input . Index ) {
65
- if rangeStart == nil {
66
- assert ( rangeEnd == nil )
67
- rangeStart = newEnd
68
- }
69
- rangeEnd = newEnd
55
+ quantifiedRange != nil
70
56
}
71
57
72
58
/// Move the next range position into pos, and removing it from the range
73
59
mutating func takePositionFromRange( _ input: Input ) {
74
60
assert ( isQuantified)
75
- pos = rangeEnd!
76
- shrinkRange ( input)
77
- }
61
+ let range = quantifiedRange!
62
+ pos = range. upperBound
63
+ if range. isEmpty {
64
+ // Becomes a normal save point
65
+ quantifiedRange = nil
66
+ return
67
+ }
78
68
79
- /// Shrink the range of the save point by one index, essentially dropping the last index
80
- mutating func shrinkRange( _ input: Input ) {
81
- assert ( isQuantified)
82
- if rangeEnd == rangeStart {
83
- // The range is now empty
84
- rangeStart = nil
85
- rangeEnd = nil
69
+ // Shrink the range
70
+ let newUpper : Position
71
+ if isScalarSemantics {
72
+ newUpper = input. unicodeScalars. index ( before: range. upperBound)
86
73
} else {
87
- if isScalarSemantics {
88
- input. unicodeScalars. formIndex ( before: & rangeEnd!)
89
- } else {
90
- input. formIndex ( before: & rangeEnd!)
91
- }
74
+ newUpper = input. index ( before: range. upperBound)
92
75
}
76
+ quantifiedRange = range. lowerBound..< newUpper
93
77
}
94
78
}
95
79
@@ -99,8 +83,7 @@ extension Processor {
99
83
SavePoint (
100
84
pc: pc,
101
85
pos: currentPosition,
102
- rangeStart: nil ,
103
- rangeEnd: nil ,
86
+ quantifiedRange: nil ,
104
87
isScalarSemantics: false ,
105
88
stackEnd: . init( callStack. count) ,
106
89
captureEnds: storedCaptures,
@@ -114,8 +97,7 @@ extension Processor {
114
97
SavePoint (
115
98
pc: pc,
116
99
pos: nil ,
117
- rangeStart: nil ,
118
- rangeEnd: nil ,
100
+ quantifiedRange: nil ,
119
101
isScalarSemantics: false ,
120
102
stackEnd: . init( callStack. count) ,
121
103
captureEnds: storedCaptures,
@@ -130,42 +112,7 @@ extension Processor {
130
112
SavePoint (
131
113
pc: controller. pc + 1 ,
132
114
pos: nil ,
133
- rangeStart: range. lowerBound,
134
- rangeEnd: range. upperBound,
135
- isScalarSemantics: isScalarSemantics,
136
- stackEnd: . init( callStack. count) ,
137
- captureEnds: storedCaptures,
138
- intRegisters: registers. ints,
139
- posRegisters: registers. positions)
140
- }
141
- //
142
- // func makeSavePoint(
143
- // resumeAt pc: InstructionAddress? = nil,
144
- // quantifiedRange: Range<Position>? = nil,
145
- // addressOnly: Bool = false,
146
- // isScalarSemantics: Bool = false
147
- // ) -> SavePoint {
148
- // SavePoint(
149
- // pc: pc ?? controller.pc + 1,
150
- // pos: addressOnly ? nil : currentPosition,
151
- // rangeStart: quantifiedRange?.lowerBound,
152
- // rangeEnd: quantifiedRange?.lowerBound,
153
- // isScalarSemantics: false, // FIXME: refactor away
154
- // stackEnd: .init(callStack.count),
155
- // captureEnds: storedCaptures,
156
- // intRegisters: registers.ints,
157
- // posRegisters: registers.positions)
158
- // }
159
-
160
- func startQuantifierSavePoint(
161
- isScalarSemantics: Bool
162
- ) -> SavePoint {
163
- // Restores to the instruction AFTER the current quantifier instruction
164
- SavePoint (
165
- pc: controller. pc + 1 ,
166
- pos: nil ,
167
- rangeStart: nil ,
168
- rangeEnd: nil ,
115
+ quantifiedRange: range,
169
116
isScalarSemantics: isScalarSemantics,
170
117
stackEnd: . init( callStack. count) ,
171
118
captureEnds: storedCaptures,
0 commit comments