From 9b924d03481c7666b8cbf10d27cf6ba75b63ef41 Mon Sep 17 00:00:00 2001 From: parrt Date: Sat, 26 Nov 2011 11:00:38 -0800 Subject: [PATCH] fix toString for EPS [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9465] --- .../antlr/v4/runtime/misc/IntervalSet.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java index 59be6fad4..f210a6730 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java @@ -481,14 +481,12 @@ public class IntervalSet implements IntSet { int a = I.a; int b = I.b; if ( a==b ) { - if ( a==Token.EOF ) buf.append(""); - else if ( a==Token.EPSILON ) buf.append(""); - else buf.append(tokenNames[a]); + buf.append(elementName(tokenNames, a)); } else { for (int i=a; i<=b; i++) { if ( i>a ) buf.append(", "); - buf.append(tokenNames[i]); + buf.append(elementName(tokenNames, i)); } } if ( iter.hasNext() ) { @@ -498,8 +496,15 @@ public class IntervalSet implements IntSet { if ( this.size()>1 ) { buf.append("}"); } - return buf.toString(); - } + return buf.toString(); + } + + protected String elementName(String[] tokenNames, int a) { + if ( a==Token.EOF ) return ""; + else if ( a==Token.EPSILON ) return ""; + else return tokenNames[a]; + + } @Override public int size() { @@ -582,17 +587,17 @@ public class IntervalSet implements IntSet { // if whole interval x..x, rm if ( el==a && el==b ) { intervals.remove(i); - return; + break; } // if on left edge x..b, adjust left if ( el==a ) { I.a++; - return; + break; } // if on right edge a..x, adjust right if ( el==b ) { I.b--; - return; + break; } // if in middle a..x..b, split interval if ( el>a && el