MCPcopy Create free account
hub / github.com/antlr/antlr4 / removeRange

Method removeRange

runtime/JavaScript/src/antlr4/misc/IntervalSet.js:105–139  ·  view source on GitHub ↗
(toRemove)

Source from the content-addressed store, hash-verified

103 }
104
105 removeRange(toRemove) {
106 if(toRemove.start===toRemove.stop-1) {
107 this.removeOne(toRemove.start);
108 } else if (this.intervals !== null) {
109 let pos = 0;
110 for(let n=0; n<this.intervals.length; n++) {
111 const existing = this.intervals[pos];
112 // intervals are ordered
113 if (toRemove.stop<=existing.start) {
114 return;
115 }
116 // check for including range, split it
117 else if(toRemove.start>existing.start && toRemove.stop<existing.stop) {
118 this.intervals[pos] = new Interval(existing.start, toRemove.start);
119 const x = new Interval(toRemove.stop, existing.stop);
120 this.intervals.splice(pos, 0, x);
121 return;
122 }
123 // check for included range, remove it
124 else if(toRemove.start<=existing.start && toRemove.stop>=existing.stop) {
125 this.intervals.splice(pos, 1);
126 pos = pos - 1; // need another pass
127 }
128 // check for lower boundary
129 else if(toRemove.start<existing.stop) {
130 this.intervals[pos] = new Interval(existing.start, toRemove.start);
131 }
132 // check for upper boundary
133 else if(toRemove.stop<existing.stop) {
134 this.intervals[pos] = new Interval(toRemove.stop, existing.stop);
135 }
136 pos += 1;
137 }
138 }
139 }
140
141 removeOne(value) {
142 if (this.intervals !== null) {

Callers 1

complementMethod · 0.95

Calls 1

removeOneMethod · 0.95

Tested by

no test coverage detected