forked from jasder/antlr
Merge pull request #1720 from parrt/fix-1703-part-deux
Fix 1703 part deux
This commit is contained in:
commit
94ac8d4b4c
|
@ -548,7 +548,10 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy {
|
|||
protected Token getMissingSymbol(Parser recognizer) {
|
||||
Token currentSymbol = recognizer.getCurrentToken();
|
||||
IntervalSet expecting = getExpectedTokens(recognizer);
|
||||
int expectedTokenType = expecting.getMinElement(); // get any element
|
||||
int expectedTokenType = Token.INVALID_TYPE;
|
||||
if ( !expecting.isNil() ) {
|
||||
expectedTokenType = expecting.getMinElement(); // get any element
|
||||
}
|
||||
String tokenText;
|
||||
if ( expectedTokenType== Token.EOF ) tokenText = "<missing EOF>";
|
||||
else tokenText = "<missing "+recognizer.getVocabulary().getDisplayName(expectedTokenType)+">";
|
||||
|
|
|
@ -407,7 +407,10 @@ public class ParserInterpreter extends Parser {
|
|||
if ( e instanceof InputMismatchException ) {
|
||||
InputMismatchException ime = (InputMismatchException)e;
|
||||
Token tok = e.getOffendingToken();
|
||||
int expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
|
||||
int expectedTokenType = Token.INVALID_TYPE;
|
||||
if ( !ime.getExpectedTokens().isNil() ) {
|
||||
expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
|
||||
}
|
||||
Token errToken =
|
||||
getTokenFactory().create(new Pair<TokenSource, CharStream>(tok.getTokenSource(), tok.getTokenSource().getInputStream()),
|
||||
expectedTokenType, tok.getText(),
|
||||
|
|
|
@ -128,16 +128,6 @@ public interface IntSet {
|
|||
@Override
|
||||
boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Returns the single value contained in the set, if {@link #size} is 1;
|
||||
* otherwise, result is undefined. Check {@link #isNil()} before using
|
||||
* this function.
|
||||
*
|
||||
* @return the single value contained in the set, if {@link #size} is 1;
|
||||
* otherwise, result is undefined.
|
||||
*/
|
||||
int getSingleElement();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the set contains the specified element.
|
||||
*
|
||||
|
|
|
@ -416,28 +416,15 @@ public class IntervalSet implements IntSet {
|
|||
return intervals==null || intervals.isEmpty();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int getSingleElement() {
|
||||
if ( intervals!=null && intervals.size()==1 ) {
|
||||
Interval I = intervals.get(0);
|
||||
if ( I.a == I.b ) {
|
||||
return I.a;
|
||||
}
|
||||
}
|
||||
return Token.INVALID_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum value contained in the set if not isNil().
|
||||
* Otherwise, result is undefined.
|
||||
*
|
||||
* @return the maximum value contained in the set. If the set is empty,
|
||||
* result is undefined.
|
||||
* @return the maximum value contained in the set.
|
||||
* @throws RuntimeException if set is empty
|
||||
*/
|
||||
public int getMaxElement() {
|
||||
if ( isNil() ) {
|
||||
return Token.INVALID_TYPE;
|
||||
throw new RuntimeException("set is empty");
|
||||
}
|
||||
Interval last = intervals.get(intervals.size()-1);
|
||||
return last.b;
|
||||
|
@ -445,14 +432,13 @@ public class IntervalSet implements IntSet {
|
|||
|
||||
/**
|
||||
* Returns the minimum value contained in the set if not isNil().
|
||||
* Otherwise, result is undefined.
|
||||
*
|
||||
* @return the minimum value contained in the set. If the set is empty,
|
||||
* result is undefined.
|
||||
* @return the minimum value contained in the set.
|
||||
* @throws RuntimeException if set is empty
|
||||
*/
|
||||
public int getMinElement() {
|
||||
if ( isNil() ) {
|
||||
return Token.INVALID_TYPE;
|
||||
throw new RuntimeException("set is empty");
|
||||
}
|
||||
|
||||
return intervals.get(0).a;
|
||||
|
|
Loading…
Reference in New Issue