Skip to content

Commit

Permalink
Use own version of getSingleElement() since we don't care about negat…
Browse files Browse the repository at this point in the history
…ive values
  • Loading branch information
bhamiltoncx committed Feb 27, 2017
1 parent 20b1b4e commit ef12fa2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tool/src/org/antlr/v4/automata/LexerATNFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public IntervalSet getSetFromCharSetLiteral(GrammarAST charSetAST) {
g.fileName, charSetAST.getToken());
return new IntervalSet();
case INTERVAL_SET:
int codePoint = escapeParseResult.intervalSet.getSingleElement();
int codePoint = getSingleElement(escapeParseResult.intervalSet);
boolean containsMultipleCodePoints = (codePoint == -1);
if (inRange) {
if (containsMultipleCodePoints) {
Expand Down Expand Up @@ -489,6 +489,21 @@ public IntervalSet getSetFromCharSetLiteral(GrammarAST charSetAST) {
return set;
}

private static int getSingleElement(IntervalSet set) {
// We don't use IntervalSet.getSingleElement() because it can't handle sets containing 0.
// See https://github.com/antlr/antlr4/issues/1703 .
if (set.size() != 1) {
return -1;
} else {
Interval interval = set.getIntervals().get(0);
if (interval.length() == 1) {
return interval.a;
} else {
return -1;
}
}
}

protected void checkSetCollision(GrammarAST ast, IntervalSet set, int el) {
if (set.contains(el)) {
g.tool.errMgr.grammarError(ErrorType.CHARACTERS_COLLISION_IN_SET, g.fileName, ast.getToken(),
Expand Down

0 comments on commit ef12fa2

Please sign in to comment.