Fix issue where original ATN would be damaged by IntervalSet operations. Foxes #3216
This commit is contained in:
parent
20a4d9d138
commit
d82e8921a6
|
@ -7,11 +7,16 @@ const {Token} = require('./Token');
|
||||||
|
|
||||||
/* stop is not included! */
|
/* stop is not included! */
|
||||||
class Interval {
|
class Interval {
|
||||||
|
|
||||||
constructor(start, stop) {
|
constructor(start, stop) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.stop = stop;
|
this.stop = stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clone() {
|
||||||
|
return new Interval(this.start, this.stop);
|
||||||
|
}
|
||||||
|
|
||||||
contains(item) {
|
contains(item) {
|
||||||
return item >= this.start && item < this.stop;
|
return item >= this.start && item < this.stop;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +60,7 @@ class IntervalSet {
|
||||||
addInterval(toAdd) {
|
addInterval(toAdd) {
|
||||||
if (this.intervals === null) {
|
if (this.intervals === null) {
|
||||||
this.intervals = [];
|
this.intervals = [];
|
||||||
this.intervals.push(toAdd);
|
this.intervals.push(toAdd.clone());
|
||||||
} else {
|
} else {
|
||||||
// find insert pos
|
// find insert pos
|
||||||
for (let pos = 0; pos < this.intervals.length; pos++) {
|
for (let pos = 0; pos < this.intervals.length; pos++) {
|
||||||
|
@ -78,7 +83,7 @@ class IntervalSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// greater than any existing
|
// greater than any existing
|
||||||
this.intervals.push(toAdd);
|
this.intervals.push(toAdd.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue