Skip to content

Commit

Permalink
Fix issue where original ATN would be damaged by IntervalSet operatio…
Browse files Browse the repository at this point in the history
…ns. Foxes #3216
  • Loading branch information
ericvergnaud committed Mar 18, 2021
1 parent 20a4d9d commit d82e892
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions runtime/JavaScript/src/antlr4/IntervalSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ const {Token} = require('./Token');

/* stop is not included! */
class Interval {

constructor(start, stop) {
this.start = start;
this.stop = stop;
}

clone() {
return new Interval(this.start, this.stop);
}

contains(item) {
return item >= this.start && item < this.stop;
}
Expand Down Expand Up @@ -55,7 +60,7 @@ class IntervalSet {
addInterval(toAdd) {
if (this.intervals === null) {
this.intervals = [];
this.intervals.push(toAdd);
this.intervals.push(toAdd.clone());
} else {
// find insert pos
for (let pos = 0; pos < this.intervals.length; pos++) {
Expand All @@ -78,7 +83,7 @@ class IntervalSet {
}
}
// greater than any existing
this.intervals.push(toAdd);
this.intervals.push(toAdd.clone());
}
}

Expand Down

0 comments on commit d82e892

Please sign in to comment.