Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime/Java/src/org/antlr/v4/runtime/misc/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
public class Interval {
public static final Interval INVALID = new Interval(-1,-2);

public int a;
public int b;
public final int a;
public final int b;

public Interval(int a, int b) { this.a=a; this.b=b; }

Expand Down
9 changes: 6 additions & 3 deletions runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,21 @@ public void remove(int el) {
}
// if on left edge x..b, adjust left
if ( el==a ) {
I.a++;
I = Interval.of(a+1, b);
intervals.set(i, I);
break;
}
// if on right edge a..x, adjust right
if ( el==b ) {
I.b--;
I = Interval.of(a, b-1);
intervals.set(i, I);
break;
}
// if in middle a..x..b, split interval
if ( el>a && el<b ) { // found in this interval
int oldb = I.b;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this variable oldb is redundant since we already saved I.b above at line 656. Let me know if you'd like me to remove this. (I didn't, in the spirit of keeping the change minimal)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only test coverage would tell us that. Let's not touch this.

I.b = el-1; // [a..x-1]
I = Interval.of(a, el-1); // [a..x-1]
intervals.set(i, I);
add(el+1, oldb); // add [x+1..b]
}
}
Expand Down
2 changes: 1 addition & 1 deletion tool/src/org/antlr/v4/parse/ANTLRLexer.g
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ UNICODE_ESC
Interval badRange = Interval.of(getCharIndex()-2-hCount, getCharIndex());
String lastChar = input.substring(badRange.b, badRange.b);
if ( lastChar.codePointAt(0)=='\'' ) {
badRange.b--;
badRange = Interval.of(badRange.a, badRange.b-1);
}
String bad = input.substring(badRange.a, badRange.b);
Token t = new CommonToken(input, state.type, state.channel, badRange.a, badRange.b);
Expand Down
Loading