Merge branch 'master' into main

This commit is contained in:
Terence Parr 2012-07-31 18:34:33 -07:00
commit abb268416e
2 changed files with 25 additions and 3 deletions

View File

@ -259,10 +259,14 @@ public class IntegerList {
} }
public final int binarySearch(int key) { public final int binarySearch(int key) {
return Arrays.binarySearch(_data, key); return Arrays.binarySearch(_data, 0, _size, key);
} }
public final int binarySearch(int fromIndex, int toIndex, int key) { public final int binarySearch(int fromIndex, int toIndex, int key) {
if (fromIndex < 0 || toIndex < 0 || fromIndex > _size || toIndex > _size) {
throw new IndexOutOfBoundsException();
}
return Arrays.binarySearch(_data, fromIndex, toIndex, key); return Arrays.binarySearch(_data, fromIndex, toIndex, key);
} }

View File

@ -34,7 +34,17 @@ import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.misc.CharSupport; import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.parse.ANTLRParser; import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.atn.ActionTransition;
import org.antlr.v4.runtime.atn.AtomTransition;
import org.antlr.v4.runtime.atn.NotSetTransition;
import org.antlr.v4.runtime.atn.RangeTransition;
import org.antlr.v4.runtime.atn.RuleStartState;
import org.antlr.v4.runtime.atn.SetTransition;
import org.antlr.v4.runtime.atn.TokensStartState;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar; import org.antlr.v4.tool.LexerGrammar;
@ -178,7 +188,15 @@ public class LexerATNFactory extends ParserATNFactory {
left.addTransition(new NotSetTransition(right, set)); left.addTransition(new NotSetTransition(right, set));
} }
else { else {
left.addTransition(new SetTransition(right, set)); Transition transition;
if (set.getIntervals().size() == 1) {
Interval interval = set.getIntervals().get(0);
transition = new RangeTransition(right, interval.a, interval.b);
} else {
transition = new SetTransition(right, set);
}
left.addTransition(transition);
} }
associatedAST.atnState = left; associatedAST.atnState = left;
return new Handle(left, right); return new Handle(left, right);